SA-MP Forums Archive
2 same keys under OnPlayerKeyStateChange. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: 2 same keys under OnPlayerKeyStateChange. (/showthread.php?tid=472750)



2 same keys under OnPlayerKeyStateChange. - Unri - 30.10.2013

Hello. Can we use 2 same keys under OnPlayerKeyStateChange? For example, i have to seperate ifs or keys, or however i can clal it, for entering a door and exiting it. Both are 'F'.


Re: 2 same keys under OnPlayerKeyStateChange. - Konstantinos - 30.10.2013

You can use a key for enter/exit (if I understood what you wanted to).
pawn Код:
new
    bool: PlayerEntered[ MAX_PLAYERS char ]
;

// OnPlayerConnect:
PlayerEntered{ playerid } = false;

public OnPlayerKeyStateChange( playerid, newkeys, oldkeys )
{
    if( ( newkeys & KEY_SECONDARY_ATTACK ) && !( oldkeys & KEY_SECONDARY_ATTACK ) )
    {
        if( !PlayerEntered{ playerid } )
        {
            // enter..
            PlayerEntered{ playerid } = true;
        }
        else
        {
            // exit..
            PlayerEntered{ playerid } = false;
        }
    }
    return 1;
}



Re: 2 same keys under OnPlayerKeyStateChange. - Pottus - 30.10.2013

How is an exit any different than an enter point? They both do the same thing therefore it is not so important that your keys may do multiple actions but how the underlying system utilizes the data to perform those actions.


Re: 2 same keys under OnPlayerKeyStateChange. - Unri - 30.10.2013

Im asking if you can have 2 IF's under OnPlayerKeyStateChange, which both use KEY_SECONDARY_ATTACK(<-an example).
Its a yes/no question.


Re: 2 same keys under OnPlayerKeyStateChange. - Konstantinos - 30.10.2013

Yes, but it's pointless. You can check if the key is KEY_SECONDARY_ATTACK only once and inside that if statement do different things.


Re: 2 same keys under OnPlayerKeyStateChange. - [ABK]Antonio - 30.10.2013

How structure works

pawn Код:
if(test == 0) { test=2; } //if this isnt called
else if(test == 2) {} //this is - however, even if we set the test var to 2, this wont be called if the first if is
else {} //if above isnt called, this is

if(test == 2) {} //after that check above, this block comes next
else { test=2;} //if above isn't true, this is called (which it is, so this wont be called)
However, like the people above said, you don't need to do this.