How do I kill this timer?
#1

It should kill the timer if they step out of the vehicle when refuelling.

It's not. But I defined it.

pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(IsRefuelling[playerid] == 1) return SendClientMessage(playerid, COLOUR_GREY, "Refuelling was cancelled as you left the vehicle.");
    IsRefuelling[playerid] = 0;
    KillTimer(RefuelTimer[playerid]); //this timer is the one that's not being killed.
    GameTextForPlayer(playerid, "", 0, 0);
    KillTimer(FuelSysTimer[playerid]);
    KillTimer(SpeedoSysTimer[playerid]);
   
    return 0;
}
Timer Define.
pawn Код:
RefuelTimer[playerid] = SetTimerEx("RefuelUpdate", 1000, true, "i", playerid);
pawn Код:
CMD:refuel(playerid, params[])
{
    if(LoggedIn[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOUR_GREY, "You are not in a vehicle.");
    printf("Checked if in vehicle");
    new string[128];
    if(!IsPlayerInRangeOfPoint(playerid, 20.0, -240.2907,1209.9883,19.7422)&& !IsPlayerInRangeOfPoint(playerid, 50.0,-1327.7439,2675.7014,50.0625) && !IsPlayerInRangeOfPoint(playerid, 10.0, 609.0861,1698.3657,6.9922)) return SendClientMessage(playerid, COLOUR_GREY, "You must be at a Gas Station to refuel.");
        new vehicleid = GetPlayerVehicleID(playerid);
        new amount, sum, num;

        num = 100;
        sum = num -= VehFuel[vehicleid];

        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        if(engine == 1) return SendClientMessage(playerid, COLOUR_GREY, "Please turn your engine off before refuelling.");
        format(string, sizeof(string), "Usage: /refuel [amount] - Use /refuel %d to fill the tank. (You have %d percent fuel left.) (Cost's $2 per %%)", sum, VehFuel[vehicleid]);
        if(sscanf(params, "d", amount)) return SendClientMessage(playerid, COLOUR_GREY, string);
        if(amount > sum) return SendClientMessage(playerid, COLOUR_GREY, "Your vehicle cannot hold this much fuel.");
        if(VehFuel[vehicleid] == num)return SendClientMessage(playerid, COLOUR_GREY, "Your vehicle's fuel tank is full.");

        RefuelAmount[playerid] = amount;
        RefuelTimer[playerid] = SetTimerEx("RefuelUpdate", 1000, true, "i", playerid);
        new price = amount * 2;
        IsRefuelling[playerid] = 1;
        format(string, sizeof(string), "Total cost of fuel($2 per %%): $%d", price);
        SendClientMessage(playerid, COLOUR_WHITE, string);
        GivePlayerMoney(playerid, -price);
        printf("Executed timer and set fuel amount");
        format(string, sizeof(string), "* %s has begun refuelling the vehicle. *", GetNameEx(playerid));
        ProxDetector(10.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
   
    return 1;
}
Reply
#2

Because you are returning a message so it "cuts the wire" before the timer.
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(IsRefuelling[playerid] == 1)
    {
        SendClientMessage(playerid, COLOUR_GREY, "Refuelling was cancelled as you left the vehicle.");
        IsRefuelling[playerid] = 0;
        KillTimer(RefuelTimer[playerid]);
        GameTextForPlayer(playerid, "", 0, 0);
        KillTimer(FuelSysTimer[playerid]);
        KillTimer(SpeedoSysTimer[playerid]);
        return 1;
    }
    return 0;
}
I don't script at ages, but it should work!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)