Home   Help Search Login Register  

Author Topic: SOLVED (So far): Checking a unit's actions and inventory  (Read 1929 times)

0 Members and 1 Guest are viewing this topic.

Offline LeeHunt

  • Former Staff
  • ****
  • John 21:25
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!

« Last Edit: 25 Aug 2007, 15:46:15 by Lee »

Offline myke13021

  • Contributing Member
  • **
  • Myke
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?

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
How about removing all satchels from the mission, except one, while Carla?
urp!

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
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. 
"When 900 years YOU reach, look as good you will not!"

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
cud also use da 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 command....

as 2 check if shes player use da isPlayer command :P

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline LeeHunt

  • Former Staff
  • ****
  • John 21:25
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!


« Last Edit: 25 Aug 2007, 16:26:52 by Lee »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: SOLVED (So far): Checking a unit's actions and inventory
« Reply #6 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:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline LeeHunt

  • Former Staff
  • ****
  • John 21:25
Re: SOLVED (So far): Checking a unit's actions and inventory
« Reply #7 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.
« Last Edit: 25 Aug 2007, 16:31:54 by Lee »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: SOLVED (So far): Checking a unit's actions and inventory
« Reply #8 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..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline LeeHunt

  • Former Staff
  • ****
  • John 21:25
Re: SOLVED (So far): Checking a unit's actions and inventory
« Reply #9 on: 25 Aug 2007, 23:11:47 »
Ahhh thank you h-! 

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: SOLVED (So far): Checking a unit's actions and inventory
« Reply #10 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
urp!

Offline LeeHunt

  • Former Staff
  • ****
  • John 21:25
Re: SOLVED (So far): Checking a unit's actions and inventory
« Reply #11 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...