OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: LeeHunt on 21 Aug 2007, 19:42:38

Title: SOLVED (So far): Checking a unit's actions and inventory
Post by: LeeHunt on 21 Aug 2007, 19:42:38
Hey there,

I am looking for expertise on how to best solve this dilemma:

I have a character (Carla in Punishment Battalion) that the player can teamswitch into for a brief amount of time--but I'd like to limit what that character can do (Carla is a civilian with no fighting skills).

I have a very basic script already to check if she picks up any weapons, but I'd like her to be able to use a satchel charge, once and only once.  Unfortunately I did not write in a way to prevent her from using tanks-- some betatesters wisely planted multiple satchel charges and drove a tank around blazing away (taking advantage of Carla's setcaptive true status) and I've gotta put a stop to that!  :whistle:

I could probably write into a script a way to eject Carla if she tries to drive or be the gunner in certain vehicles, but I'm not sure how to "know" when she has planted a satchel charge (would i check the animation?). 

And lastly, i'm wondering if all this could be combined more efficiently into a function?  What do you think? Thanks!

Title: Re: Checking a unit's actions and inventory, function better than a script?
Post by: myke13021 on 21 Aug 2007, 20:18:51
About planting the satchels: wouldn't a eventhandler "fired" not return "Put" as weapon? Something following this path but i'm not sure if this could/would work but might be worth a try.

And about preventing Carla to drive certain vehicles...lock them while being Carla, could this be an option?
Title: Re: Checking a unit's actions and inventory, function better than a script?
Post by: Mr.Peanut on 21 Aug 2007, 23:03:48
How about removing all satchels from the mission, except one, while Carla?
Title: Re: Checking a unit's actions and inventory, function better than a script?
Post by: Wolfrug on 22 Aug 2007, 10:01:37
Stopping Carla from getting inside vehicles she shouldn't:

You can see if Carla is inside a vehicle by the simple command:

?vehicle Carla !=Carla : hint "Carla's in a vehicle!"

(this is due to the fact that "vehicle unit" will always return the unit itself unless having boarded a vehicle)

After having come to the conclusion she's in a vehicle, you can, I guess, figure out what kind of vehicle it is and whether or not she's allowed to drive around in it by a number of different ways, but there are caveats of course: for instance when Carla is NOT the player, you should still be able to transport her in various trucks, APCs and possibly even tanks without her being ejected. How about something like this:

?canFire (vehicle Carla) && (gunner vehicle Carla) == Carla OR canFire (vehicle Carla) && (commander vehicle Carla) == Carla OR canfire (vehicle Carla) && (driver vehicle Carla) == Carla : Carla unassignVehicle vehicle Carla; Carla action ["Eject", vehicle Carla]; Carla say "I_Refuse_To_Drive_This"

Basically, the script first checks if the vehicle Carla is in "canFire" (has offensive capabilities), and if that is the case it boots her out and possibly gives a message. Should work, no?

Wolfrug out. 
Title: Re: Checking a unit's actions and inventory, function better than a script?
Post by: LCD on 22 Aug 2007, 10:24:48
cud also use da typeof (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=t#typeOf) command 2 check what type of veh she drivin.... im also sure deres a beter command but i just dont remember it... ohh right its da isKindOf (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=h#isKindOf) command....

as 2 check if shes player use da isPlayer (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=h#isPlayer) command :P

LCD OUT
Title: Re: Checking a unit's actions and inventory, function better than a script?
Post by: LeeHunt on 25 Aug 2007, 15:45:44
thanks gentlemen,  :D here is what I came up with using your suggestions (and i betatested it extensively, so far so good). There's only rub-- i end up with two similar scripts running at the same time, and I'm not sure how to terminateone of them without using a true/false global variable (In Punishment Battalion i've had to use religious devotion to eliminating variable names etc to allow saved games to work, which thankfully they do now). 

In the context of the mission, I made it so that Carla will only drive her car ("Sallycar", i used Sally originally as her name) and nothing else, so that solved the vehicle problem and stayed realistic. 
As for planting one satchel charge, I used the addeventhandler "Put" suggestion and then a new script that would have Carla/Sally throwing away any satchel charges you give her after her one rude awakening to violent action.  Here's where the rub comes in, two similar scripts running at the same time, the only difference is one has Carla/Sally throwing away her weapons & satchel charges.   :confused:

I posted the sample mission. Keep in mind that Carla/Sally has an eventhandler for "Put" in her initialization line.  Thanks again!


Title: Re: SOLVED (So far): Checking a unit's actions and inventory
Post by: h- on 25 Aug 2007, 16:21:49
Lee, use the code tags when posting long pieces of code.
I'm not even going to attempt to fix that mess myself..... :no:
Title: Re: SOLVED (So far): Checking a unit's actions and inventory
Post by: LeeHunt on 25 Aug 2007, 16:27:46
oop sorry i just left it as the sample mission.  I don't know about code tags (yet).  Anyway its solved and the solution is basically described well enough without the sample or code.
Title: Re: SOLVED (So far): Checking a unit's actions and inventory
Post by: h- on 25 Aug 2007, 16:49:56
You can get the code tags by pressing the # button above the smilie row.
Or type them by hand of course..
Title: Re: SOLVED (So far): Checking a unit's actions and inventory
Post by: LeeHunt on 25 Aug 2007, 23:11:47
Ahhh thank you h-! 
Title: Re: SOLVED (So far): Checking a unit's actions and inventory
Post by: Mr.Peanut on 25 Aug 2007, 23:33:00
If you write your scripts in sqf format, then using the execVM (or spawn) command returns a handle to that function. i.e.
Code: [Select]
hScript1 = [foo] execVM "Script1.sqf";
You can then use:
Code: [Select]
scriptDone hScript1to test if the script is still running,
and:
Code: [Select]
terminate hScript1to terminate the script.

Yet another reason to get jiggy with sqf.  :P
Title: Re: SOLVED (So far): Checking a unit's actions and inventory
Post by: LeeHunt on 25 Aug 2007, 23:41:14
Thanks, Mr. Peanut. that's very helpful to beginners like myself  :yes:. I'm just starting to learn SQF and I keep seeing how its a much better way to do things!!!   I will give this a try...