24.11.2013, 18:20
Well I'm wondering how to get a number between X and MAX this is based on my filterscript that I'm scripting ![Smiley](images/smilies/smile.png)
It's about fuel number, so I want to somehow detect how much fuel player filled in his vehicle, for example:
"(name) has refuel his vehicle with 60 liters of fuel"..
and second questions.. code is working good, but do you see any mistake or something to fix?..
Here is my /refuel code:
EDIT: command is based on this callback
And again, thanks in advance ^^
![Smiley](images/smilies/smile.png)
It's about fuel number, so I want to somehow detect how much fuel player filled in his vehicle, for example:
"(name) has refuel his vehicle with 60 liters of fuel"..
and second questions.. code is working good, but do you see any mistake or something to fix?..
Here is my /refuel code:
pawn Код:
if(strcmp(cmdtext, "/refuel", true) == 0)
{
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You need to be in vehicle to use this command.");
if(IsRefuelling[playerid] == true) return SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You are already refueling!");
if(IsPlayerInRangeOfGasStations(playerid)) // credits goes to "Konstantinos" - he helped me to detect coords..
{
if(Carinfo[vehicleid][F] >= 99) return SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}Your fuel tank is full!");
if(engine == 1) return SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You need to turn off engine befure refueling your vehicle!");
else
{
//KillTimer(GasTimer[playerid]); // It will kill timer to avoid any bugs
if(Carinfo[vehicleid][F] > 90 && Carinfo[vehicleid][F] < 99) GasPrice = 50;
if(Carinfo[vehicleid][F] > 80 && Carinfo[vehicleid][F] < 90) GasPrice = 100;
if(Carinfo[vehicleid][F] > 70 && Carinfo[vehicleid][F] < 80) GasPrice = 150;
if(Carinfo[vehicleid][F] > 60 && Carinfo[vehicleid][F] < 70) GasPrice = 200;
if(Carinfo[vehicleid][F] > 50 && Carinfo[vehicleid][F] < 60) GasPrice = 250;
if(Carinfo[vehicleid][F] > 40 && Carinfo[vehicleid][F] < 50) GasPrice = 300;
if(Carinfo[vehicleid][F] > 30 && Carinfo[vehicleid][F] < 40) GasPrice = 350;
if(Carinfo[vehicleid][F] > 20 && Carinfo[vehicleid][F] < 30) GasPrice = 400;
if(Carinfo[vehicleid][F] > 10 && Carinfo[vehicleid][F] < 20) GasPrice = 450;
if(Carinfo[vehicleid][F] < 10) GasPrice = 500;
if(GetPlayerMoney(playerid) < GasPrice) return SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You don't have enough money.");
IsRefuelling[playerid] = true;
SetCameraBehindPlayer(playerid);
TogglePlayerControllable(playerid, 0);
GameTextForPlayer(playerid, "Refuelling...", 1000, 5);
SetTimerEx("RefuelVehicle", 5000, 0, "d", playerid);
}
}
else SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You are not near any gas pump.");
return 1;
}
pawn Код:
public RefuelVehicle(playerid)
{
new vehicleid = GetPlayerVehicleID(playerid);
new Fuela = MAX_FUEL - Carinfo[vehicleid][F];
new string[128];
Carinfo[vehicleid][F] = Carinfo[vehicleid][F] = 100;
IsRefuelling[playerid] = false;
GivePlayerMoney(playerid, -GasPrice);
TogglePlayerControllable(playerid, 1);
format(string, sizeof(string), "Your vehicle is refuel! You paid $%d!", GasPrice);
SendClientMessage(playerid, COLOR_YELLOW, string);
format(string, sizeof(string), "%d liters", Fuela);
SendClientMessage(playerid, COLOR_YELLOW, string);
GasPrice = 0;
return 1;
}