Increasing a var while holding a key
#1

Hey,

I am failing for hours now while trying to increase a variable as long as a player holds down a key.

My current (not working) code:

Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{


                    if(newkeys&4) //CTRL
		    {
				new i=SetTimerEx("LongJumpAngle",50,1,"i",playerid); //TIMER INCREASING THE VARIABLE
				SetPVarInt(playerid,"Minigame2t",i); 
				print("2");
		    }
		    else if(oldkeys&4 && newkeys!=4) //Player releases key...I guess
		    {
		        KillTimer(GetPVarInt(playerid,"Minigame2t"));
		    }
}
Any help?
Reply
#2

You cannot detect when a player is "Holding" a key.
Reply
#3

But I can detect when a player releases a key and can stop increasing the var then, can't I?
Reply
#4

Try this: https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange

Or GetPlayerKeys in timer.
Reply
#5

I dont unterstand the "holding" part there, as the define only works in OnPlayerKeyStateChange and not with GetPlayerKeys for example.
Reply
#6

Thank you all, it works now...I cant say what exactly I changed but anyway, it works so - thank you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)