OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Ding on 06 Sep 2006, 19:21:55

Title: Unit In Vehicle
Post by: Ding on 06 Sep 2006, 19:21:55
Well basically Im using the "In" condition to play music as soon as the player gets in a car, and I want it to stop when they get out of the car. Is there a similar condition command that goes something along the lines of

Player Out Car1

that could work for this?
Title: Re: Unit In Vehicle
Post by: bedges on 06 Sep 2006, 19:24:34
i would investigate eventhandlers (http://www.ofpec.com/COMREF/index.php?action=list&letter=a#addEventHandler) if i were you. much more versatile.  :thumbsup:
Title: Re: Unit In Vehicle
Post by: JasonO on 06 Sep 2006, 19:37:09
Hmmm would:

player !in car1

work?
Title: Re: Unit In Vehicle
Post by: Cheetah on 06 Sep 2006, 19:38:34
Hmm: !(player in vehicle)
is what I would use.
Title: Re: Unit In Vehicle
Post by: Terox on 06 Sep 2006, 21:02:01
Quote
@ (vehicle player == player):

would become true when the player was out of a vehicle

bearing in mind the @ condition is fast looping, so a slower ~1 loop would be better

eg

Quote
#LOOP
~1
?(vehicle player == player):goto "OUT"
goto "LOOP"

#OUT
0.1 fadeMusic 0
exit
Title: Re: Unit In Vehicle
Post by: h- on 07 Sep 2006, 09:34:44
Quote
bearing in mind the @ condition is fast looping, so a slower ~1 loop would be better
True, but heed what bedges said..

Looping scripts for this kind of thing are soooo 1.46 ;)
Title: Re: Unit In Vehicle
Post by: THobson on 07 Sep 2006, 11:53:49
I have found no hard and fast rule about the perfomance hit from a loop vs an @ command.

Each case needs to be tested.  For complex conditional statements the @ must suffer vs the the loop, but the loop brings an overhead that the @ does not have.

In many missions the difference will be hard to spot, but in large missions where there may be many such commads running at the same time then you should test which is better.  For example I know that:

Code: [Select]
@ (getdammage _unit >0.9)
is much better than:

Code: [Select]
#loop
~0.5
if (getdammage _unit <0.9) then {goto"loop"}

Because I tested it with 5,000 scripts all running smultaneously.

Title: Re: Unit In Vehicle
Post by: Terox on 07 Sep 2006, 19:24:00
i think what is more important, is how quickly you need the "condition" to be seen

if you dont need it to be as "instantaneous" as possible, then use a slower loop

Title: Re: Unit In Vehicle
Post by: Ding on 08 Sep 2006, 20:08:16
actually "!(player in vehicle)" is what i needed really D:, I always forget about the uses of the Exclamation mark, I find that too many eventhandlers can cause lag sometimes when i have used them :(.

Thanks for all the help though  :check: :thumbsup:

Edit: Do we still need to lock Solved topics?
Title: Re: Unit In Vehicle
Post by: macguba on 08 Sep 2006, 23:47:46
We're not making a fuss about it but it remains good practice, if your question has been answered satisfactorily, to lock the thread and write something like "Topic solved - thanks everybody" at the bottom.  Always wait a couple of days after the last answer in case somebody has something intelligent to add.

Title: Re: Unit In Vehicle
Post by: h- on 09 Sep 2006, 15:17:23
@Ding
Quote
I find that too many eventhandlers can cause lag sometimes when i have used them
I find that very hard to believe, unless of course you execute scripts directly from them..
Title: Re: Unit In Vehicle
Post by: THobson on 09 Sep 2006, 18:20:48
Quote
I find that very hard to believe,
Me too.  I have a mission  that has around 1,500 killed EHs waiting to fire, and they all do eventually  :), many at the same time
Title: Re: Unit In Vehicle
Post by: Baddo on 09 Sep 2006, 18:28:14
It's not the event handlers, it's the people who start long looping scripts from, for example, fired event handlers and then they go and wonder why they get lag in a firefight of 24 soldiers... weapons on automatic fire.

On topic: there is also a function groupInVehicle (http://www.ofpec.com/ed_depot/the_files/OFPResources/functions/groupInVehicle.sqf) written for checking if a whole group is in a vehicle or not. Can be used for checking if group members are in any vehicle or if they are in the same vehicle.