Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Detecting action?

  1. #1

    Detecting action?

    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:
    Code:
    if ((vehicle player == player) && (local player)) then {player addAction ["Sat view", "Sat_Cam\SatellitenBild.sqf"];};
    if true exitWith {};

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

  3. #3
    Gunnery Sergeant VanhA-ICON's Avatar
    Join Date
    Jun 17 2009
    Location
    Scandinavia
    Posts
    509
    Author of the Thread

    hmm

    Well, this does not work but am I getting even close?
    Code:
    _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 {};

  4. #4
    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.

  5. #5
    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.

    Code:
    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
    \"Det är bara att placera den ena foten framför den andra och upprepa det tills man har kommit fram\"
    Ltn Vuorensola

  6. #6
    Quote Originally Posted by Celery View Post
    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.

    PHP Code:
    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.

  7. #7
    Quote Originally Posted by Deadfast View Post
    It won't be null, it will be nil.
    A nonexistent getVariable returns null.

  8. #8
    Quote Originally Posted by Celery View Post
    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).

  9. #9
    Gunnery Sergeant VanhA-ICON's Avatar
    Join Date
    Jun 17 2009
    Location
    Scandinavia
    Posts
    509
    Author of the Thread
    Thank you all for your effort!

    Here it is at the moment, but..
    Code:
    _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
    Code:
    #else

  10. #10
    Quote Originally Posted by Deadfast View Post
    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.
    Last edited by Celery; Sep 18 2010 at 17:17.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •