SA-MP Forums Archive
On Vehicle Refuel Sends Message Many Times - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: On Vehicle Refuel Sends Message Many Times (/showthread.php?tid=267286)



On Vehicle Refuel Sends Message Many Times - Robert_Crawford - 07.07.2011

pawn Код:
CMD:refuel(playerid, params[])
{
    if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        new engine,lights,alarm,doors,bonnet,boot,objective;
        GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
        if(engine == VEHICLE_PARAMS_ON) return SendClientMessageEx(playerid, COLOR_RED, "You need to shut off the engine before filling up (/car engine).");
        if(!IsAtFuelStation(playerid)) return SendClientMessageEx(playerid, COLOR_RED, "You're not at a fuel station.");
        if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510) return SendClientMessageEx(playerid,COLOR_RED,"This vehicle doesn't need fuel.");
        if(VehicleFuel[vehicleid] >= 100.0) return SendClientMessageEx(playerid, COLOR_RED, "This vehicle's tank is already full.");
        if(RefuelingVehicle[playerid] == 1) return SendClientMessageEx(playerid, COLOR_RED, "You are refilling your vehicle's tank.");
        SendClientMessageEx(playerid, COLOR_WHITE, "Refueling your vehicle's tank, please wait.");
        RefuelingVehicle[playerid] = 1;
        RefuelingVehicleTimer[playerid] = SetTimerEx("ReFill", 1000, true, "i", playerid);
    }
    return 1;
}
pawn Код:
stock StopRefueling(playerid)
{
    GivePlayerCash(playerid, -RefuelingVehiclePrice[playerid]);
    SendFormattedMessage(playerid, COLOR_WHITE,"Your vehicle's tank has been refilled for $%d.", RefuelingVehiclePrice[playerid]);

    new mypoint = -1;
    for (new i=0; i<MAX_POINTS; i++)
    {
        if(strcmp(Points[i][Name], "Fossil Fuel Company", true) == 0)
        {
            mypoint = i;
        }
    }
    for(new i = 0; i < sizeof(FamilyInfo); i++)
    {
        if(strcmp(Points[mypoint][Owner], FamilyInfo[i][FamilyName], true) == 0)
        {
            FamilyInfo[i][FamilyBank] = FamilyInfo[i][FamilyBank]+(RefuelingVehiclePrice[playerid]/10);
        }
    }

    RefuelingVehicle[playerid] = 0; RefuelingVehiclePrice[playerid] = 0; KillTimer(RefuelingVehicleTimer[playerid]);
    return true;
}
What happens is it sends the message many times. Maybe i need to kill the timer a different way?


Re: On Vehicle Refuel Sends Message Many Times - Cameltoe - 07.07.2011

I cant see your

RefuelingVehicleTimer[playerid] = SetTimerEx("ReFill", 1000, true, "i", playerid);

"ReFill" function


Re: On Vehicle Refuel Sends Message Many Times - Robert_Crawford - 07.07.2011

At then end of the cmd refuel


Re: On Vehicle Refuel Sends Message Many Times - Cameltoe - 07.07.2011

The refuel stock itself called by RefuelingVehicleTimer[playerid] = SetTimerEx("ReFill", 1000, true, "i", playerid);


Re: On Vehicle Refuel Sends Message Many Times - Robert_Crawford - 07.07.2011

So i would need to move RefuelingVehicleTimer[playerid] = SetTimerEx("ReFill", 1000, true, "i", playerid); to under the stock?


Re: On Vehicle Refuel Sends Message Many Times - Cameltoe - 07.07.2011

Quote:
Originally Posted by Robert_Crawford
Посмотреть сообщение
So i would need to move RefuelingVehicleTimer[playerid] = SetTimerEx("ReFill", 1000, true, "i", playerid); to under the stock?
No, i would like to see the ReFill stock


Re: On Vehicle Refuel Sends Message Many Times - Robert_Crawford - 07.07.2011

There is no stock. Just a callback. Want to see that?


Re: On Vehicle Refuel Sends Message Many Times - Cameltoe - 07.07.2011

Quote:
Originally Posted by Robert_Crawford
Посмотреть сообщение
There is no stock. Just a callback. Want to see that?
Yes
4char


Re: On Vehicle Refuel Sends Message Many Times - Robert_Crawford - 07.07.2011

pawn Код:
forward ReFill(playerid);
public ReFill(playerid)
{
    if(!IsAtFuelStation(playerid) || !IsPlayerInAnyVehicle(playerid) || VehicleFuel[GetPlayerVehicleID(playerid)] >= 100.0 || GetPlayerCash(playerid) < 1)
    {
        StopRefueling(playerid);
    }
    else
    {
        new engine,lights,alarm,doors,bonnet,boot,objective;
        GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective);
        if(engine == VEHICLE_PARAMS_ON) return StopRefueling(playerid);
        VehicleFuel[GetPlayerVehicleID(playerid)] += 1.0; RefuelingVehiclePrice[playerid] += 30;
        if(VehicleFuel[GetPlayerVehicleID(playerid)] >= 100.0) VehicleFuel[GetPlayerVehicleID(playerid)] = 100.0;
    }
    return true;
}
This forum requires that you wait 120 seconds between posts. Please try again in 29 seconds.


Re: On Vehicle Refuel Sends Message Many Times - Robert_Crawford - 09.07.2011

24 Hour Bump