Jump to content
Sign in to follow this  
ArmAriffic

select nearest civilian car

Recommended Posts

What i'm trying to do is when a player activates a action menu item the nearest civilian car stops ("setFuel 0" or "doStop", does not really matter), but I want it to be able to do for multiple cars (so not giving every car a name just random cars I placed that are driving around in the editor.

I have looked all around here trying different commands can searched the forum but I cant seem to find an answer.

Basicly...

My car is called "myCar"

I want the script to be exec-able multiple times for multiple different cars

I want the nearest driving civilian car to stop driving (setFuel 0 or doStop)

Help please I have squat :)

Share this post


Link to post
Share on other sites

How about something like this:

_nearcars = nearestobjects [player,["car"],500];
{if (side _x == civilian) exitwith {_x setfuel 0};} forEach _nearcars;

This should in theory find all the cars within 500m of the player, and then scan through the list and stop the first civilian car it finds.

Sorry if I'm barking up the wrong tree.

Share this post


Link to post
Share on other sites

wow that was fast lol

that does work but it sets the fuel for my car to 0

Share this post


Link to post
Share on other sites

_nearcars = nearestobjects [player,["car"],500]; 
{if (side _x == civilian) exitwith {(driver _x) action ["getout",_x]} forEach _nearcars;

Try this, this should just make the car driver get out. Mind you, I'm not actually running the script to test it - that's your job :)

Share this post


Link to post
Share on other sites
 _nearcars = nearestobjects [player,["car"],500]; 
{if (side _x == civilian[b] && _x != myCar[/b]) exitwith {_x setfuel 0};} forEach _nearcars; 

I got it to work, thanks

Share this post


Link to post
Share on other sites
 _nearcars = nearestobjects [player,["car"],500]; 
{if (side _x == civilian[b] && _x != myCar[/b]) exitwith {_x setfuel 0};} forEach _nearcars; 

I got it to work, thanks

No worries. Sorry I got a wire crossed, didn't realise you were also in a car. What am I?!?!

Share this post


Link to post
Share on other sites

Isn't it possible to tighten the filter in the nearestObjects? Depending on what cars are in use, you provide more than 1 filter.

 _nearcars = nearestobjects [player,["Lada_base", "Skoda_base", "etc etc"],500]; 

If you can cover all the potential cars in the filter, the result array would be smaller and more efficient. Also, I'd consider using nearObjects instead of nearestObjects as the former doesn't have to sort it's results in order of distance, so will be more efficient. Only sort the objects for distance if you need to.

Share this post


Link to post
Share on other sites
Only sort the objects for distance if you need to.

I agree, but in this case he wanted the nearest car, not just any nearby car, so nearestobjects it is.

Share this post


Link to post
Share on other sites
I agree, but in this case he wanted the nearest car, not just any nearby car, so nearestobjects it is.

You mean the single nearest car? Then he should use nearestObject. Not sure if you can supply multiple filters with that one though.

Share this post


Link to post
Share on other sites

I wish I could use this for OA, but I can't find a vehicle config page for OA, I only can find one for A2

Share this post


Link to post
Share on other sites

One more thing, can someone please look over my script.

 
private ["_goodlicence","_badlicence","_wanted","_nearcars"];
if (! isServer) exitwith {};

pof = 0; 

_goodlicence = 0;

_badlicence = 0;

_wanted = 0;

scract = true;

Player removeAction random;

Player removeAction breakinglaws;

Player globalChat "You were breaking traffic laws";

sleep 5;

Player globalChat "May I see your licence and registration please";

sleep 5;

_nearcars = nearestobjects [player,["car"],500]; 
{if (side _x == civilian && _x != myCar) exitwith {_x globalChat "here you go"}} forEach _nearcars; 

while {scract = true} do {

n1 = round (random 15 + 0.5);

if (n1 == 1) then { (hint "The licence & registration is in date.") };

if (n1 == 2) then { (hint "Licence and\or registration is out of date.") };

if (n1 == 3) then { (hint "The licence & registration is in date.") };

if (n1 == 4) then { (hint "The licence & registration is in date but the person is wanted.") };

if (n1 == 5) then { (hint "The licence & registration is out of date and the person is wanted.") };
};


fin = Player addAction ["Fine this person", "PoliceAction\fine.sqf"];
lg = Player addAction ["Let this person go", "PoliceAction\go.sqf"];
warn = Player addAction ["Give this person a warning", "PoliceAction\warning.sqf";

It wasn't working so i enabled -showscripterrors and it tells me

 '...scrat = true do {
n1 = round (random |#|15 + 0.5);
if (n1 == 1) then { (hint "T...'
Error missing )
File: (files location)
line 32 

I have looked at it with squint and that says it has no problems

Share this post


Link to post
Share on other sites

shouldn't scract = true have parenthesis, not curly brackets around it?

Share this post


Link to post
Share on other sites

Here's the new one

 private ["_goodlicence","_badlicence","_wanted","_nearcars"];
if (! isServer) exitwith {};

pof = 0; 

_goodlicence = 0;
_badlicence = 0;
_wanted = 0;

scract = true;

Player removeAction random;

Player removeAction breakinglaws;

Player globalChat "You were breaking traffic laws";

sleep 5;

Player globalChat "May I see your licence and registration please";

sleep 5;

_nearcars = nearestobjects [player,["car"],500]; 
{if (side _x == civilian && _x != myCar) exitwith {_x globalChat "here you go"}} forEach _nearcars; 

while (scract = true) do { n1 = round (random 15 + 0.5);
[b]if (n1 == 1) then { (hint "The licence & registration is in date.") };[/b]
if (n1 == 2) then { (hint "Licence and\or registration is out of date.") };
if (n1 == 3) then { (hint "The licence & registration is in date.") };
if (n1 == 4) then { (hint "The licence & registration is in date but the person is wanted.") };
if (n1 == 5) then { (hint "The licence & registration is out of date and the person is wanted.") };
};


fin = Player addAction ["Fine this person", "PoliceAction\fine.sqf"];
lg = Player addAction ["Let this person go", "PoliceAction\go.sqf"];
warn = Player addAction ["Give this person a warning", "PoliceAction\warning.sqf"; 

It tells me

 '...0")) forEach _nearCars;
while (scrat |#|= true) do { n1 = round (random 15 + 0.5...'
Error Missing )
File: ...
line 27 

Share this post


Link to post
Share on other sites

You don't need those ( and ) inside the then statement:

while (scract = true) do { n1 = round (random 15 + 0.5);
if (n1 == 1) then { hint "The licence & registration is in date." };
if (n1 == 2) then { hint "Licence and\or registration is out of date." };
if (n1 == 3) then { hint "The licence & registration is in date." };
if (n1 == 4) then { hint "The licence & registration is in date but the person is wanted." };
if (n1 == 5) then { hint "The licence & registration is out of date and the person is wanted." };
};

Also, switch might be a slightly sexier way to do it:

while (scract = true) do { n1 = round (random 15 + 0.5);
switch n1 do 
{ 
 case 1: {hint "The licence & registration is in date."}; 
 case 2: {hint "Licence and\or registration is out of date."}; 
 case 3: {hint "The licence & registration is in date."}; 
 case 4: {hint "The licence & registration is in date but the person is wanted."};
 case 5: {hint "The licence & registration is out of date and the person is wanted."};
};
};

Please feel free to tell me to get @$^#ed if you think I'm being too pedantic!

Share this post


Link to post
Share on other sites
You don't need those ( and ) inside the then statement:

while (scract = true) do { n1 = round (random 15 + 0.5);
if (n1 == 1) then { hint "The licence & registration is in date." };
if (n1 == 2) then { hint "Licence and\or registration is out of date." };
if (n1 == 3) then { hint "The licence & registration is in date." };
if (n1 == 4) then { hint "The licence & registration is in date but the person is wanted." };
if (n1 == 5) then { hint "The licence & registration is out of date and the person is wanted." };
};

Also, switch might be a slightly sexier way to do it:

while (scract = true) do { n1 = round (random 15 + 0.5);
switch n1 do 
{ 
 case 1: {hint "The licence & registration is in date."}; 
 case 2: {hint "Licence and\or registration is out of date."}; 
 case 3: {hint "The licence & registration is in date."}; 
 case 4: {hint "The licence & registration is in date but the person is wanted."};
 case 5: {hint "The licence & registration is out of date and the person is wanted."};
};
};

Please feel free to tell me to get @$^#ed if you think I'm being too pedantic!

No need to get @$^#ed, your really helpful :D

Thanks for the help guys

Share this post


Link to post
Share on other sites

Please feel free to tell me to get @$^#ed if you think I'm being too pedantic!

LOL. No, I'd use a switch there too. Though, if we must be pedantic, it's good to have a default as well as all the cases.

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  

×