Jump to content
Sign in to follow this  
Mr_B_A_Baracus

Problem with condition code checking player in range of locations

Recommended Posts

Hi,

I have an action as follows and the condition to show the action is not working. I've been struggling to see what the issue is, my guess is something to do with the location check. I'm sure someone will spot it in a few seconds! Also, can someone confirm if global variables work in condition code like the following? Thanks in advance, this one's been really bugging me.

_text = "<t color='#00cc00'>" + format ["DO ACTION"]+ "</t>"; //green

_conditionCode = format ["

_veh = _target;

_unLocked = (locked _veh == 0 || locked _veh == 1 );

_garageLocations = [

[11533.004,9433.5479,27.579933],

[20786.578,6807.8887,35.678844],

[18087.299,15245.804,25.083857],

[9268.7627,15868.939,120.79372],

[4565.4165,21384.393,299.69217]

];

_fixAllowed = false;

if( (count _garageLocations ) > 0) then{

{

if((player distance _x) < 40) then{_fixAllowed = true;};

}foreach _garageLocations ;

}else

{

_fixAllowed = true;

};

_unLocked && _fixAllowed

"];//,VLA_Garage_Distance];

_action = _veh addAction [_text, "vla\actions\DO_ACTION.sqf",[],-1,false,true,_conditionCode];

Share this post


Link to post
Share on other sites

I'm not the best but I may have cue.

I would change

player distance _x

for

_veh distance _x

I don't know but it sound more like what you want to do.

and yes it would be more efficient to use global variable for your array.

It is stated that it will run every frame (client side), in your case when player is 15 or less meters from the vehicle, including when you're in it.

not sure I'm of great help though here for your problem. What is the behavior?

Share this post


Link to post
Share on other sites

The if if section will always set _fixAllowed to true, if that's the problem.

Share this post


Link to post
Share on other sites

You can't use local variable in addaction _text,_conditionCode

You also have the condition where the shortcut should be.

I'm not sure you need the format in _text, I got a simplified version working.

I haven't tested the condition part of addaction but that could work like this

conditionCode = {"
// your code
"};//,VLA_Garage_Distance;

texts = { "<t color='#00cc00'>" + "DO ACTION" + "</t>"; };

_action = _veh addAction [call texts, "vla\actions\DO_ACTION.sqf",[],-1,false,true,"",call conditionCode];

Not really tested it mostly working from memory and I'm not sure how you send the _target variable to the function..

Edited by F2k Sel

Share this post


Link to post
Share on other sites
Hi,

I have an action as follows and the condition to show the action is not working. I've been struggling to see what the issue is, my guess is something to do with the location check. I'm sure someone will spot it in a few seconds! Also, can someone confirm if global variables work in condition code like the following? Thanks in advance, this one's been really bugging me.

_text = "<t color='#00cc00'>" + format ["DO ACTION"]+ "</t>"; //green

_conditionCode = format ["

_veh = _target;

_unLocked = (locked _veh == 0 || locked _veh == 1 );

_garageLocations = [

[11533.004,9433.5479,27.579933],

[20786.578,6807.8887,35.678844],

[18087.299,15245.804,25.083857],

[9268.7627,15868.939,120.79372],

[4565.4165,21384.393,299.69217]

];

_fixAllowed = false;

if( (count _garageLocations ) > 0) then{

{

if((player distance _x) < 40) then{_fixAllowed = true;};

}foreach _garageLocations ;

}else

{

_fixAllowed = true;

};

_unLocked && _fixAllowed

"];//,VLA_Garage_Distance];

_action = _veh addAction [_text, "vla\actions\DO_ACTION.sqf",[],-1,false,true,_conditionCode];

maybe I got your problem. locked return true or false, not 0 or 1. you may have invalid type in your log file telling expecting BOOL

so _unlocked is always false or undefined. anyway I think you tweaked it to return true for debugging purpose... maybe just put true for now

Share this post


Link to post
Share on other sites

Thanks to everyone for your suggestions, unfortunately most of you were wrong!

The winner is F2K Sel for pointing out that the _conditionCode was in the wrong place. I've not tested it yet but I do have other actions that work fine in the same way but they have the condition code in the correct place i.e.

_action = _veh addAction [_text, "vla\actions\DO_ACTION.sqf",[],-1,false,true,_conditionCode];

should be:

_action = _veh addAction [_text, "vla\actions\DO_ACTION.sqf",[],-1,false,true,"",_conditionCode];

A few things that I'd like to clarify though:

1. You CAN use local variables in addAction

2. I don't need the format option but I had left it in from previous actions.

3. I should really be using _veh distance _x but in this instance it doesn't matter too much

4. I also had to change to (getposASL player) distance _x

5. The if if statement will NOT always return true

6. Locked does now return an integer (check the documentation)

7. I believe _target is automatic, it's the object the action is assigned to.

Again thanks to everyone for their suggestions though!

Share this post


Link to post
Share on other sites

# 6.. I had cheched the doc, But I usually not have to check the comments to verify the nomenclature. Really meesed up wiki. For when to open it for modification by community?

sorry to have lead you to bad info. will check the comments everytime from now on :-)

Share this post


Link to post
Share on other sites

No problem, I know what you mean about the wiki, it's not the best!

Sent from my Spectrum 48K using Tapatalk

Share this post


Link to post
Share on other sites
1. You CAN use local variables in addAction

F2k Sel probably confused it with using local variables in the actual condition text. You can pass _text and _conditionCode, but you couldn't for example use

_fixAllowed = true;

_action = _veh addAction [_text, "vla\actions\DO_ACTION.sqf", [], -1, false, true, "", [b]"_fixAllowed"[/b]];

since the scope is different.

Share this post


Link to post
Share on other sites

I did indeed get confused which is quit usual for me. I'll have to brush up on using commands in this way.

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  

×