How to get a number? -
Lajko1 - 24.11.2013
Well I'm wondering how to get a number between X and MAX this is based on my filterscript that I'm scripting

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;
}
EDIT: command is based on this callback
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;
}
And again, thanks in advance ^^
Re: How to get a number? -
Jefff - 24.11.2013
pawn Код:
new Fuel = MAX_FUEL - Carinfo[vehicleid][F];
format(......"(name) has refuel his vehicle with %d liters of fuel",Fuel);
Re: How to get a number? -
nmader - 24.11.2013
Well, personally I believe it would be easier to use a hand-made equation to determine the price. First of all set up a global variable such as "Fuel[MAX_VEHICLES]" and set the fuel when a vehicle spawns and such (to 100 unless you are wanting to make it a saved variable, then set it to the saved variable's number. And in terms of gas prices, use this equation - it
should work:
pawn Код:
new gas, calculation;
new vehicleid = GetPlayerVehicleID(playerid);
gas = Fuel[vehicleid];
new calcuation = 100-fuel*2;
Something similar to that. The 2 stands for how much each gallon/percentage will cost.
Re: How to get a number? -
Lajko1 - 24.11.2013
@Jeff: Tag mismatch at line: "new fuel = MAX....." - it says that I've refilled my car with 212578313627... liters
@nmader: no errors or anything but code is not working :/
Also at first post I've posted I edited it with 1 more code that is based on /refuel command - Jeff's code is also there, thanks for respond but I need some more help ^^
More help ?
Re: How to get a number? -
Lajko1 - 24.11.2013
Anyone? please - I need number between X and MAX so I can use it in string for example: (name) has refueled his vehicle with "number I need" liters of fuel
Re: How to get a number? -
iPrivate - 24.11.2013
You mean something like this:
pawn Код:
stock random(min, max)
{
new randomtext = random(max-min)+min;
return randomtext;
}
And then you could use it:
pawn Код:
CMD:refuel(playerid, params[])
{
new string[126];
format(string, sizeof(string), "You have refueled your vehicle with %d liters of fuel.", random(50,100));
SendClientMessage(playerid, 0xFFFFFFFF, string);
return 1;
}
I think that's what you're asking. Change the command part on your needs, just see the example of using the stock.
Re: How to get a number? -
Lajko1 - 24.11.2013
Thanks for respond but not random number :S Exactly number how much fuel I've refill in my vehicle max fuel is 100 and if I spent 72 fuel than I have 28 fuel left, so if I refill my fuel to 100 this is 72 fuel and I need to put this number in string, but I don't know how to get code for this number :S X number - MAX, I need number so it will tell to player how much fuel he refill in vehicle...
Re: How to get a number? -
Jefff - 24.11.2013
MAX_FUEL is 100 or 100.0 ?
Carinfo[vehicleid][F] is float in enum ?
Re: How to get a number? -
Lajko1 - 24.11.2013
OnFilterScriptInit
pawn Код:
for(new vehicleid; vehicleid < MAX_VEHICLES; vehicleid++)
{
Carinfo[vehicleid][F] = 100;
}
Re: How to get a number? -
Jefff - 24.11.2013
pawn Код:
#define MAX_FUEL 100.0
if(strcmp(cmdtext, "/refuel", true) == 0)
{
new vehicleid;
if(!(vehicleid = GetPlayerVehicleID(playerid))) SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You need to be in vehicle to use this command.");
else if(IsRefuelling[playerid]) SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You are already refueling!");
else if(!IsPlayerInRangeOfGasStations(playerid)) SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You are not near any gas pump.");// credits goes to "Konstantinos" - he helped me to detect coords..
else if(Carinfo[vehicleid][F] >= 99) SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}Your fuel tank is full!");
else if(engine == 1) 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
switch(Carinfo[vehicleid][F])
{
case 0..10: GasPrice = 500;
case 11..20: GasPrice = 450;
case 21..30: GasPrice = 400;
case 31..40: GasPrice = 350;
case 41..50: GasPrice = 300;
case 51..60: GasPrice = 250;
case 61..70: GasPrice = 200;
case 71..80: GasPrice = 150;
case 81..90: GasPrice = 100;
default: GasPrice = 50;
}
if(GetPlayerMoney(playerid) < GasPrice) SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You don't have enough money.");
else{
IsRefuelling[playerid] = true;
SetCameraBehindPlayer(playerid);
TogglePlayerControllable(playerid, 0);
GameTextForPlayer(playerid, "Refuelling...", 1000, 5);
SetTimerEx("RefuelVehicle", 5000, 0, "df", playerid, (MAX_FUEL-Carinfo[vehicleid][F]));
}
}
return 1;
}
public RefuelVehicle(playerid, Float:fuela)
{
new string[128];
Carinfo[vehicleid][F] = 100.0;
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); // or replace %d to %.0f and remove _:
SendClientMessage(playerid, COLOR_YELLOW, string);
GasPrice = 0;
return 1;
}