09.04.2017, 18:34
(
Последний раз редактировалось grymtn; 09.04.2017 в 20:17.
)
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,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); }