SA-MP Forums Archive
[Help] OnPlayerKey.... - 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: [Help] OnPlayerKey.... (/showthread.php?tid=306144)



[Help] OnPlayerKey.... - Jimbo01 - 25.12.2011

I want that my KEY_JUMP function ( if(newkeys == KEY_JUMP) ) works only if someone is in the tutorial ( if(RegStep[playerid] < 1) ) how can i do it ?

Now its like this:

Code:
	if(newkeys == KEY_JUMP)
            {
            // my  function



Re: [Help] OnPlayerKey.... - Norck - 25.12.2011

Are you talking about that?
pawn Code:
if(newkeys == KEY_JUMP && RegStep[playerid] < 1)
{
// ...
}



Re: [Help] OnPlayerKey.... - Jimbo01 - 25.12.2011

yes thanks

but i get error then that playerid is not defined


Re: [Help] OnPlayerKey.... - Sinner - 25.12.2011

Better not to check them in 1 statement:

pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys == KEY_JUMP) {
        if(RegStep[playerid] < 1) {
            // Your code here
        }
    }
}



Re: [Help] OnPlayerKey.... - Jimbo01 - 25.12.2011

ty no errors

EDIT: now if i press the key nothing happens


Re: [Help] OnPlayerKey.... - Gh05t_ - 25.12.2011

Quote:
Originally Posted by Sinner
View Post
Better not to check them in 1 statement:

pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys == KEY_JUMP) {
        if(RegStep[playerid] < 1) {
            // Your code here
        }
    }
}
KEY_JUMP will still be passed to those whose value is greater than 1!

pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys == KEY_JUMP)
    {
        if(RegStep[playerid] > 1) return 0;
    }
    return 1;
}



Re: [Help] OnPlayerKey.... - Jimbo01 - 25.12.2011

pawno is crashing (Ghost)


Re: [Help] OnPlayerKey.... - Sinner - 25.12.2011

Quote:
Originally Posted by Gh05t_
View Post
KEY_JUMP will still be passed to those whose value is greater than 1!

pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys == KEY_JUMP)
    {
        if(RegStep[playerid] > 1) return 0;
    }
    return 1;
}
That was not the question, though. My code works just fine.


Re: [Help] OnPlayerKey.... - Gh05t_ - 25.12.2011

Quote:
Originally Posted by Sinner
View Post
That was not the question, though. My code works just fine.
No, it doesn't.

pawn Code:
new bool:variable;
main()
{
    if(variable == false)
    {
        print("0");
    }
    print("1"); //<<<< is still passed.
}
pawn Code:
main()
{
    if(variable == true) return 0;
    print("0");
}