After adding error message, always returns 0
#1

So I've been trying to make a repair script, but they have to be in range.
All of that works but whenever I put an error usage if the player is not in range, it always returns that.

I'm talking about
pawn Код:
} else {
            SendClientMessage(playerid, -1, "{E74C3C}Error: You are not close to a repairing station! They are marked on the map with a red flag.");
            break;
        }
Full command:
pawn Код:
CMD:repair(playerid, params[])
{
    new vehid = GetPlayerVehicleID(playerid), Float:health, string[128];
    GetVehicleHealth(vehid, Float:health);
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "{E74C3C}Error: You must be in a vehicle in order to repair a vehicle!");
    if(Float:health == 1000) return SendClientMessage(playerid, -1, "{E74C3C}Error: Your vehicle is already fully repaired!");
   
    for (new i = 0; i < sizeof (GasStations); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 75.0, GasStations[i][gX], GasStations[i][gY], GasStations[i][gZ]))
        {
            new Float:price = 1000-Float:health;
           
            format(string, sizeof(string), "{2ECC71}You have successfully repaired your vehicle for {FFFFFF}$%1.0f", floatmul(Float:price, 5));
            SendClientMessage(playerid, -1, string);
           
            PlayerData[playerid][Money] += floatround(floatmul(Float:price, 5), floatround_ceil);
            ResetPlayerMoney(playerid);
            GivePlayerMoney(playerid, PlayerData[playerid][Money]);
           
            RepairVehicle(GetPlayerVehicleID(playerid));
        } else {
            SendClientMessage(playerid, -1, "{E74C3C}Error: You are not close to a repairing station! They are marked on the map with a red flag.");
            break;
        }
    }
    return 1;
}
Reply
#2

Yeah, you should use a variable and set it to true/1 if the gas station is found or else it'll be by default false/0. So after the loop, you can send that message.

PHP код:
CMD:repair(playeridparams[])
{
    if(!
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1"{E74C3C}Error: You must be in a vehicle in order to repair a vehicle!");
    new 
vehid GetPlayerVehicleID(playerid), Float:healthstring[128];
    
GetVehicleHealth(vehidhealth);
    if(
health == 1000) return SendClientMessage(playerid, -1"{E74C3C}Error: Your vehicle is already fully repaired!");
    new 
bool:in_range;
    for (new 
0sizeof (GasStations); i++)
    {
        if(
IsPlayerInRangeOfPoint(playerid75.0GasStations[i][gX], GasStations[i][gY], GasStations[i][gZ]))
        {
            new 
Float:price 1000-health;
            
            
format(stringsizeof(string), "{2ECC71}You have successfully repaired your vehicle for {FFFFFF}$%1.0f"floatmul(Float:price5));
            
SendClientMessage(playerid, -1string);
            
            
PlayerData[playerid][Money] += floatround(floatmul(price5), floatround_ceil);
            
ResetPlayerMoney(playerid);
            
GivePlayerMoney(playeridPlayerData[playerid][Money]);
            
            
RepairVehicle(GetPlayerVehicleID(playerid));
            
in_range true;
            return 
1;
        }
    }
    if (!
in_rangeSendClientMessage(playerid, -1"{E74C3C}Error: You are not close to a repairing station! They are marked on the map with a red flag.");
    return 
1;

Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Yeah, you should use a variable and set it to true/1 if the gas station is found or else it'll be by default false/0. So after the loop, you can send that message.

PHP код:
CMD:repair(playeridparams[])
{
    if(!
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1"{E74C3C}Error: You must be in a vehicle in order to repair a vehicle!");
    new 
vehid GetPlayerVehicleID(playerid), Float:healthstring[128];
    
GetVehicleHealth(vehidhealth);
    if(
health == 1000) return SendClientMessage(playerid, -1"{E74C3C}Error: Your vehicle is already fully repaired!");
    new 
bool:in_range;
    for (new 
0sizeof (GasStations); i++)
    {
        if(
IsPlayerInRangeOfPoint(playerid75.0GasStations[i][gX], GasStations[i][gY], GasStations[i][gZ]))
        {
            new 
Float:price 1000-health;
            
            
format(stringsizeof(string), "{2ECC71}You have successfully repaired your vehicle for {FFFFFF}$%1.0f"floatmul(Float:price5));
            
SendClientMessage(playerid, -1string);
            
            
PlayerData[playerid][Money] += floatround(floatmul(price5), floatround_ceil);
            
ResetPlayerMoney(playerid);
            
GivePlayerMoney(playeridPlayerData[playerid][Money]);
            
            
RepairVehicle(GetPlayerVehicleID(playerid));
            
in_range true;
            return 
1;
        }
    }
    if (!
in_rangeSendClientMessage(playerid, -1"{E74C3C}Error: You are not close to a repairing station! They are marked on the map with a red flag.");
    return 
1;

Thank you very much!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)