2 same keys under OnPlayerKeyStateChange.
#1

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'.
Reply
#2

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;
}
Reply
#3

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

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

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.
Reply
#6

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)