SA-MP Forums Archive
OnPlayerUpdate + GetPlayerKey - 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: OnPlayerUpdate + GetPlayerKey (/showthread.php?tid=386799)



OnPlayerUpdate + GetPlayerKey - gilpenner - 21.10.2012

Hey guys I have a question, I'm trying to make a system that will not allow the player walk fast.

See, when you press "W" even without you to press sprint you gonna walk really fast and you might go to faraway places in few seconds, my idea is to make the player only walk, like if the player hold "Alt", but it's not everybody that will respect and walk slowly.

So the point is, I made this function (thanks to wiki samp) and I wanna make sure that this code will not LAG my GM.


PHP код:
new bool:Andando[MAX_PLAYERS];
public 
OnPlayerUpdate(playerid) {
    new 
Keys,ud,lr;
    
GetPlayerKeys(playerid,Keys,ud,lr);
    if(
ud != || lr != 0) {
        if(
Andando[playerid] == false) {
            
ApplyAnimation(playerid"PED""WALK_civi"4.1111111);
            
Andando[playerid] = true;
        }
    }
    else {
        if(
Andando[playerid] == true) {
            
ApplyAnimation(playerid"CARRY""crry_prtial"4.000000);
            
Andando[playerid] = false;
        }
    }
    return 
1;




Re: OnPlayerUpdate + GetPlayerKey - Jaxson - 21.10.2012

I suggest you to use OnPlayerKeyStateChange callback instead.


Re: OnPlayerUpdate + GetPlayerKey - gilpenner - 21.10.2012

OnPlayerKeyStateChange doesn't "read" KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT.
And I need to see when someone press some key to walk.


Re: OnPlayerUpdate + GetPlayerKey - Jaxson - 21.10.2012

I didn't know that, sorry.


Re: OnPlayerUpdate + GetPlayerKey - Hiddos - 21.10.2012

Pretty sure this won't lag, OnPlayerUpdate isn't that bad anyway


Re: OnPlayerUpdate + GetPlayerKey - gilpenner - 21.10.2012

Thanks Hiddos.