[Tutorial] Saving positions on GMX
#1

Hello fellow PAWNers,

I am here to show you how to save positions on a GMX. I will not be explaining the whole making of a registration system with y_ini, or how to load these coordinates. I will just show you how to save them..

Many experienced people will say that on SendRconCommand("GMX"), OnPlayerDisconnect is called. This is correct, but it is called after you see the opening screen(ocean view). This means your X, Y, and Z coordinates will be set to 0.

You will need y_ini(Credits to ******), zcmd(Credits to Zeex).

First, somewhere on the top you will need to do this.
pawn Код:
new GMX[MAX_PLAYERS]
All right let's get started by creating a stock function that saves your stats.

pawn Код:
stock UpdateStats(playerid)
{
    new Float:PosX, Float:PosY, Float:PosZ; //Making the floats.
    GetPlayerPos(playerid, PosX, PosY, PosZ); //This gets your current position, and saves them into variables.
    new INI:File = INI_Open(UserPath(playerid)); //Opens the file.
    INI_SetTag(File,"data");
    INI_WriteFloat(File,"X",PosX); //This uses saves the X coordinate.
    INI_WriteFloat(File,"Y",PosY); //This uses saves the Y coordinate.
    INI_WriteFloat(File,"Z",PosZ); //This uses saves the Z coordinate.
    INI_WriteInt(File,"VW",GetPlayerVirtualWorld(playerid)); //This is needed for if you disconnect in a interior, so you don't fall from the sky.
    INI_WriteInt(File,"Interior",GetPlayerInterior(playerid)); // Same as above.
    INI_Close(File); //Closes the file.
}
Next we have to create a GMX command.

pawn Код:
cmd(gmx, playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] < 4) return SCM(playerid, GREY, "You are not authorized to use this command"); //Your admin information here.
    SendClientMessageToAll(LIGHTRED, "GMX has been initiated by an admin, it will happen in 30 seconds."); //Sends a message to everyone telling them that a GMX will happen.
    SetTimer("GMXi", 30000, false); //Setting a timer to call this function.
    SetTimer("GMXl", 28000, false); //Setting a timer to call this function.
    return 1;
}
Next we make the functions.

pawn Код:
forward GMXl(); //You need to forward the function.
public GMXl()
{
    for (new i = 0; i != MAX_PLAYERS; ++i)// This creates a loop(Can be replaced with foreach)
    {
            GMX[i] = 1;
            UpdateStats(i);/
    }
}

forward GMXi();
public GMXi()
{
    SendRconCommand("GMX");
}
Okay so now, under OnPlayerDisconnect you are going to have saving stuff, so this is what you do.

pawn Код:
public OnPlayerDisconnect
{
    if(GMX[playerid] == 1)
    {
        GMX[playerid] = 0;
    }
    else
    {
        //Saving code here.
    }
        return 1;
}
Now you should be able to save positions on a GMX.

If you find any bugs, or anything wrong post here or PM.
Need help? Post here or PM me.
Reply
#2

Код:
: error 017: undefined symbol "UserPath"
pawn Код:
new INI:File = INI_Open(UserPath(playerid)); //Opens the file.
Can you explain this better?
Reply
#3

Or you could just do this.

pawn Код:
CMD:gmx(playerid,params[])
{
    for(new i = 0;i<MAX_PLAYERS;i++)
    {
        UpdateStats(i);
    }
    SendRconCommand("gmx");
}
Reply
#4

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
Or you could just do this.

pawn Код:
CMD:gmx(playerid,params[])
{
    for(new i = 0;i<MAX_PLAYERS;i++)
    {
        UpdateStats(i);
    }
    SendRconCommand("gmx");
}
Wrote this in ten secs lawl.
Well, if there is 50 players on the server, I'm not sure it would loop in time. Also, I like to give players 30 seconds to /park their car and stuff.
Reply
#5

Quote:
Originally Posted by Gumica
Посмотреть сообщение
Код:
: error 017: undefined symbol "UserPath"
pawn Код:
new INI:File = INI_Open(UserPath(playerid)); //Opens the file.
Can you explain this better?
I recommend reading Kush's tutorial.

pawn Код:
#define PATH "/Users/%s.ini"
pawn Код:
stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)