Jump to content
Sign in to follow this  
Mage

Check if player is in vehicle?

Recommended Posts

Hello gentlemen.

I'm featuring a task in which the player must get into a civilian truck loaded with ammunition and drive it to a city.

How can I make a trigger check if the player is there in order to set the destination only if the player is in the vehicle?

Also, how can I call different units? is there any sort of wildcard operator I could use in this scripting language?

e.g: i name a bunch of enemy units such as enemy_1 enemy_2 enemy_3

and then make a trigger that's like !alive enemy_* will match all of them?

Share this post


Link to post
Share on other sites

1) vehicle player == nameOfYourTruck

2) {alive _x} count [enemy_1,enemy_2,enemy_3] < 1

If there are billions of them, there is another way to do it, which is dynamic, but the way above is more simple if theres just few of them.

Share this post


Link to post
Share on other sites

another way would be to use

player in VehicleName

for the trigger condition.

Share this post


Link to post
Share on other sites

thank you guys :) that did the trick.

As for the wildcard operator im wondering if there's a very simple way (scripting wise) to call multiple objects with a similar name (eg: item_1 item_2) so that the underscore can be the limit in between the name and the part of the name that varies, well that's kinda self explanatory.

so im after either a built in command that will let me wildcard from any character onwards

or to build a script that will create such function for later use.

so like if the delimiter is "_" then whatever follows "_" will be wildcarded, or in the case of being called by a trigger, anything after _ doesn't matter, so if there's 2 or 100 units wich name is unit_something the something will not matter to this trigger, but as every object needs a unique name, i think this way will simplify things a lot more.

Then again, I'm not really familiar with this scripting language as of yet, though it looks pretty familiar to others im used to that have nothing to do with this game.

Share this post


Link to post
Share on other sites

Well, if you know the number of the units its pretty simple. Not knowing it would probably mean looping through allunits. However, I would probably find a way that does not include need to name hundreds of units.

Edited by Shuko

Share this post


Link to post
Share on other sites

Good point.

But for example. If I place 4 choppers and i don't name them, can I just make a trigger that will activate whenever all the units that are the same are not present?

eg !alive UH-1Y? for example? so I don't have to give names to all the stuff

Share this post


Link to post
Share on other sites

_uh1y = [];
{
 if (typeof _x == "UH1Y") then {
   _uh1y = _uh1y + [_x];
 };
} foreach allunits;
waituntil {{alive _x} count _uh1y < 1};
hint "all UHs are dead";

Or you can do this in init.sqf

aUH1Y = [];
aAH1Z = [];
{
 switch (typeof _x) do {
   case "UH1Y": { aUH1Y = aUH1Y + [_x] };
   case "AH1Z": { aAH1Z = aAH1Z + [_x] };
 };
} foreach allunits;

Then you can do this in a script or a trigger:

{alive _x} count aUH1Y < 1

Share this post


Link to post
Share on other sites

Another more generic way to do this would be to check whether the player is in any vehicle. In some scenarios that would do the trick without having to check each single vehicle name or type.

IF (vehicle player == player) THEN {};

Meaning, if the player is in the vehicle called "player" then he's not in any vehicle other than his own body. Almost philosophical actually :)

VictorFarbau

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×