Jump to content
Sign in to follow this  
fusionofp

Problem with the condition in addAction

Recommended Posts

Hi.

I keep getting a " missing ] " error if I use a condition on my addAction.

I am trying to determine if there is a mine within 2m of the player.

code so far:

_unit addAction ["disarm mine","disarm.sqf",[],80,false,true,"","_x in (player position) nearEntities,2 = "mine""];

I've tried a few different methods to find the mine, including nearObjects etc but I'll never figure out which one works until I get past this missing ] :)

Share this post


Link to post
Share on other sites

well first of, you are using nearEntitites command wrong, also player position should be position player, and around last "mine" you need ""mine"" but the code is entirely wrong so it doesnt matter.

Are you trying to grab the mine automatically with the addation? wich wont work btw, you need to grab the mine and then add the action to it, also read up on the commands you used, maybe take a look at the guide in my signature aswell.

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

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

maybe something like this will work.

_unit addAction ["disarm mine","disarm.sqf",[],80,false,true,"","(count (nearestObjects [player, [""mine""], 2])) != 0"];

Edited by Demonized

Share this post


Link to post
Share on other sites

I just wrote that code from memory, i have used position player, nearObjects and all of its cousins.

I am going to disarm the mine with a script which does work :)

I do use the Wiki but the examples given are not very helpful.

Squint throws up too many errors which don't exist but it has been useful.

So I'll try your code now :)

well, although there are no errors the condition "(count (nearestObjects [player, [""mine""], 2])) != 0" still doesn't register as true.

If there is no condition then everything works but I don't want too many entries in the options menu but i guess that is what I'll have to do.

Edited by fusionofp
update:

Share this post


Link to post
Share on other sites

this should detect if a player is within 2 meters of a mine

in trig cond

nearestObject [player, "Mine"] distance player < 2

in an EVH

this addAction ["disarm mine","disarm.sqf",[],80,false,true,"","nearestObject [player, ""Mine""] distance player < 2"];

Edited by F2k Sel

Share this post


Link to post
Share on other sites

well, although there are no errors the condition "(count (nearestObjects [player, [""mine""], 2])) != 0" still doesn't register as true.

If there is no condition then everything works but I don't want too many entries in the options menu but i guess that is what I'll have to do.

The condition field is very picky about code from my experience, try using the special caller var for addActions "_this" -- or use "_target" if it will be attached to the player.

"(count (nearestObjects [[color="Red"]_this[/color], [""mine""], 2])) != 0"

also please use

 blocks for your code, it makes it so much easier to read.

Share this post


Link to post
Share on other sites

I'll try those two examples, thanks and Riouken you are damn right about them being picky :)

As for code blocks, Its annoying to have to scroll left and right :)

Share this post


Link to post
Share on other sites

this is what worked in the condition field

"nearestObject [player, ""Mine""] distance player < 2"

Thanks everyone

Ps. I bet nobody knows how to check for a deactivated mine (so that it can be deleted from the battlefield ) ??

Share this post


Link to post
Share on other sites

if you just want it deleted as soon as it's disarmed and you calling it with the EVH you could use

save as disarm.sqf

_what = nearestObject [player, "Mine"]; 
hint format["%1","Mine has been disarmed"];
deletevehicle _what;

There is probably a neater way without calling nearestobject again but it works ok.

Share this post


Link to post
Share on other sites

I decided just to delete the mine as soon as it was deactivated.

Had a play with VectorUP, because a deactivated mine changes its z position, I managed to detect the change but something went wrong and i decided against using it :)

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  

×