Jump to content
Sign in to follow this  
lato1982

how to check the distance to any kind of vehicle or west vehicle?

Recommended Posts

Hi,

I know this question might sound silly, and also there are tyons of scripts that uses similiar solutions, but I can't figure out how to make a term that checks if the script launching object is at a distance to any type of vehicle.

waitUntil {((_this distance ambulance_01)  < 15 )};

I've got this line where i'm checking the distance for a particular vehicle, but I want to make it universal for every kind of vehicle. I know i could use isKindOf, but not sure how to define it, when "_this" is already taken :)

Thanks,

Share this post


Link to post
Share on other sites

I don't fully understand what you're asking.

Do you want to know how to make that code work as a function where you can call it specifying different vehicles to check against each time? Or to know when _this is less then 15 away from any vehicle?

If you call your code as a function from elsewhere, then you can set up multiple parameters to be passed in. So you'd define two parameters, in place of the _this and ambulance_01.

See example three here. In that example, your actual distance check would be in the "add.sqf" file. A called function can access each parameter passed to it by treating _this as an array. Where position 0 is the first variable, etc etc.

Share this post


Link to post
Share on other sites

Thanks for the tips, the call examples are still not full clear for me but...

I'm asking how to best define here any type of vehicle or west vehicle that will work in this line instead of ambulance_01?

I'm looking for a solution like:

_vehicle = all kind of vehicles
_vehicleWest = all kind of west vehicles

waitUntil {((_this distance _vehicle)  < 15 )};

or at least sth like this to define all the vehilces I need:

_list = [ambulance_01, ambulance_02, ambulance_03, ambulance_04]
_vehicle = is in _list

waitUntil {((_this distance _vehicle)  < 15 )};

Edited by Lato1982

Share this post


Link to post
Share on other sites
private["_typeList","_searching"];
_typeList = ["HMMVW"];
_searching = true;

while {_searching} do
{
{
	if (_this distance _x < 15 && (typeOf _x) in _typeList) then
	{
		_searching = false;
	};
} forEach vehicles;
};

// Any code below here won't run until condition is met

Share this post


Link to post
Share on other sites

Have you considered a trigger that's activated whenever one of those defined vehicles moves within the trigger area?

Otherwise your waitUntil condition will need to return true if any of the vehicles in the array are within 15. You may want to consider not using a waitUntil but some other kind of logic loop check...Might be intensive however. (Hence the trigger suggestion.)

Note that you can get a list of all vehicles with the vehicles command.

You can attach a trigger to a vehicle with the attachTo command. Take a look at the thisList for the trigger, which should contain the objects inside the trigger and check if any match against the desired vehicle objects. This thread might give you some ideas too.

Edited by Axek

Share this post


Link to post
Share on other sites
Thanks for the tips, the call examples are still not full clear for me but...

I'm asking how to best define here any type of vehicle or west vehicle that will work in this line instead of ambulance_01?

I'm looking for a solution like:

_vehicle = all kind of vehicles
_vehicleWest = all kind of west vehicles

waitUntil {((_this distance _vehicle)  < 15 )};

or at least sth like this to define all the vehilces I need:

_list = [ambulance_01, ambulance_02, ambulance_03, ambulance_04]
_vehicle = is in _list

waitUntil {((_this distance _vehicle)  < 15 )};

_list = [ambulance_01, ambulance_02, ambulance_03, ambulance_04];
waitUntil {({(_x distance _vehicle) < 15} count _list > 0)};

Share this post


Link to post
Share on other sites

Thanks for the answers! I can't use triggers this needs to be dynamic for each unit. This is a script for bodies transportation. I need to park a vehicle near a dead body, then the body disappears and is loaded into car.

Next I transport the bodies to base an unload them by spawning the body bag model, so after your mission you can see the returned corpses and can actually feel how many has died.

Sth like Mass Effect 2 last scene :)

Edit: maybe the attachTo could work, thanks again for the tips!

If you could explain what does the count list do here?

waitUntil {({(_x distance _vehicle) < 15} count _list > 0)};

Edited by Lato1982

Share this post


Link to post
Share on other sites

_x is a magic variable that refers to each element in _list.

_list is an array of the vehicles you want to check.¨

http://community.bistudio.com/wiki/count

So basically, you check all of the left-side code first (is any of the vehicles closer than 15 meters?) and since count is done with numbers, you check if it's higher than 0. If the evaluated code is higher than 0 (1 or above) it means that one of the vehicles are closer than 15 meters.

Share this post


Link to post
Share on other sites

Thank You for the explanation, I think it will do the job perfectly! :)

Share this post


Link to post
Share on other sites

Hi, the scripts posted above work great, however I have a problem with defining all land and Air vehicles. "AllVehicles" doesn't work as I wish, because it counds all humans. How to define land and air vehicles only?

this gives me an error:

_bodyTransporter = getPos _this nearestObject ["LandVehicle","Air"];

and this works,

_bodyTransporter = getPos _this nearestObject "LandVehicle","Air";

but chcecks only LandVehicles even if the object is closer to the heli.

How can I fix this?

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  

×