SA-MP Forums Archive
[Help] > Prices for fuel stations.. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [Help] > Prices for fuel stations.. (/showthread.php?tid=477958)



[Help] > Prices for fuel stations.. - Jacapo - 27.11.2013

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];



Re: [Help] > Prices for fuel stations.. - Jacapo - 29.11.2013

bump


Re: [Help] > Prices for fuel stations.. - xVIP3Rx - 29.11.2013

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;
}



Re: [Help] > Prices for fuel stations.. - Jacapo - 29.11.2013

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