Home   Help Search Login Register  

Author Topic: How to script this?  (Read 3919 times)

0 Members and 1 Guest are viewing this topic.

Offline MachoMan

  • Honoured
  • Former Staff
  • ****
  • KISS, Keep it Simple Stupid
Re:How to script this?
« Reply #15 on: 15 Jan 2004, 16:26:00 »
OK i think the answer is suprisingly easy:

Code: [Select]
;   -  ECP TEAM -
;=====================
;      MachoMan
;=====================
;WeaponCheck.sqs
;=====================
;Scipt will take 2 arrays
;_this select 0 -> Units
;_this select 1 -> Weapons
;selectedUnits -> Global Variable result

_units = _this select 0
_weapons = _this select 1
selectedUnits = []
_iterator = Count _units

#unitsLoop
_unit = _units select (_iterator-1)
; Iterator -1, because array starts @ null.
"?(_unit hasWeapon _x): selectedUnits = selectedUnit + [_unit]" foreEach _weapons
_iterator = _iterator-1
?(_iterator > 0):goto "unitsLoop"
exit

In essence i rewrote the foreEach function, so that u can use a double foreEach.  ;)

IF u rewrite it into a .sqf u can even have it return the array.
« Last Edit: 15 Jan 2004, 17:42:04 by MachoMan »
Get those missions out there you morons!

Unnamed

  • Guest
Re:How to script this?
« Reply #16 on: 15 Jan 2004, 17:39:05 »
You could use the In command to check against an array of weapon names as strings.

Code: [Select]
If ((SecondaryWeapon _Unit) In _Weapons) Then {selectedUnit=selectedUnit + [_unit]}

You may need to add something to delete a unit from selectedUnit, if it has been killed or has dropped the weapon?

I'm quite interested in this myself, I would like to do the same with Mortars, perhaps with three or four individual components. But this would be limited to mortar crews only.

As I only had a small number of guys in mind, and just need to add the appropriate action menu options. I thought of launching a simple script for every possible mortar crew. It looks like something like:

Code: [Select]
_Unit=_This select 0

_LastWeapon=""
_ActionID=-1

#Loop

~1

_Weapon=SecondaryWeapon _Unit

If (_Weapon!=_LastWeapon) Then {If (_LastWeapon In CheckWeapons) Then {RemoveAction...e.t.c} ; {If (_Weapon In CheckWeapons) Then {AddAction....Deploy.sqs...e.t.c}}

_LastWeapon=_Weapon

If (Alive _Unit) Then {goto "Loop"} Else {RemoveAction...e.t.c}

I'ts basic enough to probably allow quite a few copies running in the background.
« Last Edit: 15 Jan 2004, 17:40:07 by Unnamed »

PsyWarrior

  • Guest
Re:How to script this?
« Reply #17 on: 15 Jan 2004, 17:46:22 »
Wait a moment, I don't get it  ???

I may be slow and stupid, but I don't see how this solves the initial problem of numbering a global variable (globVar_#).

Can someone enlighten me? Please? Before I start losing sleep over this.

 :(

-PsyWarrior

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:How to script this?
« Reply #18 on: 15 Jan 2004, 21:00:03 »
 :cheers: Thanks to you all for the input...

I can't really tell you guys anything new since I've been very busy today and will be tomorrow so I may not be able to test anything for a couple of days...  :'(


@PsyWarrior: removing the "" from the format thingy does not work... Tested that already...   :-\
Oh, and please do not use all your free time for me...  :D
Or loose your sleep over this... I haven't..  ;)


@MachoMan
Oh, took me a while to see what you were getting at... And I'm still not quite understanding it  :D
"?(_unit hasWeapon _x): selectedUnits = selectedUnit + [_unit]" foreEach _weapons
I have always problems understanding these "_x this and that" those things... :(

It just so sad since I know that once this particular problem gets solved the next one is there waiting and it's propably much more complicated than this... :-\


@Unnamed
Yup... That certainly would be another way...

Sure, your code looks like it should work...
And I'm not meaning that this script of mine should run for 100 guys... That would too much firepower on the battlefield...  :P

Just so that i.e. the players group could have 1-3 portable weapon systems with them... or more, depending on the mission maker...

I have fully working beta of my AI deploy scripts in small circulation so if you're interested I could post a link where to get it... Needs FDF Mod 1.2 though...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline MachoMan

  • Honoured
  • Former Staff
  • ****
  • KISS, Keep it Simple Stupid
Re:How to script this?
« Reply #19 on: 15 Jan 2004, 21:55:03 »
@HateR_Kint

I'm not sure weather this is what u meant (didn't fully understand your first post  ;) ), but i thought u wanted a script that would create an array of units who have a weapon located in another array.

Code: [Select]
"?(_unit hasWeapon _x): selectedUnits = selectedUnit + [_unit]" foreEach _weapons
I'll explain this. It checks weather _unit has _x, where _x is each of the weapons in _weapons.
Get those missions out there you morons!

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:How to script this?
« Reply #20 on: 15 Jan 2004, 23:17:43 »
I'm not sure weather this is what u meant (didn't fully understand your first post  ;) ), but i thought u wanted a script that would create an array of units who have a weapon located in another array.

Code: [Select]
"?(_unit hasWeapon _x): selectedUnits = selectedUnit + [_unit]" foreEach _weapons
I'll explain this. It checks weather _unit has _x, where _x is each of the weapons in _weapons.

Ah...

Well, actually I didn't want any arrays (why, I don't know...) at first but now I'm leaning to the direction that it would be the best solution...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

PsyWarrior

  • Guest
Re:How to script this?
« Reply #21 on: 16 Jan 2004, 10:50:29 »
I suppose in the end it might actually be better to use an array instead of lots of numbered global variables. In an array, all the positions are already numbered (array select 0, 1, etc.).

For instance, instead of
sol1 has weap3, and goes in globVar_0,
you would have:
sol1 has weap3, and goes in globArr select 0.

i.e. (globArr select 0) = _unit

This removes the need for numbered variables completely. ;D

Try it...

-PsyW

Offline MachoMan

  • Honoured
  • Former Staff
  • ****
  • KISS, Keep it Simple Stupid
Re:How to script this?
« Reply #22 on: 16 Jan 2004, 12:15:49 »
I suppose in the end it might actually be better to use an array instead of lots of numbered global variables. In an array, all the positions are already numbered (array select 0, 1, etc.).

For instance, instead of
sol1 has weap3, and goes in globVar_0,
you would have:
sol1 has weap3, and goes in globArr select 0.

i.e. (globArr select 0) = _unit

This removes the need for numbered variables completely. ;D

Try it...

-PsyW


Yep, ofcourse it's better to use arrays, anything else will make using the data kinda hard, since u do not know how many global variables there will be.
If u use an array u always now there is 1 variable, the array itself, and if u want to know how many vars are in the array just use count.
Get those missions out there you morons!

PsyWarrior

  • Guest
Re:How to script this?
« Reply #23 on: 16 Jan 2004, 12:21:55 »
It's just a pity to have expended all that brainpower to try and get the format command to work.
Still arrays are more efficient and will probably do everything that HateR_Kint wants them to do.

I hope... ::)

-PsyW
« Last Edit: 16 Jan 2004, 12:23:01 by PsyWarrior »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:How to script this?
« Reply #24 on: 16 Jan 2004, 14:02:41 »
Yep, ofcourse it's better to use arrays, anything else will make using the data kinda hard, since u do not know how many global variables there will be.
If u use an array u always now there is 1 variable, the array itself, and if u want to know how many vars are in the array just use count.
I was just about to say the same thing...   :P
Now once you think of it the format thingy would've been useless as you pointed out...

Quote
It's just a pity to have expended all that brainpower to try and get the format command to work.
Agreed...  :(


I hope that I find the time during the weekend to test these things...
I'll report back then...

 :cheers:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:How to script this?
« Reply #25 on: 19 Jan 2004, 00:07:42 »
 >:(

I'm starting to believe that I'm trying to chew too big a piece with this...

The MachoMans script works fine, and I'm still wondering why in the name of all that is holy I didn't come up with it myself...
------
 
As I'm trying make the AI deploy the portable weapon systems (specially in FDF Mod...) so the weapon takes two guys to carry it; the other carries the weapon part (like Machine Gun or TOW tube) and the other carries the tripod (a 'dummy' weapon), so I had to 're-write' the MachoMans script a bit to get two arrays; units who carry the weapon and units who carry the tripods... This also works like a charm...

The current script 'bundle' I've made does make the AI deploy these weapons, but only with one weapon per group and that weapon needs to be specified by the mission maker...
What I need to achieve now is that the mission makers wouldn't have to specify the weapons him/herself as they would be defined in the scripts already. This would free the mission maker to use any of the portable weapon systems without a worry... This is why I needed that units weapons compared to the weapon array... I also hoped that this would 'enable' the use of more than one weapon of the same kind, in other words you could have two iTOWs, two Konkurs' and so on...
The current scripts do not support that feature...

Can be done so far: with array of weapons and array of tripods I can have the corresponding array of weaponcarriers and array of tripodcarriers... A big thanks to you guys… This does liberate mission maker from the definition process…

The next problems are so complex in a way that I just can't explain them to you… Instead I'll make a numbered list what features the script(s) should have and answer your questions should there rise any. And I'm NOT (bur hey, not stopping you either  ;) )asking you to write any scripts for me, merely just a ‘professional' opinion wether these ‘features' are even possible to code:

1.Check who carries which weapons. If there's portable weapons present  make arrays of the units who carry the weapon part and units who carry the tripod part. DONE.

2.Then check for ‘pairs' so that the weapon carrier and the unit who carries the tripod for that weapon are defined as weaponCarrier and tripodCarrier for that particular weapon. TODO.

3.Add an action per ‘pair' for the player so that the first ‘pair' responds to the first action and so on. Name the action relating the weapons name (maybe I'll need an array of names also…). TODO.

4.When an action for weapon deploy is called the ‘pair' ‘belonging' to that certain action performs the deploy process. TODO.


As said, I'm running out of ‘talent' with this thing  â€¦
So again, I may be up to something too big for me, as usual...  :-\

Here's (save target as…) the current version of the scripts I have working, WITHOUT the array ‘features' and such… The original one specific weapon version…
Needs the FDF Mod 1.2
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline MachoMan

  • Honoured
  • Former Staff
  • ****
  • KISS, Keep it Simple Stupid
Re:How to script this?
« Reply #26 on: 19 Jan 2004, 11:08:34 »
Ok all can be done, and are actually not that hard.

Let's start with script 2:
There are multiple ways to get this thing done, all of them use arrays for storing the names of the weapons and their ammo and tripods in arrays.

The best way (in my opinion), would be to use 2D arrays.
I will give u a simple example:
Code: [Select]
gunsAndAmmo = [ [m16, m16mag], [ak47, ak47mag], [m4, m4mag] ]

I think u'll get my point ;)

Ok now use this kind of an array to check if a unit has a weapon, then u use the second name in the array to see if another unit hase the tripod.

Again it's not really as hard as it looks  ;)

As my title says: KISS  ;D
« Last Edit: 19 Jan 2004, 11:09:41 by MachoMan »
Get those missions out there you morons!

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:How to script this?
« Reply #27 on: 19 Jan 2004, 11:41:40 »
The best way (in my opinion), would be to use 2D arrays.
I will give u a simple example:
Code: [Select]
gunsAndAmmo = [ [m16, m16mag], [ak47, ak47mag], [m4, m4mag] ]

I think u'll get my point ;)

Ok now use this kind of an array to check if a unit has a weapon, then u use the second name in the array to see if another unit hase the tripod.

Again it's not really as hard as it looks  ;)

As my title says: KISS  ;D
Again something I never even thought of  >:(

I have no problem in KISS, but I think I'd bee needing TISS, think it simple stupid...  ;D

thnx
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.