HOLDING Key_Fire doesnt work
#1

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:
Код:
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:
Код:
#define HOLDING(%0) \
	((newkeys & (%0)) == (%0))
Reply
#2

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

Quote:
Originally Posted by Vince
Посмотреть сообщение
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.
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
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
Reply
#4

He means:
pawn Код:
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 Код:
if(pHoldingKeyFire[playerid])
{
    //Do something
}
Reply
#5

Quote:
Originally Posted by [XST]O_x
Посмотреть сообщение
He means:
pawn Код:
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 Код:
if(pHoldingKeyFire[playerid])
{
    //Do something
}
Thank you
(+rep for both of you guys )
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)