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; } } } }
#define HOLDING(%0) \ ((newkeys & (%0)) == (%0))
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. |
new pHoldingKeyFire[ MAX_PLAYERS ];
public OnPlayerKeyState...
{
if(PRESSED(KEY_FIRE))
pHoldingKeyFire[playerid] = 1;
if(RELEASED(KEY_FIRE))
pHoldingKeyFire[playerid] = 0;
return 1;
}
if(pHoldingKeyFire[playerid])
{
//Do something
}
He means:
pawn Код:
pawn Код:
|