CMD:refuel(playerid, params[])
{
if (IsPlayerInAnyVehicle(playerid))
{
if (isrefuelling[playerid] == 0)
{
for(new h = 0; h < sizeof(BizzInfo); h++)
{
format(file6, sizeof(file6), "realityrp/bizzes/%d.ini", h);
BizzInfo[h][benx] = dini_Float(file6, "benx");
BizzInfo[h][beny] = dini_Float(file6, "beny");
BizzInfo[h][benz] = dini_Float(file6, "benz");
if(IsPlayerInRangeOfPoint(playerid, 15, dini_Float(file6, "benx"), dini_Float(file6, "beny"), dini_Float(file6, "benz")))
{
if(BizzInfo[h][bprods] >= 5)
{
if(GetPlayerMoney(playerid) >= BizzInfo[h][bfee])
{
if(BizzInfo[h][btype] == 7)
{
GivePlayerMinusCash(playerid,BizzInfo[h][bfee]);
SetCameraBehindPlayer(playerid);
TogglePlayerControllable(playerid,0);refuel at the same time
isrefuelling[playerid] = 1; /refuel
TextDrawSetString(td_fuel[playerid],"Refuelling..."); /refuel
SetTimerEx("timer_refuel",4500,false,"i",playerid);
BizzInfo[h][bprods] = BizzInfo[h][bprods] - 5;
BizzInfo[h][bbank] = BizzInfo[h][bbank] + BizzInfo[h][bfee];
BizzInfo[h][customers] = BizzInfo[h][customers] + 1;
}
else return SendClientMessage(playerid, COLOR_GREY, "You are not at a Gass Station!");
}
else return SendClientMessage(playerid, COLOR_GREY, "Not enough money!");
}
else return SendClientMessage(playerid, COLOR_GREY, "Gas station is empty! A petrol trucker is needed to refill!");
}
else return SendClientMessage(playerid, COLOR_GREY, "You are not at a gas station!");
}
return 1;
}
else return SendClientMessage(playerid, COLOR_GREY, "You are already refueling!");
}
else return SendClientMessage(playerid, COLOR_GREY, "You must be in a vehicle to do this!");
}
CMD:refuel(playerid, params[])
{
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You must be in a vehicle to do this!");
if(isrefuelling[playerid]) return SendClientMessage(playerid, COLOR_GREY, "You are already refueling!");
for(new h = 0; h < sizeof(BizzInfo); h++)
{
format(file6, sizeof(file6), "realityrp/bizzes/%d.ini", h);
// Not sure what the following is for, so disabled. See the InRangeOfPoint check
//BizzInfo[h][benx] = dini_Float(file6, "benx");
//BizzInfo[h][beny] = dini_Float(file6, "beny");
//BizzInfo[h][benz] = dini_Float(file6, "benz");
if(!IsPlayerInRangeOfPoint(playerid, 15, BizzInfo[h][benx], BizzInfo[h][beny], BizzInfo[h][benz]) || BizzInfo[h][btype] != 7) continue;
if(BizzInfo[h][bprods] < 5) return SendClientMessage(playerid, COLOR_GREY, "Gas station is empty! A petrol trucker is needed to refill!");
if(GetPlayerMoney(playerid) < BizzInfo[h][bfee]) return SendClientMessage(playerid, COLOR_GREY, "Not enough money!");
GivePlayerMinusCash(playerid, BizzInfo[h][bfee]);
SetCameraBehindPlayer(playerid);
TogglePlayerControllable(playerid, false);
isrefuelling[playerid] = 1;
TextDrawSetString(td_fuel[playerid], "Refuelling...");
SetTimerEx("timer_refuel", 4500, false, "i", playerid);
BizzInfo[h][bprods] -= 5;
BizzInfo[h][bbank] += BizzInfo[h][bfee];
BizzInfo[h][customers]++;
return 1;
}
SendClientMessage(playerid, COLOR_GREY, "You are not at a gas station!");
return 1;
}
if(condition) return stop
// code
rather than
if(condition)
{
// code
}
else
{
//stop
}
SendClientMessage(playerid, COLOR_GREY, "You are not at a gas station!");
for(new h = 0; h < sizeof(BizzInfo); h++)
It just seems strange to have the if() on one line and the statement 50 lines away.
|
I completely agree. I prefer to handle cases that would turn out to logically false first. One hundred nested if statements with 100 lines of code in between don't make the code anymore clear. You might want to read the part about 'no early returns' on the website I linked to in my signature; how to write unmaintainable code.
|