Problem with MAX_FUELSTATIONS and /fuel
#1

Hello, everybody.
I'm having a bit of an issue that I'm having problems figuring out. I have no idea what's causing this, I haven't run into this issue before. It might just be that I'm extremely fatigued having not slept in over 24 hours. Who knows. Either way, I came here as a last resort.

Basically, I have a dynamic fuel station system in my script that I created. An administrator goes to a spot, does /createfuelstation [businessid] [type] [fuelprice] and it'll create an arrow, and a text-draw. All of that works fine and dandy.

I'm having issues, howver, with the actual /fuel command that players use to refill their vehicles. The way it is right now, I get a message saying "You are not near a fuel station!" 50 times, as MAX_FUELSTATIONS is defined as 50. How would I make it only display once?

Also, for some reason, even when I am near a fuel station, it says that I am not. (Not sure if that's caused by the above issue or not.)

Any help is greatly appreciated.
The command:

pawn Код:
CMD:fuel(playerid, params[]) {
    for(new x = 0; x < MAX_FUELSTATIONS; x++) {
        if(IsPlayerInRangeOfPoint(playerid, 5.0, fuelVariables[x][fsPos][0], fuelVariables[x][fsPos][1], fuelVariables[x][fsPos][2])) {
            new vid = GetClosestVehicle(playerid),
                fPercent,
                fPercentTime,
                price;
            if(IsPlayerInRangeOfVehicle(playerid, vid, 5.0)) {
                if(IsPlayerInAnyVehicle(playerid))
                    return SendClientMessage(playerid, COLOR_GREY, "You must be standing outside of your vehicle to fill it.");
                if(sscanf(params, "d", fPercent)) {
                    SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/fuel [percentage]");
                    return 1;
                }
                price = fuelVariables[x][fsFuelPrice] * fPercent;
                if(vehicleVariables[vid][vVehicleFuel] + fPercent > MAX_VEHICLE_FUEL)
                    fPercent = MAX_VEHICLE_FUEL - vehicleVariables[x][vVehicleFuel];
                if(playerVariables[playerid][pMoney] >= price) {
                    format(szMessage, sizeof(szMessage), "* %s sticks the end of the fuel-hose nozzle into the %s and squeezes the trigger.", playerVariables[playerid][pNormalName], VehicleNames[vid - 400]);
                    nearByMessage(playerid, COLOR_PURPLE, szMessage);
                    fPercentTime = fPercent * 200;
                    playerVariables[playerid][pMoney] -= price;
                    SetTimerEx("fuelvehicle", fPercentTime, false, "ddd", playerid, vid, fPercent);
                    TogglePlayerControllable(playerid, 0);
                }
                else {
                    format(szMessage, sizeof(szMessage), "You do not have enough money! ($%d)", price);
                    SendClientMessage(playerid, COLOR_GREY, szMessage);
                }
            }
            else SendClientMessage(playerid, COLOR_GREY, "You are not near your vehicle!");
        }
        else SendClientMessage(playerid, COLOR_GREY, "You are not at a fuel station!");
    }
    return 1;
}
Reply
#2

Hate to do this, but, bump.
Reply
#3

pawn Код:
CMD:fuel(playerid, params[]) {
    new iCount = 0;
    for(new x = 0; x < MAX_FUELSTATIONS; x++) {
        if(IsPlayerInRangeOfPoint(playerid, 5.0, fuelVariables[x][fsPos][0], fuelVariables[x][fsPos][1], fuelVariables[x][fsPos][2])) {
            iCount++;
            new vid = GetClosestVehicle(playerid),
                fPercent,
                fPercentTime,
                price;
            if(IsPlayerInRangeOfVehicle(playerid, vid, 5.0)) {
                if(IsPlayerInAnyVehicle(playerid))
                    return SendClientMessage(playerid, COLOR_GREY, "You must be standing outside of your vehicle to fill it.");
                if(sscanf(params, "d", fPercent)) {
                    SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/fuel [percentage]");
                    return 1;
                }
                price = fuelVariables[x][fsFuelPrice] * fPercent;
                if(vehicleVariables[vid][vVehicleFuel] + fPercent > MAX_VEHICLE_FUEL)
                    fPercent = MAX_VEHICLE_FUEL - vehicleVariables[x][vVehicleFuel];
                if(playerVariables[playerid][pMoney] >= price) {
                    format(szMessage, sizeof(szMessage), "* %s sticks the end of the fuel-hose nozzle into the %s and squeezes the trigger.", playerVariables[playerid][pNormalName], VehicleNames[vid - 400]);
                    nearByMessage(playerid, COLOR_PURPLE, szMessage);
                    fPercentTime = fPercent * 200;
                    playerVariables[playerid][pMoney] -= price;
                    SetTimerEx("fuelvehicle", fPercentTime, false, "ddd", playerid, vid, fPercent);
                    TogglePlayerControllable(playerid, 0);
                }
                else {
                    format(szMessage, sizeof(szMessage), "You do not have enough money! ($%d)", price);
                    SendClientMessage(playerid, COLOR_GREY, szMessage);
                    break;
                }
            }
            else {
                SendClientMessage(playerid, COLOR_GREY, "You are not near your vehicle!");
                break;
            }
        }
    }
    if(iCount == 0) {
        SendClientMessage(playerid, COLOR_GREY, "You are not at a fuel station!");
    }
    return 1;
}
Don't send a message in a loop... I also added a break for when the code doesn't need to continue - Not near vehicle, not enough money...
Reply
#4

Wow, I'm dumb. Thanks for the help! I'll rep you when I get home, doesn't work on my phone.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)