SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 05/03/2016, 10:20 PM   #1
NeXoR
Gangsta
 
Join Date: Jun 2013
Posts: 577
Reputation: 20
Default HOLDING Key_Fire doesnt work

Hey guys, So I tried to edit a Fire script (RP)

And only when I click the fire key it reduces the Fire HP, it's supposed to keep reducing it as long as I hold the key
Code:
Code:
if (HOLDING( KEY_FIRE ))
	{
		new Float:fx, Float:fy, Float:fz;
		GetDynamicObjectPos(FireObject, fx, fy, fz);
		new string[256];
        if(GetPlayerWeapon(playerid) == 42 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 407)
        {
            if(IsPlayerInRangeOfPoint(playerid, 40.0, fx,  fy,  fz))
 	        {
			   	FireHealth -= 1;
				format(string, sizeof(string), "%d/100%", FireHealth);
				Update3DTextLabelText(FireText, GREEN, string);
			    if(FireHealth <= 0)
			    {
					DestroyDynamicObject(FireObject);
					DestroyDynamicObject(SmokeObject);ww
					Delete3DTextLabel(FireText);
					FireHealth = 0;
					FireTimer = SetTimer("StartRandomFire", 900000, false);
					format(string, sizeof(string), "Auto-Dispatcher: The fire that was started has been successfully put out. Continue with normal duties.");
					foreach(Player, i)
					{
	    				if(IsACop(i) || IsAGov(i) || IsMedic(i) || IsSASD(i))
	    				{
							SendClientMessage(i, COLOR_DEPTRADIO, string);
	    				}
	    			}
					return 1;
				}
			}
		}
	}
HOLDING Define:
Code:
#define HOLDING(%0) \
	((newkeys & (%0)) == (%0))
NeXoR is offline   Reply With Quote
Old 06/03/2016, 08:22 AM   #2
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,079
Reputation: 2655
Default Re: HOLDING Key_Fire doesnt work

I'm just going to quote myself from another thread:

Quote:
Originally Posted by Vince View Post
The HOLDING macro is often used wrongly. What is usually desired is PRESSED and RELEASED. OnPlayerKeyStateChange is only called when a key changes. You can press and then hold KEY_FIRE for an eternity but it will still only register a press when you first press it and a release when you release it. Only if you press an additional while still holding KEY_FIRE will it register as holding.

You will need to set a timer when they first press the key and it and kill the timer when they release it. Alternatively, set and unset a variable and use OnPlayerUpdate if you require faster interaction.
__________________
Vince is offline   Reply With Quote
Old 06/03/2016, 05:33 PM   #3
NeXoR
Gangsta
 
Join Date: Jun 2013
Posts: 577
Reputation: 20
Default Re: HOLDING Key_Fire doesnt work

Quote:
Originally Posted by Vince View Post
I'm just going to quote myself from another thread:
Ugh, thanks I guess
Can u just explain it more in description that way with the timer ? I mean a small example of a few lines
NeXoR is offline   Reply With Quote
Old 06/03/2016, 08:10 PM   #4
[XST]O_x
High-roller
 
[XST]O_x's Avatar
 
Join Date: Aug 2009
Posts: 1,962
Reputation: 94
Default Re: HOLDING Key_Fire doesnt work

He means:
pawn Code:
new pHoldingKeyFire[ MAX_PLAYERS ];

public OnPlayerKeyState...
{
    if(PRESSED(KEY_FIRE))
        pHoldingKeyFire[playerid] = 1;
    if(RELEASED(KEY_FIRE))
        pHoldingKeyFire[playerid] = 0;
    return 1;
}

When you want to check if a player is holding KEY_FIRE, just use
pawn Code:
if(pHoldingKeyFire[playerid])
{
    //Do something
}
[XST]O_x is offline   Reply With Quote
Old 06/03/2016, 09:33 PM   #5
NeXoR
Gangsta
 
Join Date: Jun 2013
Posts: 577
Reputation: 20
Default Re: HOLDING Key_Fire doesnt work

Quote:
Originally Posted by [XST]O_x View Post
He means:
pawn Code:
new pHoldingKeyFire[ MAX_PLAYERS ];

public OnPlayerKeyState...
{
    if(PRESSED(KEY_FIRE))
        pHoldingKeyFire[playerid] = 1;
    if(RELEASED(KEY_FIRE))
        pHoldingKeyFire[playerid] = 0;
    return 1;
}

When you want to check if a player is holding KEY_FIRE, just use
pawn Code:
if(pHoldingKeyFire[playerid])
{
    //Do something
}
Thank you
(+rep for both of you guys )
NeXoR is offline   Reply With Quote
Reply

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
ELM doesnt work? reckst4r Client Support 1 04/12/2011 01:07 PM
SplitText doesnt work + Object doesnt attach KfirRP Help Archive 6 04/08/2011 01:42 AM
function doesnt work as i want it to work. legodude Help Archive 0 14/03/2011 02:25 PM
SA-MP doesnt work grimmy149 Client Support 3 01/09/2009 10:52 PM
My Gta doesnt work :S Criss_Angel Client Support 3 28/08/2009 11:47 AM


All times are GMT. The time now is 12:15 PM.


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