#define HOLDING(%0) \
((newkeys & (%0)) == (%0))
#define RELEASED(%0) \
(((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
if (IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0)
{
for (new i; i < sizeof(RefuelPickups); i++)
{
if(IsPlayerInRangeOfPoint(playerid, 2.5, RefuelPickups[i][pux], RefuelPickups[i][puy], RefuelPickups[i][puz]))
{
if(HOLDING(KEY_FIRE))
{
if(pInfo[playerid][PlayerMoney] <= RefuelPrice) return SendClientMessage(playerid, RED, "You don't have enough money to refuel!");
TogglePlayerControllable(playerid, 0);
VehicleInfo[vehicleid][Fuel]++;
GameTextForPlayer(playerid, "~g~Refuelling your vehicle...", 3000, 5);
break;
}
}
}
}
if(RELEASED(KEY_FIRE))
{
RewardPlayer(playerid, -RefuelPrice, 0);
TogglePlayerControllable(playerid, 1);
format(RefuelMsg, 128, "Vehicle refuelled! Refuel cost: $%i", RefuelPrice);
SendClientMessage(playerid, BLUE, RefuelMsg);
}
if (IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0)
{
for (new i; i < sizeof(RefuelPickups); i++)
{
if(IsPlayerInRangeOfPoint(playerid, 2.5, RefuelPickups[i][pux], RefuelPickups[i][puy], RefuelPickups[i][puz]))
{
if(HOLDING(KEY_FIRE))
{
if(pInfo[playerid][PlayerMoney] <= RefuelPrice) return SendClientMessage(playerid, RED, "You don't have enough money to refuel!");
TogglePlayerControllable(playerid, 0);
VehicleInfo[vehicleid][Fuel]++;
GameTextForPlayer(playerid, "~g~Refuelling your vehicle...", 3000, 5);
break;
}
if(RELEASED(KEY_FIRE))
{
RewardPlayer(playerid, -RefuelPrice, 0);
TogglePlayerControllable(playerid, 1);
format(RefuelMsg, 128, "Vehicle refuelled! Refuel cost: $%i", RefuelPrice);
SendClientMessage(playerid, BLUE, RefuelMsg);
}
}
}
}
I'm not sure but TogglePlayerControllable function freezes the player, which means that player's control are uncontrollable.
|
// global:
new PlayerTimer_Fuel[MAX_PLAYERS];
// OnPlayerConnect:
PlayerTimer_Fuel[playerid] = -1;
// OnPlayerKeyStateChange:
if(HOLDING(KEY_FIRE))
{
if (!GetPlayerVehicleSeat(playerid))
{
for (new i; i < sizeof(RefuelPickups); i++)
{
if(IsPlayerInRangeOfPoint(playerid, 2.5, RefuelPickups[i][pux], RefuelPickups[i][puy], RefuelPickups[i][puz]))
{
if(pInfo[playerid][PlayerMoney] < RefuelPrice) return SendClientMessage(playerid, RED, "You don't have enough money to refuel!");
TogglePlayerControllable(playerid, 0);
PlayerTimer_Fuel[playerid] = SetTimerEx("RefuelVehicleForPlayer", 1000, true, "ii", playerid, GetPlayerVehicleID(playerid));
break;
}
}
}
}
if(RELEASED(KEY_FIRE))
{
if (PlayerTimer_Fuel[playerid] != -1)
{
RewardPlayer(playerid, -RefuelPrice, 0);
TogglePlayerControllable(playerid, 1);
format(RefuelMsg, 128, "Vehicle refuelled! Refuel cost: $%i", RefuelPrice);
SendClientMessage(playerid, BLUE, RefuelMsg);
KillTimer(PlayerTimer_Fuel[playerid]);
PlayerTimer_Fuel[playerid] = -1;
}
}
forward RefuelVehicleForPlayer(playerid, vehicleid);
public RefuelVehicleForPlayer(playerid, vehicleid)
{
VehicleInfo[vehicleid][Fuel]++;
GameTextForPlayer(playerid, "~g~Refuelling your vehicle...", 3000, 5);
}