Key Press - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Key Press (
/showthread.php?tid=126950)
Key Press -
deather - 11.02.2010
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new hits =0;
if(IsPlayerInArea(playerid, 1728.8699,-1013.6041, 1699.0139,-1032.5679))
{
if ((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE))
{
SendClientMessage(playerid, COLOR_RED, "You are being warned. Donot fight in the party. Else you will be killed");
hit[playerid] = 1;
hits++;
}
}
if(hit[playerid] == 1 &&(newkeys & KEY_FIRE) && (oldkeys & KEY_FIRE))
{
SetPlayerHealth(playerid, 0.0);
}
return 1;
}
Help me with this. i want to kill a player if he presses the fire key twice he must be killed.
Re: Key Press -
mansonh - 11.02.2010
Your Problem is that you will set hit[playerid]=1; as soon as they press fire, then you right after test for it and kill them.
So instead use an else if.
You also/instead might want to disable players weapon.
SetPlayerArmedWeapon(playerid, 0); whenever they press, this way you don't need to worry too much about someone holding down fire.
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new hits =0; //whats this for?
if(IsPlayerInArea(playerid, 1728.8699,-1013.6041, 1699.0139,-1032.5679))
{
if(hit[playerid] == 1 &&(newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE))
{
SetPlayerHealth(playerid, 0.0);
hit[playerid] = 0;
}
else if ((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE))
{
SendClientMessage(playerid, COLOR_RED, "You are being warned. Donot fight in the party. Else you will be killed");
SetPlayerArmedWeapon(playerid, 0);
hit[playerid] = 1;
hits++;
}
}
return 1;
}