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: OnPlayerKeyStateChange (
/showthread.php?tid=640340)
OnPlayerKeyStateChange -
DevHarden - 01.09.2017
PHP код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & KEY_FIRE && !HoldingKey[playerid])
{
KeyCheck(playerid);
HoldingKey[playerid] = true;
}
return true;
}
PHP код:
Server:KeyCheck(playerid)
{
if(IsPlayerConnected(playerid))
{
new keys, ud, lr;
GetPlayerKeys(playerid, keys, ud, lr);
if(keys & KEY_FIRE && IsPlayerUsingFireExting(playerid))
{
SendClientMessage(playerid, COLOR_WHITE, "[DEBUG]: Fire key is being held down for fire extinguisher.");
SetTimerEx("KeyCheck", 500, 0, "i", playerid);
}
}
HoldingKey[playerid] = false;
return false;
}
PHP код:
IsPlayerUsingFireExting(playerid)
{
if(CurrentWeaponID[playerid] == 42) return true;
else return false;
}
Hey guys! I was just experiencing a little issue that I'm not quite able to figure out so I thought I'd run it by some of you guys.
Currently, All of this functions 100% correct but when I use another weapon or hold down the KEY_FIRE with no weapon and then try to use the extinguisher again, then it doesn't function anymore until a restart. Any ideas? Am I missing something obvious?
Thanks ahead of time!
Re: OnPlayerKeyStateChange -
DevHarden - 01.09.2017
Bump
Re: OnPlayerKeyStateChange -
Sew_Sumi - 01.09.2017
https://sampwiki.blast.hk/wiki/OnPlayerK..._holding_a_key
24 hour bumps only as well.
You should just use the natives, rather than making the check lag out like that.
You can easily just put in GetPlayerWeapon into the if statement, rather than have it run a check in another function, other than IsPLayerUsingFireExting...
Less, is better.
Re: OnPlayerKeyStateChange -
DevHarden - 02.09.2017
Quote:
Originally Posted by Sew_Sumi
.
|
The function "IsPlayerUsingFireExting" is currently dumbed down for debugging purposes, originally it checks much more than just the weapon ID otherwise I would be using solely the native functions but I reverted it all the way back to make it simple to try and figure the issue out. And again, Everything functions 100% as intended until I switch weapons away from the extinguisher and then back to it, Then it no longer sends me the debug message until a server restart.
EDIT: I re read what you said and looked over the code again and got it figured out. Thanks for the helpful response.
Re: OnPlayerKeyStateChange -
Sew_Sumi - 02.09.2017
Awesome.