KillTimer problem in Fuel System
#1

Код HTML:
new RefuelingVehicle[MAX_PLAYERS];
new RefuelingVehiclePrice[MAX_PLAYERS];
new RefuelingVehicleTimer[MAX_PLAYERS];

stock StopRefueling(playerid)
{
	GivePlayerCash(playerid, -RefuelingVehiclePrice[playerid]);

	new string[128];
	format(string, sizeof(string), "Your vehicle's tank has been refilled for $%d.", RefuelingVehiclePrice[playerid]);
	SendClientMessageEx(playerid, COLOR_WHITE,string);

	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);
		}
	}
 	KillTimer(RefuelingVehicleTimer[playerid]);
 	RefuelingVehicle[playerid] = 0;
 	RefuelingVehiclePrice[playerid] = 0;
	return true;
}

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;
}
Код HTML:
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) {
			StopRefueling(playerid);
		}
		else {
			VehicleFuel[GetPlayerVehicleID(playerid)] += 1.0;
			RefuelingVehiclePrice[playerid] += 30;
			if(VehicleFuel[GetPlayerVehicleID(playerid)] >= 100.0) VehicleFuel[GetPlayerVehicleID(playerid)] = 100.0;
		}
	}
	return true;
}
Reply
#2

You might want to explain us what's the problem you're experiencing with this code.
Reply
#3

The timer is not working.
Its dont stop the refueling in the game and keep take money from the account.
Reply
#4

Well, you have to kill the timer to make it stop.
https://sampwiki.blast.hk/wiki/KillTimer

pawn Код:
if(VehicleFuel[GetPlayerVehicleID(playerid)] >= 100.0)
{
      VehicleFuel[GetPlayerVehicleID(playerid)] = 100.0;
     KillTimer( RefuelingVehicleTimer[playerid]);
}
Reply
#5

Still dont work

Код HTML:
stock StopRefueling(playerid)
{
	GivePlayerCash(playerid, -RefuelingVehiclePrice[playerid]);

	new string[128];
	format(string, sizeof(string), "Your vehicle's tank has been refilled for $%d.", RefuelingVehiclePrice[playerid]);
	SendClientMessageEx(playerid, COLOR_WHITE,string);

	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);
		}
	}
    if(VehicleFuel[GetPlayerVehicleID(playerid)] >= 100.0)
    {
      	VehicleFuel[GetPlayerVehicleID(playerid)] = 100.0;
     	KillTimer(RefuelingVehicleTimer[playerid]);
	}
	RefuelingVehicle[playerid] = 0;
 	RefuelingVehiclePrice[playerid] = 0;
	return true;
}
Reply
#6

No... you should add that inthe ReFill function.
Reply
#7

Now it just say
You are refilling your vehicle's tank.
and its dont take money and dont refuel it

Код HTML:
forward ReFill(playerid);
public ReFill(playerid)
{
	if(VehicleFuel[GetPlayerVehicleID(playerid)] >= 100.0)
	{
      	VehicleFuel[GetPlayerVehicleID(playerid)] = 100.0;
     	KillTimer(RefuelingVehicleTimer[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) {
			StopRefueling(playerid);
		}
		else {
			VehicleFuel[GetPlayerVehicleID(playerid)] += 1.0;
			RefuelingVehiclePrice[playerid] += 30;
			if(VehicleFuel[GetPlayerVehicleID(playerid)] >= 100.0) VehicleFuel[GetPlayerVehicleID(playerid)] = 100.0;
		}
	}
	return true;
}
Reply
#8

help?
Reply
#9

help?
Reply
#10

Your first code is good. I think the problem might be with float comparison, but let's debug some more first
pawn Код:
printf("%f >= %f == %d", VehicleFuel[GetPlayerVehicleID(playerid)], 100.0, VehicleFuel[GetPlayerVehicleID(playerid)] >= 100.0)
Put this in your ReFill function, and tell me what does it print after VehicleFuel[GetPlayerVehicleID(playerid)] is bigger than 100
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)