SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 11/02/2010, 09:25 AM   #1
deather
Huge Clucker
 
deather's Avatar
 
Join Date: Dec 2009
Location: India
Posts: 360
Reputation: 3
Default Key Press

Code:
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.
deather is offline  
Old 11/02/2010, 03:31 PM   #2
mansonh
Gangsta
 
Join Date: Jun 2009
Posts: 602
Reputation: 0
Default Re: Key Press

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 Code:
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;
}
__________________
mansonh is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Force a player to press a key? Remba Help Archive 5 12/05/2010 01:50 PM
How to make a player press a key? Torran Help Archive 0 15/03/2010 06:25 PM
Press ALT And Add to jail BLACK-RIDER-1692 Help Archive 7 28/08/2009 10:19 AM
If user press key X... carlos- Help Archive 5 21/07/2009 11:27 PM
[Help] Teleports with press TAB system Cr0ssFir3 Help Archive 2 08/07/2009 05:28 PM


All times are GMT. The time now is 01:17 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.