PDA

View Full Version : fuel system problem all vehicles use same fuel(enum variables, timers)


grymtn
09/04/2017, 06:34 PM
hello friend i have a fuel system and vehicle ownership that i developed more over a filtescript found from here. Players can own up to 3 cars but they all share same fuel even tho i created different varibles and different timers. Can somebodey take a look?


new Text:td_fuel[MAX_PLAYERS];
new Text:td_vspeed[MAX_PLAYERS];
forward timer_update(playerid);
forward timer_refuel(playerid);
new isrefuelling[MAX_PLAYERS] = 0;
new fuel[MAX_VEHICLES];
new Engine[MAX_PLAYERS];

public OnGameModeInit(){
for(new i=0;i<MAX_VEHICLES;i++) {
fuel[i] = 250 + random(150); //setting fuel for vehicles
}
for(new i=0;i<MAX_PLAYERS;i++) { //setting up all textdraws
td_fuel[i] = TextDrawCreate(476,355,"Fuel:");
td_vspeed[i] = TextDrawCreate(478,397,"Speed:");
TextDrawAlignment(td_fuel[i],0);
TextDrawAlignment(td_vspeed[i],0);
TextDrawBackgroundColor(td_fuel[i],0x000000ff);
TextDrawBackgroundColor(td_vspeed[i],0x000000ff);
TextDrawFont(td_fuel[i],1);
TextDrawLetterSize(td_fuel[i],0.699999,2.699999);
TextDrawFont(td_vspeed[i],1);
TextDrawLetterSize(td_vspeed[i],0.699999,2.699999);
TextDrawColor(td_fuel[i],0xffffffff);
TextDrawColor(td_vspeed[i],0xffffffff);
TextDrawSetOutline(td_fuel[i],1);
TextDrawSetOutline(td_vspeed[i],1);
TextDrawSetProportional(td_fuel[i],1);
TextDrawSetProportional(td_vspeed[i],1);
TextDrawSetShadow(td_fuel[i],1);
TextDrawSetShadow(td_vspeed[i],1);
}
SetTimer("timer_update",1000,true);
blablabla(goes on)
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if (newstate == PLAYER_STATE_DRIVER)
{
TextDrawSetString(td_fuel[playerid],"Fuel:");
TextDrawSetString(td_vspeed[playerid],"Speed:");

TextDrawShowForPlayer(playerid,td_fuel[playerid]);
TextDrawShowForPlayer(playerid,td_vspeed[playerid]);
}
if( newstate == PLAYER_STATE_ONFOOT || newstate == PLAYER_STATE_PASSENGER)
{
TextDrawHideForPlayer(playerid,td_fuel[playerid]);
TextDrawHideForPlayer(playerid,td_vspeed[playerid]);
}
return 1;
}
public timer_update(playerid)
{
for(new i=0;i<MAX_PLAYERS;i++) {
if (isrefuelling[i]) return 0;
new vid = GetPlayerVehicleID(i);
if (GetPlayerVehicleSeat(i) == 0) {
if(PlayerInfo[i][pVehicle1Engine]==1){
fuel[vid] = fuel[vid] - 1;
}
if(PlayerInfo[i][pVehicle1Engine]==2){
fuel[vid] = fuel[vid] - 1;
}
if(PlayerInfo[i][pVehicle1Engine]==3){
fuel[vid] = fuel[vid] - 1;
}
if (fuel[vid]<1)
{
fuel[vid] = 0;
new veh = GetPlayerVehicleID(i);
new engine,lights,alarm,doors,bonnet,boot,objective;
PlayerInfo[i][pVehicle1Engine]=0;
GetVehicleParamsEx(veh,engine,lights,alarm,doors,b onnet,boot,objective);
SetVehicleParamsEx(veh,VEHICLE_PARAMS_OFF,lights,a larm,doors,bonnet,boot,objective);
Engine[i]=0;
GameTextForPlayer(i,"~r~You are out of ~w~fuel~r~!",5000,4);
}
}
new string[128];format(string,sizeof string,"Fuel: %i",fuel[vid] /3);
TextDrawSetString(td_fuel[i],string);

new Float:speed_x,Float:speed_y,Float:speed_z,Float:te mp_speed,final_speed;

GetVehicleVelocity(vid,speed_x,speed_y,speed_z);
temp_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+ (speed_z*speed_z))*136.666667;
final_speed = floatround(temp_speed,floatround_round);
format(string,sizeof string,"Speed: %i",final_speed);
TextDrawSetString(td_vspeed[i],string);
}
return 1;
}
public timer_refuel(playerid)
{
new vid = GetPlayerVehicleID(playerid);
fuel[vid] = 30000;
isrefuelling[playerid] = 0;
TextDrawSetString(td_fuel[playerid],"Fuel:10000");
TogglePlayerControllable(playerid,1);
}

Vin Diesel
09/04/2017, 06:55 PM
I'm not sure if this gonna work or not but give it a shot.

public timer_refuel(playerid)
{
new vid = GetPlayerVehicleID(playerid);
if(vid==personalcar1[playerid]){
PlayerInfo[playerid][Fuel1] = 30000;
isrefuelling[playerid] = 0;
TextDrawSetString(td_fuel[playerid],"Fuel:10000");
TogglePlayerControllable(playerid,1);
}
else if(vid==personalcar2[playerid]){
PlayerInfo[playerid][Fuel2] = 30000;
isrefuelling[playerid] = 0;
TextDrawSetString(td_fuel[playerid],"Fuel:900"); //edited
TogglePlayerControllable(playerid,1);
}
else if(vid==personalcar3[playerid]){
PlayerInfo[playerid][Fuel3] = 30000;
isrefuelling[playerid] = 0;
TextDrawSetString(td_fuel[playerid],"Fuel:800"); //edited
TogglePlayerControllable(playerid,1);
}
}

grymtn
09/04/2017, 07:00 PM
I'm not sure if this gonna work or not but give it a shot.

public timer_refuel(playerid)
{
new vid = GetPlayerVehicleID(playerid);
if(vid==personalcar1[playerid]){
PlayerInfo[playerid][Fuel1] = 30000;
isrefuelling[playerid] = 0;
TextDrawSetString(td_fuel[playerid],"Fuel:10000");
TogglePlayerControllable(playerid,1);
}
else if(vid==personalcar2[playerid]){
PlayerInfo[playerid][Fuel2] = 30000;
isrefuelling[playerid] = 0;
TextDrawSetString(td_fuel[playerid],"Fuel:900"); //edited
TogglePlayerControllable(playerid,1);
}
else if(vid==personalcar3[playerid]){
PlayerInfo[playerid][Fuel3] = 30000;
isrefuelling[playerid] = 0;
TextDrawSetString(td_fuel[playerid],"Fuel:800"); //edited
TogglePlayerControllable(playerid,1);
}
}

TextDrawSetString(td_fuel[playerid],"Fuel:900");

these ones show for only one second after that it returns to normal value which is using same fuel ..

Vince
09/04/2017, 07:07 PM
How is "fuel" a property of "player"? If anything it should be a property of "car". What if someone else drives the car?

Vin Diesel
09/04/2017, 07:07 PM
Players can own up to 3 cars but they all share same fuel even tho i created different varibles and different timers. Can somebodey take a look?[/CODE]

Same textdraw value ?

Why you don't try to make it like this?

TextDrawSetString(td_fuel1[carid],"Fuel:");

TextDrawSetString(td_fuel1[vehicleid],"Fuel:");

grymtn
09/04/2017, 07:23 PM
How is "fuel" a property of "player"? If anything it should be a property of "car". What if someone else drives the car?

that means i have to change my whole car script doesnt it? i didnt think that thru fu..

grymtn
09/04/2017, 07:47 PM
Same textdraw value ?

Why you don't try to make it like this?

TextDrawSetString(td_fuel1[carid],"Fuel:");

TextDrawSetString(td_fuel1[vehicleid],"Fuel:");

no you got me wrong i mean refueling personalcar1 refuels personalcar2 and 3 too also using personalcar1 uses personalcar2 and 3's fuel too because its like all have been set same

grymtn
09/04/2017, 08:16 PM
bump see the new code for more info i need help!