[Help] > Prices for fuel stations..
#1

Hello,
i making fuel stations with randomize price of fuel as you can see.

pawn Код:
#define MAX_FUEL_STATIONS 10
new fStations = 0;
enum FuelStations
{
Float:f_X,
Float:f_Y,
Float:f_Z,
Price
}
new fuel[MAX_FUEL_STATIONS][FuelStations];
pawn Код:
stock AddFuelStation(Float:x, Float:y, Float:z)
{
    fStations++;
    if(fStations > MAX_FUEL_STATIONS) return print("MAX_FUEL_STATIONS > 10 !");
    fuel[fStations][f_X] = x;
    fuel[fStations][f_Y] = y;
    fuel[fStations][f_Z] = z;
    fuel[fStations][Price] = RandomEx(15, 30);
    printf("Fuel station id %i have price %i $", fStations, fuel[fStations][Price]);
    return 1;
}
So for example
Код:
Fuel station id 1 have price 22 $
Код:
Fuel station id 2 have price 25 $
etc..

And my question is: How to make e.g. GetActuallyFuelPrice() - return fuel price where player is(maybe by fStations?).

Edit: I trying something like that, is that correct? >
pawn Код:
stock GetActuallyFuelPrice() return fuel[fStations][Price];
Reply
#2

bump
Reply
#3

This should work
pawn Код:
stock GetActuallyFuelPrice(FuelStation) return fuel[FuelStation][Price];
And to check if the player is near a station and return the price..
pawn Код:
stock GetPlayersNearestFuelStationPrice(playerid)
{
    for(new i=0; i<MAX_FUEL_STATIONS; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 10, fuel[i][f_X], fuel[i][f_Y], fuel[i][f_Z]) // If the player is near any of the stations by 10 units..
        {
            return fuel[FuelStation][Price]; // Return to Price of that station | OR..
            //return i; This to return the station's id, If you want to return the station's id..
        }
    }
    return -1;
}
Reply
#4

Thank you xVIP3Rx for helping me again

It works, but only with this little edit:

pawn Код:
stock GetPlayersNearestFuelStationPrice(playerid)
{
    for(new i=0; i<MAX_FUEL_STATIONS; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 10, fuel[i][f_X], fuel[i][f_Y], fuel[i][f_Z]) // If the player is near any of the stations by 10 units..
        {
            return fuel[i][Price]; // Return to Price of that station | OR..
            //return i; This to return the station's id, If you want to return the station's id..
        }
    }
    return -1;
}
+REP
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)