SA-MP Forums Archive
I think the problem is defining - 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: I think the problem is defining - OnPlayerKeyStateChange (/showthread.php?tid=368626)



I think the problem is defining - OnPlayerKeyStateChange - gnoomen2 - 14.08.2012

Ok, so i didn't understand the define things in the tutorial on sa-mp wiki...so..here is what i got


public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
#define PRESSED(%0) \
if (PRESSED(KEY_JUMP))
{
new
Float:X5,
Float:Y5,
Float:Z5;
GetPlayerPos(playerid, X5, Y5, Z5);
SetPlayerPos(playerid, X5, Y5, Z5 + 10.0);
}
return 1;
}


and i get this warning: warning 201: redefinition of constant/macro (symbol "PRESSED(%0)")

on the if (pressed line


Re: I think the problem is defining - OnPlayerKeyStateChange - gnoomen2 - 14.08.2012

Quote:
Originally Posted by belhot1992
Посмотреть сообщение
Try this:
PHP код:
//On top of your script
#define PRESSED(%0) \
    
((newkeys & (%0)) == (%0))
public 
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if (
PRESSED(KEY_JUMP))
    {
           new 
Float:X5Float:Y5Float:Z5;
         
GetPlayerPos(playeridX5Y5Z5);
         
SetPlayerPos(playeridX5Y5Z5 10.0);
    }
    return 
1;

copy and pasted yours, i now got:

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
#define PRESSED(%0) \
((newkeys & (%0)) == (%0))
if (PRESSED(KEY_JUMP))
{
new
Float:X5,
Float:Y5,
Float:Z5;
GetPlayerPos(playerid, X5, Y5, Z5);
SetPlayerPos(playerid, X5, Y5, Z5 + 10.0);
}
return 1;
}

and still the same warning. I dunno if this works IG, havent tested it.. its the super jump example from sa-mp wiki, but i just dont understand this defining.


Re: I think the problem is defining - OnPlayerKeyStateChange - gnoomen2 - 14.08.2012

Quote:
Originally Posted by belhot1992
Посмотреть сообщение
Ahhh, I now read your warning, sorry.
That means that you have PRESSED defined somewhere else in your script, just switch it to this:
PHP код:
//On top of your script
#define HOLDING(%0) \
    
((newkeys & (%0)) == (%0))
//End of defines
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if (
HOLDING(KEY_JUMP)) {
        new 
Float:X5Float:Y5Float:Z5;
        
GetPlayerPos(playeridX5Y5Z5);
        
SetPlayerPos(playeridX5Y5Z5 10.0);
    }
    return 
1;

Thank you very much, it's fixed and i saw i had a extra #define pressed xD

Thanks for the help!