Jump to content
Sign in to follow this  
VanhA-ICON

Detecting action?

Recommended Posts

Hi huys.

The problem:

Is there a way to detect in a script if player already has certain action added?

The issue comes up when I reassign satellite view via norrins revive script.

It works of course but if an AI unit revives another unit or I revive someone I get added additional "Sat view" action.

The additional ones get deleted when I use the action so it's not a big deal but still a bit annoying.

I wish there was an "hasAction" command for this...

The satView sqf:

if ((vehicle player == player) && (local player)) then {player addAction ["Sat view", "Sat_Cam\SatellitenBild.sqf"];};
if true exitWith {};

Share this post


Link to post
Share on other sites

You could use set/getvariable to toggle a boolean (true/false) for each unit. :/

Share this post


Link to post
Share on other sites

Well, this does not work but am I getting even close?

_hasIt = false;
_hasAction = [];
while {true} do
{
if (alive player) then
{
_hasAction = player getVariable "ACT";
}
};
if true exitWith {};
else
{
if ((vehicle player == player) && (local player)) then {player addAction ["Sat view", "Sat_Cam\SatellitenBild.sqf"];};
player setVariable ["ACT",_hasAction, true];
_hasIt = true;
};
if true exitWith {};

:lecture:

Share this post


Link to post
Share on other sites

player setVariable ["ACT", true, true]; when adding the action should be enough. You can check whether he has the action with if (!isNull (unit getVariable "ACT")) then ...

If the variable hasn't been added, it will be null. If the variable isn't null, you'll know that the action is there.

Share this post


Link to post
Share on other sites

Im not sure but I think its a good idea to move the first if true exitwith {}; inside the if brackets. I believe the script is exiting now regardless if player is alive or not.

if (alive player) then
{
_hasAction = player getVariable "ACT";
if true exitWith {};
};
};
else 
{ 

+ your missing one ;

Took me some time but now I have managed to get 2 pieces of Grandiosa in me without loosing them ;)

Share this post


Link to post
Share on other sites
player setVariable ["ACT", true, true]; when adding the action should be enough. You can check whether he has the action with if (!isNull (unit getVariable "ACT")) then ...

If the variable hasn't been added, it will be null. If the variable isn't null, you'll know that the action is there.

It won't be null, it will be nil.

if ((vehicle player == player) && (local player) && isNil{player getVariable "TAG_satAction"}) then
{
    player setVariable["TAG_satAction", player addAction ["Sat view", "Sat_Cam\SatellitenBild.sqf"]];
};

@OP: there is no point in using exitWith in the context you do. SQF scripts terminate automatically once end of the file is reached.

Share this post


Link to post
Share on other sites
A nonexistent getVariable returns null.

No, it doesn't. Just like any other variable it is nil and the condition will be skipped due to undefined variable (wish this would be considered an error).

Share this post


Link to post
Share on other sites

Thank you all for your effort!

Here it is at the moment, but..

_hasIt = false;
_hasAction = [];
while {true} do
{
if (alive player) then
{
_hasAction = player getVariable "ACT";
if true exitWith {};
};
};
else
{
if ((vehicle player == player) && (local player) && isNil{player getVariable "ACT"}) then
{
    player setVariable["ACT", player addAction ["Sat view", "Sat_Cam\SatellitenBild.sqf"]];
_hasIt = true;
};  
};

It's still saying that it's missing a ";" in

#else

:confused:

Share this post


Link to post
Share on other sites
No, it doesn't. Just like any other variable it is nil and the condition will be skipped due to undefined variable (wish this would be considered an error).

Go to the editor, place a player unit and put hintSilent format ["%1",player getVariable "lol"] in its init and see what it returns.

Edit: never mind, it returns <null> but responds only to isNil. :)

Edited by Celery

Share this post


Link to post
Share on other sites

You have a }; in the wrong place and an extra stuff?

_hasIt = false;

while {true} do
{
if (alive player) then
{
	if ((vehicle player == player) && (local player) && isNil{player getVariable "ACT"}) then
	{
	     player setVariable["ACT", player addAction ["Sat view", "Sat_Cam\SatellitenBild.sqf"]];  // Doe this actually add the action?
		_hasIt = true;  // what's this for?  It's local so can't be used globally, also not used in this script.
	};  
};
};

Is that setVariable going to act like you expect it to? It's just setting the ACT variable to some weird string, that doesn't actually execute that code does it?

Is this your entire code? Since it's not making sense for me as written by you or rewritten by me. :)

Edited by kylania

Share this post


Link to post
Share on other sites

Well, I can't script. Period. That must be why...

:(

It does not give error messages anymore but does not work either.

No action comes up anymore.

(I have the "ACT" also defined in init.sqf)

Share this post


Link to post
Share on other sites

Is that setVariable going to act like you expect it to? It's just setting the ACT variable to some weird string, that doesn't actually execute that code does it?

It will store the addAction ID there. This can be handy if you ever need to remove it.

Share this post


Link to post
Share on other sites

Is this your entire code? Since it's not making sense for me as written by you or rewritten by me. :)

Well, your rewrite seems to be doing the trick I was after!

It's still giving the message "re-enabling satellite" but now I don't get piled up "Sat View" actions when someone revives a unit.

I'll test it on dedicated to be sure but I hope this is it.

I know you don't understand why it's so but it's a bit complicated since I re-run it through the revive script.

:)

I removed the "_hasIt" stuff.....

Share this post


Link to post
Share on other sites
It will store the addAction ID there. This can be handy if you ever need to remove it.

Ahh, good to know it works like that, neat!

Glad it's working Vanh-A!

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  

×