SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 09/04/2017, 06:34 PM   #1
grymtn
Huge Clucker
 
Join Date: Jun 2013
Posts: 267
Reputation: 26
Default fuel system problem all vehicles use same fuel(enum variables, timers)

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?

Code:
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,bonnet,boot,objective);
				SetVehicleParamsEx(veh,VEHICLE_PARAMS_OFF,lights,alarm,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:temp_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);
}

Last edited by grymtn; 09/04/2017 at 08:17 PM.
grymtn is offline   Reply With Quote
Old 09/04/2017, 06:55 PM   #2
Vin Diesel
Gangsta
 
Vin Diesel's Avatar
 
Join Date: Aug 2011
Location: ŠSA:MP Map EditorŽ
Posts: 528
Reputation: 100
Default Re: fuel system problem all vehicles use same fuel(enum variables, timers)

I'm not sure if this gonna work or not but give it a shot.

Code:
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);
	}
}
__________________
Youtube Channel: EGMido
Vin Diesel is offline   Reply With Quote
Old 09/04/2017, 07:00 PM   #3
grymtn
Huge Clucker
 
Join Date: Jun 2013
Posts: 267
Reputation: 26
Default Re: fuel system problem all vehicles use same fuel(enum variables, timers)

Quote:
Originally Posted by Vin Diesel View Post
I'm not sure if this gonna work or not but give it a shot.

Code:
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);
	}
}
Code:
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 ..
grymtn is offline   Reply With Quote
Old 09/04/2017, 07:07 PM   #4
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,071
Reputation: 2655
Default Re: fuel system problem all vehicles use same fuel(enum variables, timers)

How is "fuel" a property of "player"? If anything it should be a property of "car". What if someone else drives the car?
__________________
Vince is offline   Reply With Quote
Old 09/04/2017, 07:07 PM   #5
Vin Diesel
Gangsta
 
Vin Diesel's Avatar
 
Join Date: Aug 2011
Location: ŠSA:MP Map EditorŽ
Posts: 528
Reputation: 100
Default Re: fuel system problem all vehicles use same fuel(enum variables, timers)

Quote:
Originally Posted by grymtn View Post
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?

Code:
TextDrawSetString(td_fuel1[carid],"Fuel:");
Code:
TextDrawSetString(td_fuel1[vehicleid],"Fuel:");
__________________
Youtube Channel: EGMido
Vin Diesel is offline   Reply With Quote
Old 09/04/2017, 07:23 PM   #6
grymtn
Huge Clucker
 
Join Date: Jun 2013
Posts: 267
Reputation: 26
Default Re: fuel system problem all vehicles use same fuel(enum variables, timers)

Quote:
Originally Posted by Vince View Post
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 is offline   Reply With Quote
Old 09/04/2017, 07:47 PM   #7
grymtn
Huge Clucker
 
Join Date: Jun 2013
Posts: 267
Reputation: 26
Default Re: fuel system problem all vehicles use same fuel(enum variables, timers)

Quote:
Originally Posted by Vin Diesel View Post
Same textdraw value ?

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

Code:
TextDrawSetString(td_fuel1[carid],"Fuel:");
Code:
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 is offline   Reply With Quote
Old 09/04/2017, 08:16 PM   #8
grymtn
Huge Clucker
 
Join Date: Jun 2013
Posts: 267
Reputation: 26
Default Re: fuel system problem all vehicles use same fuel(enum variables, timers)

bump see the new code for more info i need help!
grymtn is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] Fuel System [Fuel/Speed/Vehicle Name/Health] reddromero Filterscripts 5 10/05/2014 02:50 AM
Custom Fuel system taking 2 fuel instead of 1. ricardo178 Scripting Help 6 27/04/2013 10:16 AM
Fuel system - Group vehicles Geniuss Scripting Help 0 08/06/2012 12:45 PM
Fuel system problem swieberdevos Help Archive 10 31/03/2011 05:11 PM


All times are GMT. The time now is 07:45 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.