Home   Help Search Login Register  

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

0 Members and 1 Guest are viewing this topic.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
How to script this?
« on: 13 Jan 2004, 13:25:50 »
How would one do this in a script:

You define a array of weapons _warr = [wep1,wep2,wep3,etc...]
Then you put one of these weapons to a soldier (let's call'm Sol1) and make the script check if the soldier has one of these weapons in the array...
So basicly a loop of ((primaryWeapon Sol1) in _warr) or similar should do the trick..?

That's easy (for me) compared to the next thing I need the sript to do...
I need the script to assign the unit having one of the weapons in that weapon array to a global variable so that the global variable kind of 'doubles' itself so that if more units carry weapons defined in the weapon array they each get assigned as individual global variable.
And even if two soldiers carry the 'same' weapon, so that i.e Sol1 has wep1 and Sol4 has wep1 they would still each get the individual variable...Example:

Sol1 has weapon wep1, thus becoming globalvariable_1
Sol2 has weapon wep3, thus becoming globalvariable_2
Sol3 has weapon wep24534, thus becoming globalvariable_3
Sol4 has weapon wep1, thus becoming globalvariable_4
And so on...

I'm guessing that the format command would be needed in this but I have no idea how to implement that for this use...
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 #1 on: 13 Jan 2004, 18:34:00 »
Greetings.

Clarification: you want to combine 2 variables (soldierName and weapon) into one global variable (sorta like this -> [Sol1, m16])?

Or something different?

-Supreme Commander PsyWarrior
-Psychic Productions.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:How to script this?
« Reply #2 on: 13 Jan 2004, 21:36:10 »
Nope, something different...  :)

For example something like weaponCarrier_#...


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 #3 on: 13 Jan 2004, 21:42:20 »
Ah, so you want to combine the soldier and the weapon name/num into a single text string?

Like "Soldier1 has weapon 4"

or "WEST: Alpha Black 1 has M16"

so GlobalVar_1 = "Soldier1 has weapon#4"

or am I shooting randomly in the wrong direction again?  :gunman:

-PsyWarrior

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:How to script this?
« Reply #4 on: 14 Jan 2004, 03:33:53 »
Ah, so you want to combine the soldier and the weapon name/num into a single text string?

Like "Soldier1 has weapon 4"

or "WEST: Alpha Black 1 has M16"

so GlobalVar_1 = "Soldier1 has weapon#4"

or am I shooting randomly in the wrong direction again?  :gunman:

-PsyWarrior
:D

Almost...  :)

And nope, I don't need any strings... I only need to assign the soldier who carries one of the specific weapons as a global variable...

To clarify, here's an example (not in anyway an actual code):

Code: [Select]
_grp = _this select 0
_wepArr = _this select 1
_check = 0
_nr = 0

#loop
_unit = _grp select _nr
?((primaryWeapon _unit) in _wepArr): _check=_check+1; globVar_#=_unit

?(_nr == (count _grp)): exit
_nr = _nr + 1
goto "loop"

I need to know how to implement that number given by the _check to the global variable... Meaning that the # would be the same as _check...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Unnamed

  • Guest
Re:How to script this?
« Reply #5 on: 14 Jan 2004, 11:01:11 »
I think I know what your after, but a couple of questions:

You want to monitor every guy in a unit, to see when he picks up, or if he is carrying a particular weapon?

What do you want to do once you have a list of all the units carrying those particular wepaons?

Is it for multiplayer or single player?

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:How to script this?
« Reply #6 on: 14 Jan 2004, 11:55:51 »
I think I know what your after, but a couple of questions:

You want to monitor every guy in a unit, to see when he picks up, or if he is carrying a particular weapon?
Yes... Should do both. If the weapon is given to the soldier in the briefing or if he picks it up in the battlefield...

Quote
What do you want to do once you have a list of all the units carrying those particular wepaons?
They are (of course) distributed into the global space to use in other scripts and a few triggers. Too lazy to go through all the details...  :P
I'm looking a way to improve my scripts which I wrote for making the AI deploy portable weapon systems in FDF Mod... If/when I get this particular thing sorted and tested, based on that I'll go deeper into the subject since I'm pretty sure I'll be needing a ton of help...

Anyhoo, I don't think that there's a need to store the global variables in an array or something... They do exist once they are defined... If that's is what you were after?

Quote
or multiplayer or single player?
Single player...
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 #7 on: 14 Jan 2004, 12:51:06 »
*ping*

Ah, now I think I see  :D .

So all you want is to check if a soldier has any one of the weapons in the weapArr array, and then assign the soldier to a global variable - which is called globalVar_# (with # being a number that increases every time?

I think you are correct in assuming that the format command could be used here. I have only really used the format command with text strings, so the code below is theoretical at best:

Code: [Select]
_count = 4; comment "example only"
format [globalVar_%1, _count] = _unit

This may or may not work - it's untested I'm afraid, because I'm at college at the minuite (and for some reason, the admin won't let me install OFP on the network. Don't know why...). However, it should be something along those lines, so experiment with it.

If nothing works, I'll do some of my own experiments when I get back.

-PsyWarrior

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:How to script this?
« Reply #8 on: 14 Jan 2004, 13:20:02 »
*ping*

Ah, now I think I see  :D .

So all you want is to check if a soldier has any one of the weapons in the weapArr array, and then assign the soldier to a global variable - which is called globalVar_# (with # being a number that increases every time?
;D

Yep... BUT  :D as I was going to test that I noticed this needs to be more complicated  :-X
:tomato:  :beat:

If the sol1 carries wep2 -> global variable = globVar_1...
BUT if the sol1 drops/puts down the weapon and picks it up again the global variable should still stay as globvar_1 OR if the sol1 dies and someone else picks up the wep2 that guy would be assigned as globVar_1...

So as the global variable is assigned for the first time it would get 'locked' somehow to sort of match the weapon the soldier was carrying so that the same weapon picked up again wouldn't cause the globVar_# to go up... (you had a bit similar thought in one of your earlier posts...)

I hope you can get my drift from that...
English's not by native language so I may not be as clear as I wanted in explaining myself... ;)
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 #9 on: 14 Jan 2004, 14:43:22 »
Aaaaaaaaaaaaaagh! :noo:

Okay... Here goes:

So if sol1 picks up weap3, globalVariable_1 = sol1.
But if sol1 drops weap3, globalVariable_1 = sol1 still.

dammit!

Right, try this -> After sol1 has been assigned to gV_1 (for short), you need to execute another script using the parameters [gV_#, sol#, _weapArr, num]. In the script:

Code: [Select]
_var = _this select 0
_sol = _this select 1
_weapArr = _this select 2
_num = _this select 3

#primaryLoop
; run a loop to check if primaryWeapon _sol in _weapArr
; If yes, goto primaryLoop. If no goto noWeap

#noWeap
_var = RES; comment "RES for Reserved"
format [globalVar_%1, _num] = _var; comment "if this works at all"
? !(alive _unit): exit

#secondryLoop
; loop to check if unit picks up weapon again
; if yes, reassign globalVar_1 to _unit. If no, loop. Also check if unit is !alive.

You also need to add some code to the original script, removing _unit from the _grp array when this script is executed - otherwise, when the unit picks up the weapon again, the main script will assign them to globalVar_13 or something.

OK?

-PsyWarrior :beat:

PS - did that "format..." thing work? Or do I have to kill myself?

Unnamed

  • Guest
Re:How to script this?
« Reply #10 on: 14 Jan 2004, 17:48:00 »
Code: [Select]
Anyhoo, I don't think that there's a need to store the global variables in an array or something... They do exist once they are defined... If that's is what you were after?

No I was just curious to know what you wanted to do as there are wealth of possible approaches, is it for one guy, 100 hundred guys e.t.c

At least you know you dont need to use arrays or something, thats a start.






Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:How to script this?
« Reply #11 on: 15 Jan 2004, 01:37:17 »
Quote
PS - did that "format..." thing work? Or do I have to kill myself?
Nope... :(
Just says "Error Unknown Operator"...
So, are you planning to use rope, gun or what… ;)  :D

Quote
Okay... Here goes:

So if sol1 picks up weap3, globalVariable_1 = sol1.
But if sol1 drops weap3, globalVariable_1 = sol1 still.

Yes... BUT if the weapon dropped by the sol1 is picked by another dude, like sol6, then sol1 would get nilled and sol6 would become the globVar_1...
I'm starting to doubt that's this is not even possible to do...  ::)


Quote
No I was just curious to know what you wanted to do as there are wealth of possible approaches, is it for one guy, 100 hundred guys e.t.c
Well, it could be for 100 guys as well...
So, it is for more that 1 dude...


I made a list of what the sript(s) should do (if this clarifies anything...)

1. Check what weapons the soldiers are carrying and cross reference them with the weapon array. Should check only secondaryWeapon since other checks not needed.

2. If a match is found assign the soldier carrying the first match as globalVariable_1, a soldier carrying the second match as globalVariable_2, and so on...

3. If the globalVariable_1 drops/puts down the weapon he still stays as globalVariable_1.
BUT if the weapon he dropped/put down is picked up by another soldier that soldier now becomes the globalVariable_1...
Or the globalVariable_1 dies and someone else picks up the weapon from him that someone would get assigned as globalVariable_1...
So in a sense the weapon matched in the weapon array should sort of be 'toetagged' with the globalVariable_#... (Or maybe the weapon should be assigned as a global variable as well... ???)

I know this must be somewhat confusing and I just can't explain it any better...
All I know is that I have a clear 'vision' in my head what this script should do...


Here's the code I have now, did this a while while back and it's fully functional. Don't care about the global variables, they are defined elsewhere and this is only one part of currently five part script...
Only drawback this has is that you can use it only for one specific weapon and one dude...
(Well actually two as they carry the weapon in two parts...)

Code: [Select]
_nr    = 0
_pArr      = units group player - [player]
_intAmmo   = HTR_depWepAmmo

?(HTR_weaponCarrierSet == 1) && (HTR_tripodCarrierSet == 1): exit

#loopCheck
~.05
_unit = _pArr select _nr

?(alive _unit) && (_unit hasWeapon HTR_wpnToDeploy): HTR_weaponCarrier = _unit; HTR_weaponCarrierSet = 1
?(alive _unit) && (_unit hasWeapon HTR_trpToCarry): HTR_tripodCarrier = _unit; HTR_tripodCarrierSet = 1

?(_nr == (count _pArr)): exit
_nr = _nr + 1

?(HTR_weaponCarrierSet == 1) && (HTR_tripodCarrierSet == 1): goto "ammoRoutine"

goto "loopCheck"

So this checks the players groups AI who might be carrying a specific weapon and tripod and assigns them as global variables...
Why I want that weapon array for is that it would be predefined so the mission maker would not have to define it by him/herself... With this current code the mission maker needs to define the weapon in the init.sqs specificly...
Why I need the globalVariable_# thingy is that I'd like this script to be useable for more than one weapon per group without the weapon to be predefined... Now this script limits the players group to carry only one portable weapon system which needs to be predefined...

I hope this helps u to get a glimpse of what I'm getting at...
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 #12 on: 15 Jan 2004, 12:50:33 »
 :noo: :noo:
 :gunman:
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaagh!
Noooooooooooooo...

*bang*.

It could be that the format command only works in conjunction with another scripting command, or only works with text strings (although I think I've seen it used with other data types).

As for monitoring who is in possesion of a given weapon at any one time, I don't know if this is even possible. If there is only one instance of a weapon at any one time, it should be fairly easy to rig up a script that detects who has what weapon at which time. However, if there are multiple instances of a weapon (e.g. 3x M16, 2x M60), I can't see any way of monitoring who has what instance of which weapon at what time  ??? . At least not without getting incredibly 'credibly advanced.

Of course it could be that it is possible for OFP to differentiate between one M16 and another, which would solve most of our problems instantly!

As for the format cmnd, what does it say is the unknown operator? And try this to see if you can get a text string to output:

hint format ["globVar_%1", _nr]

If that doesn't work, then something else is messed up. It's also possible that the understrike (_) is messing it up. Try stuff like "globVar%1" or "globVar-%1".

And next time you add a feature to this script, myself and PsySniper will be knocking on your door. With a 200mm shell...

-PsyWarrior

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:How to script this?
« Reply #13 on: 15 Jan 2004, 13:53:37 »
It could be that the format command only works in conjunction with another scripting command, or only works with text strings (although I think I've seen it used with other data types).

As for the format cmnd, what does it say is the unknown operator? And try this to see if you can get a text string to output:

hint format ["globVar_%1", _nr]

If that doesn't work, then something else is messed up. It's also possible that the understrike (_) is messing it up. Try stuff like "globVar%1" or "globVar-%1".
Works fine if you use it as hint format but if you use it like format ["globVar_%1",_nr] = _unit you'll get the error... So 'tis the = _unit that causes it...

I think the format needs to be defined separately before using it as the global variable... Not tested yet though...

As for monitoring who is in possesion of a given weapon at any one time, I don't know if this is even possible. If there is only one instance of a weapon at any one time, it should
be fairly easy to rig up a script that detects who has what weapon at which time. However, if there are multiple instances of a weapon (e.g. 3x M16, 2x M60), I can't see any way of monitoring who has what instance of which weapon at what time  ??? . At least not without getting incredibly 'credibly advanced.
I've had it working so that if you use different kinds of weapons like portable TOW, portable Konkurs and portable Heavy Machinegun at the same... Made it work with the current script of mine, only downside being that I had to copy/paste and rename all the global variables and the scripts to make it work... Very very feeble...  >:(

Maybe we need a new section to these forums; 'Incredibly Impossibly Advanced Scripting'  ;D
(Just kiddin'....  ;) )

And next time you add a feature to this script, myself and PsySniper will be knocking on your door. With a 200mm shell...
:D ;D :P
Oh I haven't told you even the half of the features I'd like this (these) scripts to perform...  ;)

Maybe I still should go and buy some Class 4 Armor and Laser shielding...  :D
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 #14 on: 15 Jan 2004, 15:47:29 »
 >:(

Anyway, if you want to use the format command in this way, I think you have to remove the speech marks ["globVar_%1"...] should be [globVar_%1...] or you will end up formating globVar_# as a string rather than as a variable.

excuse me a minuite...

LOAD WEAPONS!

As I was saying, I'm kind of out of ideas at the moment, so I will try some stuff when I get home, and update you then.

AIM!

If you discover a way around this, please post it up or i'll be spending hours trying stuff out for nothing... and that would be bad. Very bad.  >:(

FIRE!

 :gunman:
 :gunman:
 :gunman:
 :gunman:
 :gunman:

-PsyWarrior