12.02.2014, 13:49
Before we start, i assume that you already have any registration & login system, in case you don't feel free to use this awesome tutorial made by Kush. (CLICK ME)
Getting started:
Before we start we need to understand few things about the system,
○ It can be avoided if the player forces crash instead of disconnecting.
○ gmx will not save the player stats.
Lets get started:
First we need to make some variables to save the player position and skin.
Find:
Add in the bottom:
So it would look like this:
REMEMBER: Add the new 5 variables into all your player data loader/saver for example:
REMEMBER: Make sure the X,Y,Z have Float: beforehand, or else it won't load their position correctly.
Next, we going to find your login Dialog/Textdraw/System and add a
SpawnPlayer(playerid);
At the bottom there.
For example:
This will call the OnPlayerSpawn and there we will add the player information.
Next we going to find OnPlayerSpawn and add few lines there:
Usually it will look like this:
We going to add those things into it:
So we gonna dd those to OnPlayerSpawn, but before we do we have to make sure he is NOT a new registrator so we gonna check for it at the beginning.
Next we going to go to OnPlayerDisconnect and set the variables there:
Last thing is going to our Registration system and adding a little thing at the bottom of it:
Hope it helped few players, even though i am not good at writing tutorials if it even helped one person, that makes this whole thread as helpful .
Getting started:
Before we start we need to understand few things about the system,
○ It can be avoided if the player forces crash instead of disconnecting.
○ gmx will not save the player stats.
Lets get started:
First we need to make some variables to save the player position and skin.
Find:
pawn Code:
enum pInfo
{
pawn Code:
Skin,
Float:Xpos,
Float:Ypos,
Float:Zpos,
NewReg,
pawn Code:
enum pInfo
{
Pass,
Money,
Admin,
Deaths,
Skin, // Saving the player skin into his INI file.
Float:Xpos, // Saving the player X position into his INI file.
Float:Ypos, // Saving the player Y position into his INI file.
Float:Zpos, // Saving the player Z position into his INI file.
NewReg, // To tell the difference between new registers and people who already played.
}
pawn Code:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Password",PlayerInfo[playerid][Pass]);
INI_Int("Money",PlayerInfo[playerid][Money]);
INI_Int("Admin",PlayerInfo[playerid][Admin]);
INI_Int("Deaths",PlayerInfo[playerid][Deaths]);
INI_Int("Skin",PlayerInfo[playerid][Skin]);
INI_Float("Xpos",PlayerInfo[playerid][Xpos]); // Make sure they are Float here.
INI_Float("Ypos",PlayerInfo[playerid][Ypos]); // Make sure they are Float here.
INI_Float("ZXpos",PlayerInfo[playerid][Zpos]); // Make sure they are Float here.
INI_Int("NewReg",PlayerInfo[playerid][NewReg]);
return 1;
}
// My registration system YOU might have a different one.
case DIALOG_REGISTER:
{
if (!response) return Kick(playerid);
if(response)
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Password",udb_hash(inputtext));
INI_WriteInt(File,"Money",0);
INI_WriteInt(File,"Admin",0);
INI_WriteInt(File,"Deaths",0);
INI_WriteInt(File,"Skin",0);
INI_WriteInt(File,"Xpos",0); // It doesn't matter they are Int here because we change them to Float later.
INI_WriteInt(File,"Ypos",0);// It doesn't matter they are Int here because we change them to Float later.
INI_WriteInt(File,"Zpos",0);// It doesn't matter they are Int here because we change them to Float later.
INI_WriteInt(File,"NewReg",0);
INI_Close(File);
SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
}
}
Next, we going to find your login Dialog/Textdraw/System and add a
SpawnPlayer(playerid);
At the bottom there.
For example:
pawn Code:
case DIALOG_LOGIN:
{
if ( !response ) return Kick ( playerid );
if( response )
{
if(udb_hash(inputtext) == PlayerInfo[playerid][Pass])
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);
SpawnPlayer(playerid); // We added this at the bottom.
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
}
return 1;
}
}
Next we going to find OnPlayerSpawn and add few lines there:
Usually it will look like this:
pawn Code:
public OnPlayerSpawn(playerid)
{
return 1;
}
pawn Code:
SetPlayerSkin(playerid, ); // This sets the player skin to his skin.
SetPlayerPos(playerid, ); // This will set the player position.
pawn Code:
public OnPlayerSpawn(playerid)
{
if(PlayerInfo[playerid][NewReg] == 0) // Checking if the player is a new registrator.
{
SetPlayerSkin(playerid, PlayerInfo[playerid][Skin]); // Sets the player skin.
SetPlayerPos(playerid, PlayerInfo[playerid][Xpos], PlayerInfo[playerid][Ypos], PlayerInfo[playerid][Zpos]+0.3); // Sets the player position with extra 0.3 of Z position to make him not fall off the map when he spawns.
}
return 1;
}
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
new Float:Xlog, Float:Ylog, Float:Zlog;
GetPlayerPos(playerid, Xlog, Ylog, Zlog); // Getting the player position on disconnect.
PlayerInfo[playerid][Xpos] = Xlog;
PlayerInfo[playerid][Ypos] = Ylog;
PlayerInfo[playerid][Zpos] = Zlog;
new playerskin = GetPlayerSkin(playerid); // getting the player skin on disconnect.
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Money",GetPlayerMoney(playerid));
INI_WriteInt(File,"Admin",PlayerInfo[playerid][Admin]);
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][Deaths]);
INI_WriteInt(File,"Skin",playerskin); // his skin.
INI_WriteFloat(File,"Xpos",PlayerInfo[playerid][Xpos]); // Making sure we save it as a FLOAT
INI_WriteFloat(File,"Ypos",PlayerInfo[playerid][Ypos]); // Making sure we save it as a FLOAT
INI_WriteFloat(File,"Zpos",PlayerInfo[playerid][Zpos]); // Making sure we save it as a FLOAT
INI_WriteInt(File,"NewReg",0); // When he disconnects he is no longer a new registrator.
INI_Close(File);
return 1;
}
pawn Code:
case DIALOG_REGISTER:
{
if (!response) return Kick(playerid);
if(response)
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Password",udb_hash(inputtext));
INI_WriteInt(File,"Money",0);
INI_WriteInt(File,"Admin",0);
INI_WriteInt(File,"Deaths",0);
INI_WriteInt(File,"Skin",0);
INI_WriteInt(File,"Xpos",0);
INI_WriteInt(File,"Ypos",0);
INI_WriteInt(File,"Zpos",0);
INI_WriteInt(File,"NewReg",0);
INI_Close(File);
SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
PlayerInfo[playerid][NewReg] = 1; // Adding a variable that this is a NEW registrator and he doesn't have an old saved position and skin.
}
}