SA-MP Forums Archive
Quick Help Needed! [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: Quick Help Needed! [OnPlayerKeyStateChange] (/showthread.php?tid=482992)



Quick Help Needed! [OnPlayerKeyStateChange] - $Marco$ - 23.12.2013

Sup guys i need help with detecting if the player has pressed a key, and if he released it.

At the top of the script i have added:
pawn Код:
#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
#define RELEASED(%0) \
    (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
And:

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PlayerInfo[playerid][XXX] == 1 && PlayerInfo[playerid][XXXY] == 1) // Line 286
    { // Line 287
        if(PRESSED(KEY_AIM)) // Line 288
        { // Line 289
            SendClientMessage(playerid, WHITE, "Something."); // Line 290
        } // Line 291
        else if(RELEASED(KEY_AIM)) // Line 292
        { // Line 293
            ClearAnimations(playerid); // Line 294
        } // Line 295
        if((newkeys & KEY_WALK) && !(oldkeys & KEY_WALK)) //line 296
        { //line 297
            ApplyAnimation(playerid,"PED","WALK_armed",4.1, 1, 1, 1, 0, 0, 0); //Line 298
        } // Line 299
    } // Line 300
}
Errors:
Код:
(Line: 288 ) : error 029: invalid expression, assumed zero
(Line: 290) : error 001: expected token: ")", but found ";"
(Line: 290) : error 036: empty statement
(Line: 292) : error 029: invalid expression, assumed zero
(Line: 294) : error 001: expected token: ")", but found ";"
(Line: 294) : error 036: empty statement
(Line: 296) : error 010: invalid function or declaration
Thanks to all the kind helpers.


Re: Quick Help Needed! [OnPlayerKeyStateChange] - Vince - 23.12.2013

Did you define KEY_AIM? This one's not defined by default.


Re: Quick Help Needed! [OnPlayerKeyStateChange] - $Marco$ - 23.12.2013

Damn, i forgot it.
Thanks it has solved it.


Re: Quick Help Needed! [OnPlayerKeyStateChange] - Konstantinos - 23.12.2013

It seems fine to me, I even compiled it (ignoring PlayerInfo).

EDIT: I didn't refresh the page and I didn't see the above replies.

Although, wouldn't it just give error about undefined symbol "KEY_AIM" and not those it gave?


Re: Quick Help Needed! [OnPlayerKeyStateChange] - $Marco$ - 23.12.2013

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
It seems fine to me, I even compiled it (ignoring PlayerInfo).

EDIT: I didn't refresh the page and I didn't see the above replies.

Although, wouldn't it just give error about undefined symbol "KEY_AIM" and not those it gave?
Yea it should have, that's so stupid it didn't.