Quantcast
Channel: SA-MP Forums - Filterscripts
Viewing all articles
Browse latest Browse all 595

[FilterScript] Dynamic Gas station system.

$
0
0
Just a simple Dynamic Gas Station creation,Just follow the next steps carefully . . .
If you're a new scripter i suggest you ignoring it

Commands:
/creategasstation [Exterior & Complete]
/deletegasstation [ID]

Code:

#define MAX_GSTATION 500 //Use any amount you want instead of '500'
Gstation text labels
Code:

new Text3D:GSTATION[MAX_GSTATION];
Code:

new SpawnedGSTATION;
Scroll down, try finding any 'stock' function and paste this text
Code:

forward SaveGSTATIONs();
stock SaveGSTATIONs()
{
    for(new i = 0; i < MAX_GSTATION; i++)
    {
                SaveGSTATION(i);
    }
        return 1;
}
stock SaveGSTATION(i)
{
    new FileName[128];
    format(FileName, sizeof(FileName), "GSTATIONs/GSTATION_%d.ini", i);
    if(dini_Exists(FileName))
    {
        dini_IntSet(FileName, "PickupID", GSTATIONInfo[i][gstationPickupID]);
        dini_FloatSet(FileName, "X", GSTATIONInfo[i][gstationX]);
        dini_FloatSet(FileName, "Y", GSTATIONInfo[i][gstationY]);
        dini_FloatSet(FileName, "Z", GSTATIONInfo[i][gstationZ]);
                  printf( "[system] Gas Station %d saved.", i);
    }
        return 1;
}


Paste the next text in your 'pInfo' or whatever you're using, just try searching for ' pLevel, ' in top of your page and paste them.
Code:

GSTATIONID,
GSTATIONExterior,



Search for any 'enum' text and paste this:
Code:

enum gstationInfo
{
        gstationPickupID,
        Float:gstationX,
        Float:gstationY,
        Float:gstationZ,
};
new GSTATIONInfo[MAX_GSTATION][gstationInfo];

Also use this stock function to load your Gas Station when hosting the server.
Code:

stock LoadGSTATION()
{
        new FileName[128], string[256];
    for(new i = 0; i < MAX_GSTATION; i++)
    {
        format(FileName, sizeof(FileName), "GSTATIONs/GSTATION_%d.ini", i);
        if(dini_Exists(FileName))
        {
            GSTATIONInfo[i][gstationPickupID] = dini_Int(FileName, "PickupID" );
            GSTATIONInfo[i][gstationX] = dini_Float(FileName, "X" );
            GSTATIONInfo[i][gstationY] = dini_Float(FileName, "Y" );
            GSTATIONInfo[i][gstationZ] = dini_Float(FileName, "Z" );
            GSTATIONInfo[i][gstationPickupID] = CreateDynamicPickup(1239, 23, GSTATIONInfo[i][gstationX], GSTATIONInfo[i][gstationY], GSTATIONInfo[i][gstationZ]);
                        printf( "[system] Gas Station %d spawned.", i);
            SpawnedGSTATION++;
                        format(string, sizeof(string), "{01FCFF}[Gas Station]{F0CC00}\nYou can refill your vehicle here\nGas Station ID: %d\n[/refuel]", i);
                        GSTATION[i] = CreateDynamic3DTextLabel(string, COLOR_DCHAT, GSTATIONInfo[i][gstationX], GSTATIONInfo[i][gstationY], GSTATIONInfo[i][gstationZ]+0.75,10.0,INVALID_PLAYER_ID,INVALID_VEHICLE_ID,0,0,-1,-1, 100.0);
            }
    }
        return 1;
}

THEN ADD THIS in your OnGameModinit to load them
Code:

LoadGSTATION();


Code:

public OnPlayerRegister(playerid, password[])
{
        if(IsPlayerConnected(playerid))
        {
                        new string3[32];
                        new PlayerName3[MAX_PLAYER_NAME];
                        GetPlayerName(playerid, PlayerName3, sizeof(PlayerName3));
                        format(string3, sizeof(string3), "%s.ini", PlayerName3);
                        new File: hFile = fopen(string3, io_write);
                        if(hFile)
                        {
                            new var[32];
                                    format(var, 32, "GSTATIONExterior=%d\n", PlayerInfo[playerid][GSTATIONExterior]);fwrite(hFile, var);
                                    format(var, 32, "GSTATIONID=%d\n",PlayerInfo[playerid][GSTATIONID]);fwrite(hFile, var);
                        }
        }
        return 1;
}



Code:

public OnPlayerSave(playerid)
{
        if(IsPlayerConnected(playerid))
        {
            if(IsPlayerNPC(playerid)) return 1;
                if(gPlayerLogged[playerid] != 0 && gPlayerSpawned[playerid] == 1)
                {
                        new string3[32];
                        new PlayerName3[MAX_PLAYER_NAME];

                        GetPlayerName(playerid, PlayerName3, sizeof(PlayerName3));
                        format(string3, sizeof(string3), "%s.ini", PlayerName3);
                        new File: hFile = fopen(string3, io_write);
                        if(hFile)
                        {
                                new var[64];
format(var, 32, "GSTATIONExterior=%d\n", PlayerInfo[playerid][GSTATIONExterior]);fwrite(hFile, var);
                        }
                }
        }
        return 1;
}


Code:

public OnPlayerLogin(playerid,password[])
{
        new tmp2[256];
    new string2[128];
        format(string2, sizeof(string2), "%s.ini", PlayerName(playerid));
        new File: UserFile = fopen(string2, io_read);
        if ( UserFile )
    {
        new PassData[128];
            new keytmp[256], valtmp[256];
            fread( UserFile , PassData , sizeof( PassData ) );
            keytmp = ini_GetKey( PassData );
            if( strcmp( keytmp , "Key" , true ) == 0 )
                {
                        valtmp = ini_GetValue( PassData );
                        strmid(PlayerInfo[playerid][pKey], valtmp, 0, strlen(valtmp)-1, 255);
                }
                if(strcmp(PlayerInfo[playerid][pKey],password, true ) == 0 )
        {
                    new key[ 256 ] , val[ 256 ];
                        new Data[ 256 ];
                        while ( fread( UserFile , Data , sizeof( Data ) ) )
                        {
                            key = ini_GetKey( Data );
if( strcmp( key , "GSTATIONExterior" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][GSTATIONExterior] = strvalEx( val ); }
if( strcmp( key , "GSTATIONID" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][GSTATIONID] = strvalEx( val ); }
              }
                        fclose(UserFile);
        }
      }
    return 1;
}

then add this
Code:

public OnPlayerCommandText(playerid, cmdtext[])
{
dcmd(creategstation, 14, cmdtext);
dcmd(deletegstation, 14, cmdtext);
}

Code:

public GameModeInitExitFunc()
{
SaveGSTATIONs();
return 1;
}


(Choose any location you like In-Game and use/creategasstation Exterior ) then (/creategasstation complete)
You are able whenever you want to delete it using (/deletegasstation)
Code:

dcmd_creategasstation(playerid, params[])
{
        new Usage[128], string[128];
        if( sscanf( params, "s", Usage))
        {
            if( PlayerInfo[playerid][pAdmin] >= 3)
            {
                        SendClientMessage(playerid, COLOR_WHITE, "USAGE: /creategasstation [name]" );
                        SendClientMessage(playerid, COLOR_GREY, "Available Names: Exterior and Complete" );
                }
        }
        else
        {
            if(PlayerInfo[playerid][pAdmin] >= 3)
            {
                    if(strcmp(Usage, "exterior", true) == 0)
                    {
                                PlayerInfo[playerid][GSTATIONExterior]++;
                            GetPlayerPos( playerid, PlayerInfo[playerid][dExtX], PlayerInfo[playerid][dExtY], PlayerInfo[playerid][dExtZ]);
                            GetPlayerFacingAngle(playerid, PlayerInfo[playerid][dAngle]);
                            format( string, sizeof( string ), "Exterior set! (X: %f, Y: %f, Z: %f, A: %f).", PlayerInfo[playerid][dExtX], PlayerInfo[playerid][dExtY], PlayerInfo[playerid][dExtZ], PlayerInfo[playerid][dAngle]);
                              SendClientMessage( playerid, COLOR_WHITE, string);
                          }
                      if(strcmp(Usage, "complete", true) == 0)
                      {
                              if(PlayerInfo[playerid][GSTATIONExterior] > 0)
                        {
                                        new NewGSTATIONID = SpawnedGSTATION+1;
                                  if(NewGSTATIONID >= MAX_GSTATION)
                                  {
                                    SendClientMessage( playerid, COLOR_WHITE, "Too many Gas Stations are currently spawned!");
                            }
                            format( string, sizeof( string ), "GSTATIONs/GSTATION_%d.ini", NewGSTATIONID);
                            if(dini_Exists(string))
                            {
                                                SpawnedGSTATION++;
                                    format( string, sizeof( string ), "Gas Station- (ID: %d) already exist!", NewGSTATIONID);
                                      SendClientMessage( playerid, COLOR_GREY, string);
                                    SendClientMessage( playerid, COLOR_YELLOW, "Please try again by typing /creategasstation complete" );
                              }
                              else
                              {
                                                GSTATIONInfo[NewGSTATIONID][gstationX] = PlayerInfo[playerid][dExtX];
                                                GSTATIONInfo[NewGSTATIONID][gstationY] = PlayerInfo[playerid][dExtY];
                                                GSTATIONInfo[NewGSTATIONID][gstationZ] = PlayerInfo[playerid][dExtZ];
                                                dini_Create(string);
                                          dini_FloatSet( string, "X", GSTATIONInfo[NewGSTATIONID][gstationX]);
                                    dini_FloatSet( string, "Y", GSTATIONInfo[NewGSTATIONID][gstationY]);
                                    dini_FloatSet( string, "Z", GSTATIONInfo[NewGSTATIONID][gstationZ]);
                                    PlayerInfo[playerid][GSTATIONExterior]--;
                                    SpawnedGSTATION++;
                                    GSTATIONInfo[NewGSTATIONID][gstationPickupID] = CreateDynamicPickup(1239, 23, GSTATIONInfo[NewGSTATIONID][gstationX], GSTATIONInfo[NewGSTATIONID][gstationY], GSTATIONInfo[NewGSTATIONID][gstationZ]);
                                    format(string, sizeof(string), "{01FCFF}[Gas Station]{F0CC00}\nYou can refill your vehicle here\nGas Station ID: %d\n[/refuel]", NewGSTATIONID);
                                                GSTATION[NewGSTATIONID] = CreateDynamic3DTextLabel(string, COLOR_DCHAT, GSTATIONInfo[NewGSTATIONID][gstationX], GSTATIONInfo[N        if(!fexist( string) )
                {
                    SendClientMessage( playerid, COLOR_GREY, "Invalid Gas-Station ID!" );
                    return 1;
                }
                else
                {
                                GSTATIONInfo[id][gstationX] = 0;
                                GSTATIONInfo[id][gstationY] = 0;
                                GSTATIONInfo[id][gstationZ] = 0;
                            DestroyDynamicPickup(GSTATIONInfo[id][gstationPickupID]);
                            DestroyDynamic3DTextLabel(GSTATION[id]);
                                format(string, sizeof(string), "You have deleted the Gas Station (ID: %d).", id);
                                  SendClientMessage( playerid, COLOR_WHITE, string);
                              format(FileName, sizeof(FileName), "GSTATIONs/GSTATION_%d.ini", id);
                        dini_Remove(FileName);
                        SpawnedGSTATION--;
                }
                }
        }
        return 1;
}

Make sure to add 'GSTATIONs' file in your scriptfiles file.

Viewing all articles
Browse latest Browse all 595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>