26.07.2013, 17:59
I'm trying to make a simple fuel system to role play gamemode while doing it perfectly right it does wired stuff in-game to the fuel itself, here's what it does: 
This is very wierd! I would give the full code so you can try please help me with it
Under enum pInfo
Under OnPlayerConnect(playerid)
Under OnPlayerRegister(playerid, password[]) & OnPlayerSave(playerid)
Under OnPlayerLogin
Texdraw Under OnPlayerConnect(playerid)
Under OnPlayerStateChange(playerid, newstate, oldstate)
Under OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
Under OtherTimer()
Those Public's are exist along with fuel:
There is a refuel command for player and for admin, the refuel goes through the public's, but the commands isn't the problem, the problem is that the updated Fuel: 100/100 goes crazy while invehicle and i can't figure why, can someone see it and guide me PLEASEE :]

This is very wierd! I would give the full code so you can try please help me with it

Код:
//---- Fuel System ----// new NoFuel[MAX_PLAYERS]; new Refueling[MAX_PLAYERS]; new Gas[MAX_VEHICLES]; new gGas[MAX_PLAYERS]; new Text:Textdraw40[MAX_PLAYERS]; new checkgastimer; new stoppedvehtimer; forward CheckGas(); forward Fillup(); forward StoppedVehicle(); #define GasMax 100 #define RunOutTime 40000 #define RefuelWait 5000
Код:
pFuel,
Код:
NoFuel[playerid] = 0; gGas[playerid] = 1; PlayerInfo[playerid][pFuel] = 0;
Код:
format(var, 32, "Fuel=%d\n",PlayerInfo[playerid][pFuel]);fwrite(hFile, var);
Код:
if( strcmp( key , "Fuel" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pFuel] = strvalEx( val ); }
Код:
Textdraw40[playerid] = TextDrawCreate(498.000000, 140.000000, " "); // fuel TextDrawBackgroundColor(Textdraw40[playerid], 255); TextDrawFont(Textdraw40[playerid], 1); TextDrawLetterSize(Textdraw40[playerid], 0.389999, 1.299999); TextDrawColor(Textdraw40[playerid], 0xFFFFFFFF); TextDrawSetOutline(Textdraw40[playerid], 1); TextDrawSetProportional(Textdraw40[playerid], 1);
Код:
if(newstate == PLAYER_STATE_DRIVER)
{
TextDrawShowForPlayer(playerid, Textdraw40[playerid]);
}
Код:
if(NoFuel[playerid] == 1)
{
TogglePlayerControllable(playerid, 1);
SafeRemovePlayerFromVehicle(playerid);
NoFuel[playerid] = 0;
return 1;
}
Код:
if(gGas[i] == 1)
{
new vehicle = GetPlayerVehicleID(i);
if(IsAPlane(vehicle) || IsABoat(vehicle) || IsABycicle(vehicle) || IsAHelicopter(vehicle))
{
format(string, sizeof(string), "~w~Fuel: ~g~~h~N/A");
}
else if(vehicle >= 1698)
{
format(string, sizeof(string), "~w~Fuel: ~p~Unknown");
}
else
{
if(Gas[vehicle] > 10)
{
format(string, sizeof(string), "~w~Fuel: ~g~~h~%d/~w~100%.",Gas[vehicle]);
}
else
{
format(string, sizeof(string), "~w~Fuel: ~r~~h~%d/~w~100%.",Gas[vehicle]);
}
}
TextDrawSetString(Textdraw40[i], string);
}
Код:
public CheckGas()
{
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerConnected(i))
{
if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
{
new vehicle = GetPlayerVehicleID(i);
if(Gas[vehicle] >= 1)
{
if(Gas[vehicle] <= 10)
{
PlayerPlaySound(i, 1085, 0.0, 0.0, 0.0);
if(gGas[i] == 0)
{
GameTextForPlayer(i,"~w~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~Fuel is low",5000,3);
}
}
if(IsAPlane(vehicle) || IsABycicle(vehicle) || IsABoat(vehicle) || engineOn[vehicle] == 0 || vehicle >= 1579 || IsAHelicopter(vehicle)) { Gas[vehicle]++; }
Gas[vehicle]--;
}
else
{
NoFuel[i] = 1;
TogglePlayerControllable(i, 0);
GameTextForPlayer(i,"~w~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~No fuel in Vehicle",1500,3);
}
}
}
}
return 1;
}
public Fillup()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new VID;
new FillUp;
new string[128];
VID = GetPlayerVehicleID(i);
FillUp = GasMax - Gas[VID];
if(Refueling[i] == 1)
{
if(IsACopsVehicle(VID) || IsAnAgentVehicle(VID) || IsAnAmbulance(VID) || IsAnFiretruck(VID))
{
Gas[VID] += FillUp;
FillUp = FillUp * BizzInfo[3][bEntranceCost];
format(string,sizeof(string),"* Vehicle filled up, for: $%d.",FillUp);
SendClientMessage(i,COLOR_WHITE,string);
GameTextForPlayer(i, "~w~Government has paid for a gas.", 5000, 1);
BizzInfo[3][bTill] += FillUp;
ExtortionBiz(3, FillUp);
Refueling[i] = 0;
SetVehicleParamsEx(VID,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
TogglePlayerControllable(i, 1);
}
else
{
if(GetPlayerMoney(i) >= FillUp+4)
{
Gas[VID] += FillUp;
FillUp = FillUp * BizzInfo[3][bEntranceCost];
format(string,sizeof(string),"* Vehicle filled up, for: $%d.",FillUp);
SendClientMessage(i,COLOR_WHITE,string);
AC_BS_GivePlayerMoney(i, - FillUp);
BizzInfo[3][bTill] += FillUp;
ExtortionBiz(3, FillUp);
Refueling[i] = 0;
SetVehicleParamsEx(VID,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
TogglePlayerControllable(i, 1);
}
else
{
format(string,sizeof(string),"* Not enough Money to refill, it costs $%d to fill your Vehicle.",FillUp);
SendClientMessage(i,COLOR_WHITE,string);
SetVehicleParamsEx(VID,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
TogglePlayerControllable(i, 1);
}
}
}
}
}
return 1;
}
public StoppedVehicle()
{
new Float:x,Float:y,Float:z;
new Float:distance,value;
//foreach(Player, i)
for(new i; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(IsPlayerInAnyVehicle(i))
{
new VID;
VID = GetPlayerVehicleID(i);
GetPlayerPos(i, x, y, z);
distance = floatsqroot(floatpower(floatabs(floatsub(x,SavePlayerPos[i][LastX])),2)+floatpower(floatabs(floatsub(y,SavePlayerPos[i][LastY])),2)+floatpower(floatabs(floatsub(z,SavePlayerPos[i][LastZ])),2));
value = floatround(distance * 3600);
if(UpdateSeconds > 1)
{
value = floatround(value / UpdateSeconds);
}
if(value == 0)
{
Gas[VID]++;
}
SavePlayerPos[i][LastX] = x;
SavePlayerPos[i][LastY] = y;
SavePlayerPos[i][LastZ] = z;
}
}
}
return 1;
}



(