Spawn player at saved location
#1

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;
Reply
#2

To make player spawn at the location where he logged off you need to make it all save and load. On disconnect you get the player position and save it(store SQL/MYSQL) and when player connects and spawns you make it load the stored cordinates.
Reply
#3

Yeah, but how do I do that?
Reply
#4

I mean, in the script it clearly saves the players location. All I want to do is to make the player spawn at that location. I want to know how to do that.

Thanks in advance.
Reply
#5

Hey! How about stop doing DOUBLE POST? It's very annyoing to many people, and mostly they won't help you if, you are going to act like this. Use edit, if you want to add something to your post.

So, basically if you want to place player on his position before he left, just save his position using:
pawn Код:
INI_WriteFloat
More about that function you can read in y_ini topic created by ******, you can find there everything. And then when player logged on, read data as usual and set his position from the data file and call SpawnPlayer after that.

If you gonna convert my words into a code, you'll have what you wanted. Easier than it looks like.
Reply
#6

Riddick, the thing is, I've already saved his position in INI, but I don't know how to make a command to spawn the player there. Not to sound rude or anything, but I did mention this in the actual topic.
Reply
#7

it still must be a float, as riddick said, Coordinates are floats.
Reply
#8

Read data from file, store loaded data to arrays (x[playerid]) or PVars, depends on you and then set everything in SetSpawnInfo function. After all, call SpawnPlayer(playerid);
Reply
#9

What do you mean by "Coordinates are floats"? I want the player to spawn at the place where left, choosing a specific coordinate would kind of result in the player spawning there everytime he relogs.

And Riddick, I'm kind of a noob scripter, so is there any way you could explain that further? I don't want you give me the whole script, I'm just wondering if you could explain it in a way so I can understand?

Cheers!
Reply
#10

So, when you're saving player's position you probably just save it from current position like this:

pawn Код:
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);

//Save
INI_WriteFloat(..., "PosX", X);
[...]
So, to load your position from file, you must load it to the variable. How do you load other variables, please show me LoadUser_[...] public function, which is called by INI_ParseFile.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)