Refueling Timer Problem
#1

Hello Everybody,

I have got a problem with my Fuel System ..
I guess it is a Timer matter ..

The problem is that when I do /refuel , I keep geting this Message every second : "Your vehicle's tank has been refilled for $100.", then my money keeps getting reduced by 100$ at every message,
And I don't even get any fuel !!!
...
So, I thought That I have to Kill The Timer RefuelingVehicleTimer .. But I've already this in the StopRefueling stock :

Код:
KillTimer(RefuelingVehicleTimer[playerid] = 6000);
I'm not really familiar with the timers ...

So, Let me just show you some code :

The Command :

Код:
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 (Press 'N').");
	    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;
}
Refill (callback)

Код:
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;
}
stock StopRefueling :

Код:
stock StopRefueling(playerid)
{
	GivePlayerCash(playerid, -100);
  	SendFormattedMessage(playerid, COLOR_WHITE,"Your vehicle's tank has been refilled for $100.");
  	
	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] = 6000);
	return true;
}

Can anyone, please, help me with this ?
I'm really stuck ..
Thanks in advance.



_
Reply
#2

PHP код:
RefuelingVehicleTimer[playerid] = 6000 
What is the point of the

PHP код:
6000 
Also,you are checking if the players cash is not lower than 1, even though the cost should be hundred

And if the player isn't inside of a car he will still loose 100 because stoprefilling will be called

And i think you should start indenting your code properly (just don't mix tabs and spaces pls ) and not make rows of statements (multiple statements on 1 line), because it lowers the readability.
Reply
#3

I removed this :

PHP код:
6000 
but still the same problem ..
Please Help ..
Reply
#4

You set timer to repeat pass false instead of true to that parameter

Код:
	RefuelingVehicleTimer[playerid] = SetTimerEx("ReFill", 1000, true, "i", playerid);
Now about not getting fuel (assuming your function is correct on the basis of logical concept) debug this part
PHP код:
if(!IsAtFuelStation(playerid) || !IsPlayerInAnyVehicle(playerid) || VehicleFuel[GetPlayerVehicleID(playerid)] >= 100.0 || GetPlayerCash(playerid) < 1)
    {
        
StopRefueling(playerid);
                
printf("IsAtFuelStation(playerid) = %d IsPlayerInAnyVehicle(playerid)=%d   VehicleFuel[GetPlayerVehicleID(playerid)] = %d GetPlayerCash(playerid) = %d",IsAtFuelStation(playerid),IsPlayerInAnyVehicle(playerid),VehicleFuel[GetPlayerVehicleID(playerid)],GetPlayerCash(playerid) < 1));
    } 
Reply
#5

I did exactly what you've told me..
It just says "Refueling your vehicle's tank, please wait." then I'm waiting forever .. nothing happens .. Please help ..
Reply
#6

How exactly do you know you aren't getting fuel? Are you updating your fuel display enough to show that you are?

Output the refill status to SendClientMessage so you can see that it is actually filling.
Reply
#7

Quote:
Originally Posted by MiiSha
Посмотреть сообщение
I did exactly what you've told me..
It just says "Refueling your vehicle's tank, please wait." then I'm waiting forever .. nothing happens .. Please help ..
Where is the debug output? did anything print on console?
Reply
#8

it is not filling I have a progress bar and a Command that shows my car status .. I am very sure that I'm not getting the fuel !
And The Debug did not print at all.
Reply
#9

Quote:
Originally Posted by MiiSha
Посмотреть сообщение
it is not filling I have a progress bar and a Command that shows my car status .. I am very sure that I'm not getting the fuel !
And The Debug did not print at all.
Please debug it like this and review the output (assuming VehicleFuel[GetPlayerVehicleID(playerid)] is var holding fuel)
PHP код:
forward ReFill(playerid);
public 
ReFill(playerid)
{
    
printf("entered function Refill");
    if(!
IsAtFuelStation(playerid) || !IsPlayerInAnyVehicle(playerid) || VehicleFuel[GetPlayerVehicleID(playerid)] >= 100.0 || GetPlayerCash(playerid) < 1)
    {
        
printf("IsAtFuelStation(playerid) = %d IsPlayerInAnyVehicle(playerid)=%d   VehicleFuel[GetPlayerVehicleID(playerid)] = %d GetPlayerCash(playerid) = %d",IsAtFuelStation(playerid),IsPlayerInAnyVehicle(playerid),VehicleFuel[GetPlayerVehicleID(playerid)],GetPlayerCash(playerid) < 1)); 
        
StopRefueling(playerid);
    }
    else
    {
        
printf("else");
        new 
engine,lights,alarm,doors,bonnet,boot,objective;
        
GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective);
        if(
engine == VEHICLE_PARAMS_ON
        {
            
printf("engine == VEHICLE_PARAMS_ON");
            return 
StopRefueling(playerid);
        }
        
printf("Before VehicleFuel[GetPlayerVehicleID(playerid)] = %d",VehicleFuel[GetPlayerVehicleID(playerid)]);
        
VehicleFuel[GetPlayerVehicleID(playerid)] += 1.0RefuelingVehiclePrice[playerid] += 30;
        
printf("After VehicleFuel[GetPlayerVehicleID(playerid)] = %d",VehicleFuel[GetPlayerVehicleID(playerid)]);
        if(
VehicleFuel[GetPlayerVehicleID(playerid)] >= 100.0
        {
            
printf("if(VehicleFuel[GetPlayerVehicleID(playerid)] >= 100.0)");
            
VehicleFuel[GetPlayerVehicleID(playerid)] = 100.0;
        }
        
    }
    return 
true;

Reply
#10

FIXED !!
there were some variables and functions that are misconfigured .. like that one :

PHP код:
if(VehicleFuel[GetPlayerVehicleID(playerid)] >= 100.0
it should be like this :

PHP код:
if(VehicleFuel[GetPlayerVehicleID(playerid)] < 100.0
So that if the Vehicle Fuel was under 100% that it would be filled in not if it equals 100 or bigger than 100 ..
not only this one but many of them I had to Fix ..

Thanks Everyone anyway for your Considerable Help !!
Rep+ to everyone ..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)