PDA

View Full Version : How to spawn a player at a saved location?


Vasu99
26/01/2014, 09:51 AM
This part, which will be below, will save the players location, but is there any way to make the player spawn at the saved location? I'm not sure how to make such a script so instead I just made a script where the player keeps spawning at the same place over and over again.


public OnPlayerDisconnect(playerid, reason)
{
/* Reason of quiting */
new
szString[64],
name[MAX_PLAYER_NAME];

GetPlayerName(playerid, name, MAX_PLAYER_NAME);

switch(reason)
{
case 0: format(szString, sizeof szString, "%s left the server. (Timed Out/Crashed)", name);
case 1: format(szString, sizeof szString, "%s left the server. (Quit)", name);
case 2: format(szString, sizeof szString, "%s left the server. (Kicked/Banned)", name);
}
/* Reason of quiting END */

SendClientMessageToAll(0xC4C4C4FF, szString);

new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]);
INI_WriteInt(File,"Sex", PlayerInfo[playerid][pSex]);
INI_WriteInt(File,"Skin", PlayerInfo[playerid][pSkin]);
INI_WriteInt(File,"Location", PlayerInfo[playerid][pLocation]);
INI_Close(File);
return 1;
}


This is what makes the player spawn at the location when joining, I think.


case DIALOG_LOCATION:
{
if(!response) return Kick(playerid);
if(response)
{
if(listitem == 0)
{
PlayerInfo[playerid][pLocation] = 0;
SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], 942.0000,-4630.0000,2.2887,359.7559, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
}
}
}
case DIALOG_LOGIN:
{
if ( !response ) return Kick ( playerid );
if( response )
{
if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], 942.0000,-4630.0000,2.2887,359.7559, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
}
else
{
Kick(playerid);
}
return 1;
}
}
}
return 1;


I'm sorry for posting this same topic a second time, but the last one got too messy due to all my "BUMP"s.

MCZOFT
26/01/2014, 10:07 AM
you need to change your cords of last spawning of that player

add somewhere

saveplayer(playerid)

stock it

define it ,
Good luck

Vanter
26/01/2014, 10:12 AM
okay

public OnPlayerDisconnect(playerid)
{
new Float:x, Float:y, Float:z;
new pname[MAX_PLAYER_NAME];
new string[128];
new file[60];
GetPlayerPos(playerid, x, y, z);
GetPlayerName(playerid,pname,sizeof(pname));
format(file,sizeof(file),"/Users/%s.ini",pname);
new INI:File = INI_Open(file);
INI_WriteFloat(File,"posX", x);
INI_WriteFloat(File,"posY", y);
INI_WriteFloat(File,"posZ", z);
INI_Close(File);
return 1;
}

Vasu99
26/01/2014, 06:33 PM
you need to change your cords of last spawning of that player

add somewhere

saveplayer(playerid)

stock it

define it ,
Good luck

I'm not sure what you mean, I'm sorry.

okay

public OnPlayerDisconnect(playerid)
{
new Float:x, Float:y, Float:z;
new pname[MAX_PLAYER_NAME];
new string[128];
new file[60];
GetPlayerPos(playerid, x, y, z);
GetPlayerName(playerid,pname,sizeof(pname));
format(file,sizeof(file),"/Users/%s.ini",pname);
new INI:File = INI_Open(file);
INI_WriteFloat(File,"posX", x);
INI_WriteFloat(File,"posY", y);
INI_WriteFloat(File,"posZ", z);
INI_Close(File);
return 1;
}

Thanks Vanter for your help, but isn't that and this the same thing..-?


public OnPlayerDisconnect(playerid, reason)
{
/* Reason of quiting */
new
szString[64],
name[MAX_PLAYER_NAME];

GetPlayerName(playerid, name, MAX_PLAYER_NAME);

switch(reason)
{
case 0: format(szString, sizeof szString, "%s left the server. (Timed Out/Crashed)", name);
case 1: format(szString, sizeof szString, "%s left the server. (Quit)", name);
case 2: format(szString, sizeof szString, "%s left the server. (Kicked/Banned)", name);
}
/* Reason of quiting END */

SendClientMessageToAll(0xC4C4C4FF, szString);

new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]);
INI_WriteInt(File,"Sex", PlayerInfo[playerid][pSex]);
INI_WriteInt(File,"Skin", PlayerInfo[playerid][pSkin]);
INI_WriteInt(File,"Location", PlayerInfo[playerid][pLocation]);
INI_Close(File);
return 1;
}


Oh and by the way can you please explain what you did so I kind of learn something from it? Thanks in advance!

Vanter
26/01/2014, 06:54 PM
You're saving normal information, edit what I posted with the axis
new Float:x......
and GetPlayerPos(playerid, x, y, z);

then copy the INI_WriteFloat below your INI_WriteInt
then check the player file, you'll see the last coordinates the player was at

Vasu99
27/01/2014, 04:49 PM
Hmm..- I still don't seem to get it. Where do I add your code? And what do I do with this current one..-?


public OnPlayerDisconnect(playerid, reason)
{
/* Reason of quiting */
new
szString[64],
name[MAX_PLAYER_NAME];

GetPlayerName(playerid, name, MAX_PLAYER_NAME);

switch(reason)
{
case 0: format(szString, sizeof szString, "%s left the server. (Timed Out/Crashed)", name);
case 1: format(szString, sizeof szString, "%s left the server. (Quit)", name);
case 2: format(szString, sizeof szString, "%s left the server. (Kicked/Banned)", name);
}
/* Reason of quiting END */

SendClientMessageToAll(0xC4C4C4FF, szString);

new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]);
INI_WriteInt(File,"Sex", PlayerInfo[playerid][pSex]);
INI_WriteInt(File,"Skin", PlayerInfo[playerid][pSkin]);
INI_WriteInt(File,"Location", PlayerInfo[playerid][pLocation]);
INI_Close(File);
return 1;
}


And I still don't understand how they aren't the same thing.

Vasu99
27/01/2014, 08:33 PM
Bump?

Vasu99
28/01/2014, 07:55 PM
BUMP

Manyula
28/01/2014, 08:14 PM
public OnPlayerDisconnect(playerid, reason)
{
/* Reason of quiting */
new
szString[64],
name[MAX_PLAYER_NAME];

GetPlayerName(playerid, name, MAX_PLAYER_NAME);

switch(reason)
{
case 0: format(szString, sizeof szString, "%s left the server. (Timed Out/Crashed)", name);
case 1: format(szString, sizeof szString, "%s left the server. (Quit)", name);
case 2: format(szString, sizeof szString, "%s left the server. (Kicked/Banned)", name);
}
/* Reason of quiting END */

SendClientMessageToAll(0xC4C4C4FF, szString);

/* Saving Last Player Position*/
new
Float:PosX;
Float:PosY;
Float:PosZ;

GetPlayerPos(playerid, PosX, PosY, PosZ);

new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]);
INI_WriteInt(File,"Sex",PlayerInfo[playerid][pSex]);
INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]);
INI_WriteInt(File,"Location",PlayerInfo[playerid][pLocation]);
INI_WriteFloat(File,"LastPosX",PosX);
INI_WriteFloat(File,"LastPosX",PosY);
INI_WriteFloat(File,"LastPosX",PosZ);
INI_Close(File);
return 1;
}

Don't forget to fetch the data again and set him to the position when he comes back to the server.

Vasu99
30/01/2014, 03:49 PM
Thanks a lot Manyula, I kind of understand that. How do I fetch the data though? REP +

Vasu99
01/02/2014, 09:28 AM
How do I fetcha the data? BUMP?

Vasu99
05/02/2014, 01:49 PM
public OnPlayerDisconnect(playerid, reason)
{
/* Reason of quiting */
new
szString[64],
name[MAX_PLAYER_NAME];

GetPlayerName(playerid, name, MAX_PLAYER_NAME);

switch(reason)
{
case 0: format(szString, sizeof szString, "%s left the server. (Timed Out/Crashed)", name);
case 1: format(szString, sizeof szString, "%s left the server. (Quit)", name);
case 2: format(szString, sizeof szString, "%s left the server. (Kicked/Banned)", name);
}
/* Reason of quiting END */

SendClientMessageToAll(0xC4C4C4FF, szString);

/* Saving Last Player Position*/
new
Float:PosX;
Float:PosY;
Float:PosZ;

GetPlayerPos(playerid, PosX, PosY, PosZ);

new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]);
INI_WriteInt(File,"Sex",PlayerInfo[playerid][pSex]);
INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]);
INI_WriteInt(File,"Location",PlayerInfo[playerid][pLocation]);
INI_WriteFloat(File,"LastPosX",PosX);
INI_WriteFloat(File,"LastPosX",PosY);
INI_WriteFloat(File,"LastPosX",PosZ);
INI_Close(File);
return 1;
}

Don't forget to fetch the data again and set him to the position when he comes back to the server.

Thanks a lot Manyula, I kind of understand that. How do I fetch the data though? REP +

Bump, please help!

CallumDaBest
05/02/2014, 03:55 PM
i would use public OnPlayerDisconnect(playerid)
{
new Float:x, Float:y, Float:z;
new pname[MAX_PLAYER_NAME];
new string[128];
new file[60];
GetPlayerPos(playerid, x, y, z);
GetPlayerName(playerid,pname,sizeof(pname));
format(file,sizeof(file),"/Users/%s.ini",pname);
new INI:File = INI_Open(file);
INI_WriteFloat(File,"posX", x);
INI_WriteFloat(File,"posY", y);
INI_WriteFloat(File,"posZ", z);
INI_Close(File);
return 1;
}
as i always do


----------------------
Working on Big Project

Vasu99
05/02/2014, 06:48 PM
What do you mean? Manyula already told me what to do, if that's what you're telling me, I only need help with "fetching the data". Honestly, I don't even know what "fetcha the data" is and how to do it.

Vasu99
06/02/2014, 04:48 PM
What do you mean? Manyula already told me what to do, if that's what you're telling me, I only need help with "fetching the data". Honestly, I don't even know what "fetcha the data" is and how to do it.

BUMP

Manyula
06/02/2014, 05:22 PM
public OnPlayerDisconnect(playerid, reason)
{
//Saving Last Player Position
enum PlayerInfo
{
//other stuff in your enum above...
Float:pPosX,
Float:pPosY,
Float:pPosZ
}

new PlayerInfo[MAX_PLAYERS][PlayerInfo]; //I suppose you have sth like that

new pPosX, pPosY, pPosZ;
GetPlayerPos(playerid, pPosX, pPosY, pPosZ);

new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]);
INI_WriteInt(File,"Sex",PlayerInfo[playerid][pSex]);
INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]);
INI_WriteInt(File,"Location",PlayerInfo[playerid][pLocation]);
INI_WriteFloat(File,"LastPosX",PlayerInfo[playerid][pPosX]);
INI_WriteFloat(File,"LastPosX",PlayerInfo[playerid][pPosY]);
INI_WriteFloat(File,"LastPosX",PlayerInfo[playerid][pPosZ]);
INI_Close(File);
return 1;
}

Do you have a public to load the user data when a player connects to the server?
Something like this:

forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
//other stuff above...
INI_Float(File,"LastPosX",PlayerInfo[playerid][PosX]);
INI_Float(File,"LastPosX",PlayerInfo[playerid][PosY]);
INI_Float(File,"LastPosX",PlayerInfo[playerid][PosZ]);
return 1;
}

//Under OnPlayerConnect, you check the (User)Path and call the public
INI_ParseFile(Path(playerid), "loadaccount_%s", .bExtra = true, .extra = playerid);

Now, the data is loaded. Insert the position variables (PlayerInfo[playerid][pPosX], and so forth) in SetPlayerPos under OnPlayerSpawn, and you should be done.

NOTE: This is untested.

Vasu99
06/02/2014, 08:40 PM
Now, the data is loaded. Insert the position variables (PlayerInfo[playerid][pPosX], and so forth) in SetPlayerPos under OnPlayerSpawn, and you should be done.



Thanks a lot for your help, but I didn't really understand the last part (the one I just quouted above).

Manyula
06/02/2014, 10:08 PM
When a player connects to your server, you obviously check for his Userpath. If it doesn't exist, you let him register, if it already does exist, you let him log in. As soon as he confirms his password, you give him/her access to the data that is stored in that particular file.
When he spawns, he needs access to this data once more, as the last coordinates are saved in it in variables:
PlayerInfo[playerid][pPosX] contains the X coordinate.
PlayerInfo[playerid][pPosY] contains the Y coordinate.
PlayerInfo[playerid][pPosZ] contains the Z coordinate.
Treat these variables as if they were X, Y and Z in SetPlayerPos(playerid, X, Y, Z).

You could also go a step further and save the FacingAngle of the player. By the examples I've given you, you should be able to do it. ;)

Vasu99
09/02/2014, 08:38 PM
When a player connects to your server, you obviously check for his Userpath. If it doesn't exist, you let him register, if it already does exist, you let him log in. As soon as he confirms his password, you give him/her access to the data that is stored in that particular file.
When he spawns, he needs access to this data once more, as the last coordinates are saved in it in variables:
PlayerInfo[playerid][pPosX] contains the X coordinate.
PlayerInfo[playerid][pPosY] contains the Y coordinate.
PlayerInfo[playerid][pPosZ] contains the Z coordinate.
Treat these variables as if they were X, Y and Z in SetPlayerPos(playerid, X, Y, Z).

You could also go a step further and save the FacingAngle of the player. By the examples I've given you, you should be able to do it. ;)

I'm not sure what you mean, do I have to write the players XYZ cordinates in pawno everytime they log out?

Unfriendly
10/02/2014, 02:40 PM
I'm not sure what you mean, do I have to write the players XYZ cordinates in pawno everytime they log out?

INI is a file saving system.

When the player disconnects, GetPlayerPos stores the x y and z coordinates in your variables. (PlayerInfo[playerid][pPosX],PlayerInfo[playerid][pPosY],PlayerInfo[playerid][pPosZ]

then the INI saves those positions under the right column.

When a player connects, the loaduser function he created sets PlayerInfo[playerid][pPosX],PlayerInfo[playerid][pPosY],PlayerInfo[playerid][pPosZ] as the coordinates saved in the INI.

So all you have to do now after you loaded the user, is go under onplayerspawn and find where you have SetPlayerSkin etc.

Just put SetPlayerPos(playerid, PlayerInfo[playerid][pPosX],PlayerInfo[playerid][pPosY],PlayerInfo[playerid][pPosZ]);
Those variables inside setplayerpos are whatever was saved when he logged out.

I hope you understand, if not, just read the code and realize what each one is doing. Just keep reading it and you'll understand it and be able to help other people do this one day.