Timer Problem
#1

pawn Код:
forward GasPumpSaleTimer(playerid, business);
public GasPumpSaleTimer(playerid, business)
{
        new iVehicleID = GetPVarInt(playerid, "Refuelling"), Float: fPumpAmount = 0.1 / 4, szLabel[128];

        if(fPumpAmount*10 + iVehicleFuel[iVehicleID] > 100.0)
        {
            SendClientMessage(playerid, COLOR_LIGHTBLUE, "* The vehicles fuel tank is now full. *");
            StopRefuellingVehicle(playerid, business);
            return 1;
        }
        else if(IsRefuelling[playerid] == 0)
        {
            SendClientMessage(playerid, COLOR_LIGHTRED, "* You have stopped refueling. *");
            StopRefuellingVehicle(playerid, business);
            KillTimer(GasPumpTimer[playerid]);
            return 1;
        }
        else if(fPumpAmount > BusinessInfo[business][bI_GasPumpGallons])
        {
            SendClientMessage(playerid, COLOR_LIGHTRED, "* There is no more gallons of gas left in the pump, please come back later. *");
            StopRefuellingVehicle(playerid, business);
            return 1;
        }
        else if(PlayerData[playerid][p_Money] < floatround(BusinessInfo[business][bI_GasSalePrice]))
        {
            SendClientMessage(playerid, COLOR_LIGHTRED, "* You cannot afford anymore fuel. *");
            StopRefuellingVehicle(playerid, business);
            return 1;
        }
        else if(GetVehicleDistanceFromPoint(iVehicleID, BusinessInfo[business][bI_GasPumpPos][0], BusinessInfo[business][bI_GasPumpPos][1], BusinessInfo[business][bI_GasPumpPos][2]) > 5.0)
        {
            StopRefuellingVehicle(playerid, business);
            return 1;
        }

        BusinessInfo[business][bI_GasPumpGallons] -= fPumpAmount;
        iVehicleRefuel[iVehicleID] += fPumpAmount*10;
        BusinessInfo[business][bI_SaleGallons] += fPumpAmount;
        BusinessInfo[business][bI_GasSalePrice] += fPumpAmount * BusinessInfo[business][bI_GasPrice];
        format(szLabel, sizeof(szLabel), "[ Sale Total: $%.2f\n[ Gallons: %.3f ]\n\n[ Price Per Gallon: $%.2f ]\n[ Gas Available: %.2f/%.2f gallons ]", BusinessInfo[business][bI_GasSalePrice], BusinessInfo[business][bI_SaleGallons], BusinessInfo[business][bI_GasPrice], BusinessInfo[business][bI_GasPumpGallons], BusinessInfo[business][bI_GasPumpCapacity]);
        UpdateDynamic3DTextLabelText(BusinessInfo[business][bI_GasPumpText], COLOR_YELLOW, szLabel);
        DeletePVar(playerid, "StoppingGasTimer");
    return 1;
}
StopRefuellingVehicle function:
pawn Код:
StopRefuellingVehicle(playerid, business)
{
    new iCost = floatround(BusinessInfo[business][bI_GasSalePrice]), iVehicleID = GetPVarInt(playerid, "Refuelling"), iPlayerVeh = GetPlayerVehicle(playerid, GetPlayerVehicleID(playerid));

    format(szOutput, sizeof(szOutput), "* You have refilled your vehicle's fuel tank for: $%d. *", iCost);
    SendClientMessage(playerid, COLOR_LIGHTBLUE, szOutput);

    if(GetPlayerVehicle(playerid, GetPlayerVehicleID(playerid))) // Player Owned Veh
    {
        VehicleInfo[playerid][iPlayerVeh][pv_Fuel] += iVehicleRefuel[iVehicleID];
        GivePlayerCash(playerid, -iCost);
    }
    if(IsAFactionVehicle(GetPlayerVehicleID(playerid))) // Fac Veh
    {
        iVehicleFuel[iVehicleID] += iVehicleRefuel[iVehicleID];
        FactionInfo[PlayerData[playerid][p_Faction]][fI_vBalance] -= iCost;
        SendClientMessage(playerid, COLOR_WHITE, "As this is a faction vehicle, they have paid for the fuel.");
    }
    else { // Random Veh
        iVehicleFuel[iVehicleID] +=iVehicleRefuel[iVehicleID];
        GivePlayerCash(playerid, -iCost);
    }

    DeletePVar(playerid, "Refuelling");
    BusinessInfo[business][bI_GasPumpStatus] = 0;
    KillTimer(GasPumpTimer[playerid]);
    return 1;
}
I have this for my gas pumps, and basically whenever I do /refuel which sets the IsRefuelling variable to 0 so then StopRefuellingVehicle is called, it spams " You have stopped refueling. " and "You have refilled your vehicle's fuel tank for: $%d. "

Refuel CMD: http://pastebin.com/KP5YAYqf

Any idea why?

Thanks!
Reply
#2

how is this whole thing launched ?
looks like your have more then 1 timer or the timer is never killed because of not assigning it properly.
Reply
#3

Quote:
Originally Posted by park4bmx
Посмотреть сообщение
how is this whole thing launched ?
looks like your have more then 1 timer or the timer is never killed because of not assigning it properly.
That's the thing, the timer is only called once.. and it is killed?

Is there a way to check if it's properly killed or not?
Reply
#4

pawn Код:
if(GasPumpTimer[playerid] != -1) // running
Reply
#5

Quote:
Originally Posted by park4bmx
Посмотреть сообщение
pawn Код:
if(GasPumpTimer[playerid] != -1) // running
Error still occuring after adding that in, it seems the timer won't stop..
Reply
#6

that is to check if the timer is running not to stop it or anything...

Show how you call
"GasPumpSaleTimer()"
Reply
#7

Quote:
Originally Posted by park4bmx
Посмотреть сообщение
that is to check if the timer is running not to stop it or anything...

Show how you call
"GasPumpSaleTimer()"
GasPumpTimer[playerid] = SetTimerEx("GasPumpSaleTimer", 250, true, "ii", playerid, b);
Reply
#8

bump - error still occruing
Reply
#9

anyone? sake
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)