Detecting player for holding key. -
Whizion - 25.10.2010
So i tryed this code under OnPlayerKeyStateChange:
pawn Код:
if(HOLDING(KEY_FIRE))
{
SendClientMessage(playerid,COLOR_RED,"SERVER: Your holding LMB, good job.");
}
But, it only sends a message once (when i pressed) but this is suppose to detect 'HOLDING' so why doesn't it spam my chat with that message? Am i doing something wrong? Please help me, thank you.
Re: Detecting player for holding key. -
Crayon - 25.10.2010
My guess is you forgot to place:
Re: Detecting player for holding key. -
Whizion - 25.10.2010
Nope, just tryed it, it's the same. If i want the message to spam my chat... I have to be clickin like a maniac (and that's not holding) if i want it to do that.
Maybe i need a timer, and GetPlayerKeys, anybody got an idea? Because i tryed something and also didn't work.
Re: Detecting player for holding key. -
Crayon - 25.10.2010
The timer would be a bad idea because it would just lag the hell out of the server I believe, lol.
I'm clueless though since I'm new to scripting, sorry man
Re: Detecting player for holding key. -
Miguel - 25.10.2010
Using while...?
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
while(HOLDING(KEY_FIRE)) SendClientMessage(playerid, COLOR_RED, "SERVER: You're holding LMB, good job.");
return 1;
}
I don't know...
Re: Detecting player for holding key. -
Tannz0rz - 25.10.2010
That's because OnPlayerKeyStateChange is only called when a player's key state changes. If you're holding the same key and doing nothing else, it won't spam your chatbox with that message.
Re: Detecting player for holding key. -
Whizion - 25.10.2010
Quote:
Originally Posted by Tannz0rz
That's because OnPlayerKeyStateChange is only called when a player's key state changes. If you're holding the same key and doing nothing else, it won't spam your chatbox with that message.
|
Than how to do it.
Re: Detecting player for holding key. -
Tannz0rz - 25.10.2010
Quote:
Originally Posted by Whizion
Than how to do it. 
|
Something along the lines of:
pawn Код:
new
bool:HoldingKey[MAX_PLAYERS];
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & KEY && !HoldingKey[playerid])
{
KeyCheck(playerid);
HoldingKey[playerid] = true;
}
return 1;
}
forward KeyCheck(playerid);
public KeyCheck(playerid)
{
if(IsPlayerConnected(playerid))
{
new
keys, ud, lr;
GetPlayerKeys(playerid, keys, ud, lr);
if(keys & KEY)
{
// Player is holding the key if it gets here
SetTimerEx("KeyCheck", 100, 0, "i", playerid);
return 0;
}
}
HoldingKey[playerid] = false;
return 0;
}
Re: Detecting player for holding key. -
Whizion - 25.10.2010
I'll try it, thank you.
Re: Detecting player for holding key. -
Whizion - 25.10.2010
Update: It works perfectly, thanks again.