21.02.2011, 06:32
(
Последний раз редактировалось Desertsoulz; 19.04.2011 в 14:05.
)
The Code
Version: 1.6
Explained
What it does.
Okay so first, THIS IS NOT MY SCRIPT, it was originally posted by gamer931215 and I modified it to be better for roleplaying!
Now this is very simple, there is to the bottom right a textdraw with your fuel, vehicle health, and your speed in kilometers. Your fuel decreases by 1 every 3 seconds from 100. At 20, it will send a warning, "You are almost out of fuel, go to the nearest gas station!". To refuel, you simply go to a defined gas station and type /refuel, it will turn off your engine, take $20, and give you back to 100 gas. Then after done refueling, it will turn your car engine back on.
What it used to do.
At the bottom right theres a textdraw with your fuel, vehicle health, and your speed in kilometers (This is the same). Your fuel decreased by 2 every second from 100 (Different). (It did not warn you at 20gas.). To refuel you just type /refuel anywhere (different) and it will take $80 and set your gas to 100 (different.). If you did not make it to a gas station on time, it would kick you out of your vehicle (different). (Added engine off/on)
Modifying.
To Modify its simple.
Adding Gas Stations:
Under Line 79 Type,
Amount for Gas:
Around Line 113 and 114
change -20 to your desired amount on both lines (Theres two, one below the other).
Rate Gas Goes Down (RGGD):
RGGD is how many seconds your gas will go down, I have it set to 3, for 1gas every 3 seconds.
To change, go to around line 143 change /3 to your desired amount.
Amount of Gas recieved:
Around lines 157 and 178 change 300 to your desired amount (its 1gas * RGGD) if you want it at 100 and your RGGD at 5 then you put 500, if you want it at 250 and your RGGD is at 2 then it will be 500.
Wait at the Gas Station:
Players are unable to move at the gas station, because it turns off the car engine.
If you want to change the time players have to wait, its on a timer around line 119
Change 4500 to your desired amount (it goes by milliseconds, 4500 is 4.5seconds.)
KNOWN BUGS
When enter car for first time it goes to 99 and not a random number.
AGAIN THIS WAS NOT ORIGINALLY MINE I JUST MODIFIED IT!
If you would like me to modify it some more, post requests below.
Version: 1.6
pawn Код:
#include <a_samp>
new Text:td_fuel[MAX_PLAYERS];
new Text:td_vhealth[MAX_PLAYERS];
new Text:td_vspeed[MAX_PLAYERS];
new Text:td_box[MAX_PLAYERS];
forward timer_update();
forward timer_refuel(playerid);
new isrefuelling[MAX_PLAYERS] = 0;
new fuel[MAX_VEHICLES];
new Float:max_vhealth[MAX_VEHICLES];
new Engine[MAX_PLAYERS];
public OnFilterScriptInit()
{
for(new i=0;i<MAX_VEHICLES;i++) {
GetVehicleHealth(i,max_vhealth[i]); //getting max health
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_vhealth[i] = TextDrawCreate(478,376,"Health:");
td_vspeed[i] = TextDrawCreate(478,397,"Speed:");
td_box[i] = TextDrawCreate(478.000000,328.000000,"Vehicle Stats: ~n~~n~~n~~n~");
TextDrawUseBox(td_box[i],1);
TextDrawBoxColor(td_box[i],0x00000066);
TextDrawTextSize(td_box[i],626.000000,21.000000);
TextDrawAlignment(td_fuel[i],0);
TextDrawAlignment(td_vhealth[i],0);
TextDrawAlignment(td_vspeed[i],0);
TextDrawAlignment(td_box[i],0);
TextDrawBackgroundColor(td_fuel[i],0x000000ff);
TextDrawBackgroundColor(td_vhealth[i],0x000000ff);
TextDrawBackgroundColor(td_vspeed[i],0x000000ff);
TextDrawBackgroundColor(td_box[i],0x000000cc);
TextDrawFont(td_fuel[i],1);
TextDrawLetterSize(td_fuel[i],0.699999,2.699999);
TextDrawFont(td_vhealth[i],1);
TextDrawLetterSize(td_vhealth[i],0.699999,2.699999);
TextDrawFont(td_vspeed[i],1);
TextDrawLetterSize(td_vspeed[i],0.699999,2.699999);
TextDrawFont(td_box[i],0);
TextDrawLetterSize(td_box[i],0.699999,2.899999);
TextDrawColor(td_fuel[i],0xffffffff);
TextDrawColor(td_vhealth[i],0xffffffff);
TextDrawColor(td_vspeed[i],0xffffffff);
TextDrawColor(td_box[i],0xffffffff);
TextDrawSetOutline(td_fuel[i],1);
TextDrawSetOutline(td_vhealth[i],1);
TextDrawSetOutline(td_vspeed[i],1);
TextDrawSetOutline(td_box[i],1);
TextDrawSetProportional(td_fuel[i],1);
TextDrawSetProportional(td_vhealth[i],1);
TextDrawSetProportional(td_vspeed[i],1);
TextDrawSetProportional(td_box[i],1);
TextDrawSetShadow(td_fuel[i],1);
TextDrawSetShadow(td_vhealth[i],1);
TextDrawSetShadow(td_vspeed[i],1);
TextDrawSetShadow(td_box[i],10);
}
SetTimer("timer_update",1000,true);
return 1;
}
public OnFilterScriptExit()
{
for(new i=0;i<MAX_PLAYERS;i++) {
TextDrawDestroy(td_fuel[i]);
TextDrawDestroy(td_vhealth[i]);
TextDrawDestroy(td_vspeed[i]);
TextDrawDestroy(td_box[i]);
}
return 1;
}
stock IsPlayerAtRefuelStation(playerid)
{
if (IsPlayerInRangeOfPoint(playerid,10,655.5993,-564.9833,16.3359)) return 1; //Dilimore
if (IsPlayerInRangeOfPoint(playerid,10,4,5,6)) return 1; //random
return 0;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if (newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
{
TextDrawSetString(td_fuel[playerid],"Fuel:");
TextDrawSetString(td_vhealth[playerid],"Health:");
TextDrawSetString(td_vspeed[playerid],"Speed:");
TextDrawShowForPlayer(playerid,td_fuel[playerid]);
TextDrawShowForPlayer(playerid,td_vspeed[playerid]);
TextDrawShowForPlayer(playerid,td_vhealth[playerid]);
TextDrawShowForPlayer(playerid,td_box[playerid]);
} else {
TextDrawHideForPlayer(playerid,td_fuel[playerid]);
TextDrawHideForPlayer(playerid,td_vspeed[playerid]);
TextDrawHideForPlayer(playerid,td_vhealth[playerid]);
TextDrawHideForPlayer(playerid,td_box[playerid]);
}
return 1;
}
public OnPlayerCommandText(playerid,cmdtext[]) {
if (!strcmp("/refuel",cmdtext,true,7)) {
if (!IsPlayerAtRefuelStation(playerid)) return SendClientMessage(playerid,0xFFC800FF,"You're not at an fuel station!");
if (!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFFC800FF,"You are not in an vehicle!"); //if a player isnt in a vehicle, it stops here
if (isrefuelling[playerid]) return SendClientMessage(playerid,0xFFC800FF,"You are already refuelling!"); //if a player is already refuelling, it stops here
if (GetPlayerMoney(playerid) - 20 <0) return SendClientMessage(playerid,0xFFC800FF,"You dont have enough money!"); //if a player doesnt have $80 anymore, it stops here
GivePlayerMoney(playerid, -20); //Sets the player's cash -$80
SetCameraBehindPlayer(playerid); //Sets the camera behind the player (looks better because the player will be frozen for a few secs)
isrefuelling[playerid] = 1; //setting isrefuelling to 1 so the player cant spam /refuel
TextDrawSetString(td_fuel[playerid],"Refuelling..."); //changing textdraw to /refuel
SetTimerEx("timer_refuel",4500,false,"i",playerid); //setting refueltimer
return 1;
}
return 0;
}
public timer_update()
{
for(new i=0;i<MAX_PLAYERS;i++) {
if (isrefuelling[i]) return 0;
new vid = GetPlayerVehicleID(i);
if (GetPlayerVehicleSeat(i) == 0) {
fuel[vid] = fuel[vid] - 1;
if (fuel[vid]<1)
{
fuel[vid] = 0;
new veh = GetPlayerVehicleID(i);
new engine,lights,alarm,doors,bonnet,boot,objective;
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,Float:health;
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);
GetVehicleHealth(vid,health);
if (max_vhealth[vid] == 0)//if its an random spawned vehicle
{
fuel[vid] = 300;
GetVehicleHealth(vid,max_vhealth[vid]);
}
health = (((health - max_vhealth[vid]) /max_vhealth[vid]) *100)+ 100;
format(string,sizeof string,"Health: %i",floatround(health,floatround_round));
TextDrawSetString(td_vhealth[i],string);
}
return 1;
}
public timer_refuel(playerid)
{
new vid = GetPlayerVehicleID(playerid);
if(Engine[playerid]==0)
{
new veh = GetPlayerVehicleID(playerid);
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(veh,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
Engine[playerid]=1;
}
fuel[vid] = fuel[vid] = 300;
isrefuelling[playerid] = 0;
TextDrawSetString(td_fuel[playerid],"Fuel:100");
}
Explained
What it does.
Okay so first, THIS IS NOT MY SCRIPT, it was originally posted by gamer931215 and I modified it to be better for roleplaying!
Now this is very simple, there is to the bottom right a textdraw with your fuel, vehicle health, and your speed in kilometers. Your fuel decreases by 1 every 3 seconds from 100. At 20, it will send a warning, "You are almost out of fuel, go to the nearest gas station!". To refuel, you simply go to a defined gas station and type /refuel, it will turn off your engine, take $20, and give you back to 100 gas. Then after done refueling, it will turn your car engine back on.
What it used to do.
At the bottom right theres a textdraw with your fuel, vehicle health, and your speed in kilometers (This is the same). Your fuel decreased by 2 every second from 100 (Different). (It did not warn you at 20gas.). To refuel you just type /refuel anywhere (different) and it will take $80 and set your gas to 100 (different.). If you did not make it to a gas station on time, it would kick you out of your vehicle (different). (Added engine off/on)
Modifying.
To Modify its simple.
Adding Gas Stations:
Under Line 79 Type,
pawn Код:
if (IsPlayerInRangeOfPoint(playerid,10,x,y,z)) return 1;
Around Line 113 and 114
change -20 to your desired amount on both lines (Theres two, one below the other).
Rate Gas Goes Down (RGGD):
RGGD is how many seconds your gas will go down, I have it set to 3, for 1gas every 3 seconds.
To change, go to around line 143 change /3 to your desired amount.
Amount of Gas recieved:
Around lines 157 and 178 change 300 to your desired amount (its 1gas * RGGD) if you want it at 100 and your RGGD at 5 then you put 500, if you want it at 250 and your RGGD is at 2 then it will be 500.
Wait at the Gas Station:
Players are unable to move at the gas station, because it turns off the car engine.
If you want to change the time players have to wait, its on a timer around line 119
Change 4500 to your desired amount (it goes by milliseconds, 4500 is 4.5seconds.)
KNOWN BUGS
When enter car for first time it goes to 99 and not a random number.
AGAIN THIS WAS NOT ORIGINALLY MINE I JUST MODIFIED IT!
If you would like me to modify it some more, post requests below.