Jump to content
Sign in to follow this  
Scouter

Checking for vehicles in a radius of a marker

Recommended Posts

Hello, this is my first thread...

Anyway, my overall goal is to make a laptop with the addAction command to spawn a vehicle at on a marker, which I have done successfully. However, if I were to spawn more than one vehicle and not move them, the vehicles will spawn in/on each other and that is bad... What I am looking for is some way to check a 5m radius of a marker and deny the spawning of the vehicle if something is already in the 5m radius.

Here is what I have so far:

createVehicle ["VWGolf", getMarkerPos "MARKcar", [], 0, "can_collide"];

I assume for doing this, I need an 'if' statement.

(I am relativity new to coding/scripting so I am taking stabs in the dark here)

_area1 = getMarkerPos "MARKcar" nearObjects 5;

if (_area1 = false) then {hintSilent "Can't spawn vehicle,\nsomething is blocking it's spawn!"} else {createVehicle ["VWGolf", getMarkerPos "MARKcar", [], 0, "can_collide"]};

I guess the main problem is the condition of the 'if' statement. I tested the 'then' and 'else' with (!alive p2) as the condition and it worked...

Edited by Scouter
Holy typos Batman...

Share this post


Link to post
Share on other sites

Hi... use count as _area1 will be a list of objects.

Here I changed _area1 to _objects;

_objects = [];
_objects = getMarkerPos "MARKcar" nearObjects 5;

if (count _objects >0) then {
   hintSilent "Can't spawn vehicle,\nsomething is blocking it's spawn!"};
} else {
   createVehicle ["VWGolf", getMarkerPos "MARKcar", [], 0, "can_collide"];
};

EDIT: You might be better of with something like this statement which will find only objects of class "LandVehicle". Object Classes can be found here.

_objects = (getMarkerPos "MARKcar") nearObjects ["LandVehicle",5];

Edited by twirly

Share this post


Link to post
Share on other sites

Thanks for that really quick response. That looks like it is what I need, I will test it soon. Thanks. I am surprised I did not think of using 'count'.

Another thing; I am going to have a lot of vehicles that can be spawned from the addAction laptop. Is there a way I can get a 'goto' type command so each individual addAction can find a different part of the sqf?

(Like goto for MS-DOS ie: goto end -> :end)

Share this post


Link to post
Share on other sites

You can pass the vehicle type to one .sqf that creates vehicles... so an addaction for each vehicle type.

_action1_ID = player [url="http://community.bistudio.com/wiki/addAction"]addAction[/url] ["Create Tunguska", "create_veh.sqf","2S6M_Tunguska"];
_action2_ID = player addAction ["Create T72", "create_veh.sqf","T72"];

create_veh.sqf:-

_typofvehicle = _this select 3;

_objects = [];
_objects = getMarkerPos "MARKcar" nearObjects 5;

if (count _objects >0) then {
   hintSilent "Can't spawn vehicle,\nsomething is blocking it's spawn!";
} else {
   _veh = [url="http://community.bistudio.com/wiki/createVehicle_array"]createVehicle[/url] [_typofvehicle, getMarkerPos "MARKcar", [], 0, "NONE"];
};

Edited by twirly
Clarity

Share this post


Link to post
Share on other sites

Excellent! Thanks. This is exactly what I need. I am actually learning from this. :)

Share this post


Link to post
Share on other sites

EDIT: I goofed, then found and fixed an error 2 minutes after posting this.. derp.

(Can't delete it)

Edited by Scouter

Share this post


Link to post
Share on other sites

No worries....there was actually a "}" too many... I fixed it in the second post.

Share this post


Link to post
Share on other sites

Ok, now, I am trying to have the spawned vehicle rotated to a direction other than 0. I looked at other codes and I did exactly what they did and it still doesn't work for me. I took a shot at it with the _dir variable.

Everything else is working perfectly.

_type = _this select 3;
_dir = 205.55;

_objects = [];
_objects = (getMarkerPos "Mcar") nearObjects ["AllVehicles",5];

if (count _objects >=1) then {
hintSilent "Can't spawn vehicle,\na vehicle is blocking it's spawn!";
} else {
_veh = createVehicle [_type, getMarkerPos "Mcar", [], 0, "can_collide"];
};

_veh setdir _dir;

Refering to this thread:

http://forums.bistudio.com/showthread.php?127850-How-to-set-direction-of-spawned-vehicle

Edited by Scouter

Share this post


Link to post
Share on other sites

Hi mate... check this out....uses the nearEntities command instead.

Works fine.

Notice all the diag_log statements? I tracked the script the whole way through and logged the stuff to the .rpt file.

Between that and -showScriptErrors parameter in your shortcut.. it becomes a little easier to work out. Keep trying till something works. Lots of commands are similar. It's quirky stuff.

_type = _this select 3;
_dir = 205.55;

//diag_log format ["_type: %1",_type];

_objects = [];
_objects = getMarkerPos "mcar" nearEntities [["Man","Air","Car","Motorcycle","Tank"],5];

//diag_log format ["_objects: %1",_objects];

if (count _objects >=1) then {

hintSilent "Can't spawn vehicle,\na vehicle is blocking it's spawn!";

//diag_log "The hint fired.";

} else {

_veh = createVehicle [_type, getMarkerPos "mcar", [], 0, "NONE"];
_veh setdir _dir;

//diag_log format ["%1 created. Heading: %2",_type,getdir _veh];

};

If you want to randomise the direction then do this...

_dir = random 360;

Hope that helps!

Edited by twirly

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  

×