Saving the player's position on disconnect?
#1

So, im using this script currently: https://sampforum.blast.hk/showthread.php?tid=279927

I have modified it alot, it saves except the player's position. The default spawn everytime you log in or die(I can fix that)is at the airport. I could remove that but I would fall through the ground at Blueberry, I have tried tutorial's, etc but I can't get the player's position to save:/

If someone could help me out with the code, or anything like that please reply!

Thank you!
Matty

OnPlayerConnect:
Quote:

public OnPlayerConnect(playerid)
{
if(!IsValidName(playerid))
{
SCM(playerid,COLOR_RED,"Please change your name into the following format: First_Last(name).");
Kick(playerid);
}
new string[128];
new plname[MAX_PLAYER_NAME];
GetPlayerName(playerid, plname, sizeof(plname));
PlayerInfo[playerid][pLevel] = 0;
PlayerInfo[playerid][pCash] = 0;
PlayerInfo[playerid][pDriveLic] = 0;
PlayerInfo[playerid][pVip] = 0;
PlayerInfo[playerid][pAdmin] = 0;
PlayerInfo[playerid][pTester] = 0;
PlayerInfo[playerid][pSpawn] = 0;
PlayerInfo[playerid][pSex] = 0;
RefuelTime[playerid] = 0;
TrackCar[playerid] = 0;
PlayerInfo[playerid][pAge] = 0;
PlayerInfo[playerid][pOrigin] = 0;
PlayerInfo[playerid][pModel] = 23;
PlayerInfo[playerid][pLocked] = 0;
PlayerInfo[playerid][pExp] = 0;
PlayerInfo[playerid][pWarns] = 0;
PlayerNeedsHelp[playerid] = 0;
Mobile[playerid] = 255;
PlayerInfo[playerid][pMuted] = 0;
PlayerInfo[playerid][pMuteTime] = 0;
gPlayerTutorialing[playerid] = 0;
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
format(string, sizeof(string), "/Users/%s.ini", plname);

Other stuff maybe needed:
Quote:

enum pInfo
{
pPass,
pLevel,
pSex,
pAge,
pOrigin,
pPlace,
pCash,
pExp,
pAdmin,
pNumber,
pTester,
pWarns,
pSelected,
pMuted,
pMuteTime,
pFirstJoined,
pModel,
pVip,
pSpawn,
pLocked,
pDriveLic
};

new PlayerInfo[MAX_PLAYERS][pInfo];
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Password",PlayerInfo[playerid][pPass]);
INI_Int("Level",PlayerInfo[playerid][pLevel]);
INI_Int("Cash",PlayerInfo[playerid][pCash]);
INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
INI_Int("Age",PlayerInfo[playerid][pAge]);
INI_Int("Origin",PlayerInfo[playerid][pOrigin]);
INI_Int("Sex",PlayerInfo[playerid][pSex]);
INI_Int("Model",PlayerInfo[playerid][pModel]);
INI_Int("DriveLic",PlayerInfo[playerid][pDriveLic]);
INI_Int("Place",PlayerInfo[playerid][pPlace]);
INI_Int("Exp",PlayerInfo[playerid][pExp]);
INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
INI_Int("Number",PlayerInfo[playerid][pNumber]);
INI_Int("Tester",PlayerInfo[playerid][pTester]);
INI_Int("Warns",PlayerInfo[playerid][pWarns]);
INI_Int("Selected",PlayerInfo[playerid][pSelected]);
INI_Int("Muted",PlayerInfo[playerid][pMuted]);
INI_Int("MuteTime",PlayerInfo[playerid][pMuteTime]);
INI_Int("FirstJoined",PlayerInfo[playerid][pFirstJoined]);
INI_Int("Vip",PlayerInfo[playerid][pVip]);
INI_Int("Spawn",PlayerInfo[playerid][pSpawn]);
INI_Int("Locked",PlayerInfo[playerid][pLocked]);
return 1;
}
stock UserPath(playerid)
{
new string[128],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playernam e));
format(string,sizeof(string),PATH,playername);
return string;
}

Reply
#2

You need to create three number Integer variables similar to pAdmin. Those can be pX , pY ,pZ. These all three will be saved separately. Put pX , pY ,pZ to 0 when a player registers.

Add up these variables in LoadUser_data too along with the same format used above.

then OnPlayerSpawn use
pawn Код:
if(PlayerInfo[playerid][pX] != 0 && PlayerInfo[playerid][pY] != 0 && PlayerInfo[playerid][pZ] != 0) return SetPlayerPos(playerid,pX ,pY, pZ);
Reply
#3

Okay, gonna try it out, thanks!

I added it all in although I get this on compiling.

C:\Users\Matty\Desktop\Roleplay\Roleplay\gamemodes \rp.pwn(136 : warning 213: tag mismatch
C:\Users\Matty\Desktop\Roleplay\Roleplay\gamemodes \rp.pwn(136 : warning 213: tag mismatch
C:\Users\Matty\Desktop\Roleplay\Roleplay\gamemodes \rp.pwn(136 : warning 213: tag mismatch

Line 1368:
if(PlayerInfo[playerid][pX] != 0 && PlayerInfo[playerid][pY] != 0 && PlayerInfo[playerid][pZ] != 0) return SetPlayerPos(playerid,pX ,pY, pZ);
Reply
#4

Make the pX,
Код:
Float:pX
do the same for the other coords.
Reply
#5

Quote:
Originally Posted by SomebodyAndMe
Посмотреть сообщение
Make the pX,
Код:
Float:pX
do the same for the other coords.
EXACTLY. You will need to save this as a Float , Load it as Float. That means add it in the enum this way,
pawn Код:
Float:pX,
Then on Load_UserData you will need to load it as a Float with INI_Float function.

In the Use OnPlayerSpawn code i gave you!
Reply
#6

Thank you guys!

Although I have no idea about the INI Float thing, I ******'d it and I couldn't find anything..
Could you give me an idea of how it works or what I should enter in please.

Thank you!
Reply
#7

Some natives from y_ini thread.

This is how we write data when there is a Float variable.
pawn Код:
INI_WriteFloat(ini, "Xpos",PlayerInfo[playerid][pX]); // ini is the filename
This is how we read data when there is a Float Variable (This will be used in your LoadUserData)
pawn Код:
INI_Float("Xpos", PlayerInfo[playerid][pX]);
Reply
#8

Thank you!

So, this is correct?
p
Quote:

ublic LoadUser_data(playerid,name[],value[])
{
INI_Int("Password",PlayerInfo[playerid][pPass]);
INI_Int("Level",PlayerInfo[playerid][pLevel]);
INI_Int("Cash",PlayerInfo[playerid][pCash]);
INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
INI_Int("Age",PlayerInfo[playerid][pAge]);
INI_Int("Origin",PlayerInfo[playerid][pOrigin]);
INI_Int("Sex",PlayerInfo[playerid][pSex]);
INI_Int("Model",PlayerInfo[playerid][pModel]);
INI_Int("DriveLic",PlayerInfo[playerid][pDriveLic]);
INI_Int("Insurance",PlayerInfo[playerid][pInsurance]);
INI_Int("Place",PlayerInfo[playerid][pPlace]);
INI_Int("Exp",PlayerInfo[playerid][pExp]);
INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
INI_Int("Number",PlayerInfo[playerid][pNumber]);
INI_Int("Tester",PlayerInfo[playerid][pTester]);
INI_Int("Warns",PlayerInfo[playerid][pWarns]);
INI_Int("Selected",PlayerInfo[playerid][pSelected]);
INI_Int("Muted",PlayerInfo[playerid][pMuted]);
INI_Int("MuteTime",PlayerInfo[playerid][pMuteTime]);
INI_Int("FirstJoined",PlayerInfo[playerid][pFirstJoined]);
INI_Int("Vip",PlayerInfo[playerid][pVip]);
INI_Int("Spawn",PlayerInfo[playerid][pSpawn]);
INI_Int("Locked",PlayerInfo[playerid][pLocked]);
INI_Int("Insurance",PlayerInfo[playerid][pInsurance]);
INI_Float("Xpos", PlayerInfo[playerid][pX]);
INI_Float("Ypos", PlayerInfo[playerid][pY]);
INI_Float("Zpos", PlayerInfo[playerid][pZ]);
return 1;
}

Also, don't I need something OnPlayerDisconnect to save their last position?

Thanks
Reply
#9

Yes make a function to save user data and use it OnPlayerDisconnect.

As well as when the player registers , keep a check if it saves 'Xpos' 'Ypos' 'Zpos' as 0. and When LoadUserData is called it reads the right data.
Reply
#10

What would the function be?

As all of them are: INI_WriteInt(File, "Level",PlayerInfo[playerid][pLevel]); - something like that with the pNAMEHERE changed, but because it's co-ordinates doesn't it need something different?

Thanks!

If you could help, I am implementing a crime system, anyone(for now) can do /su and the player ID, I have made the pCrimes, etc, made the command but How do I make it so it's like once there did /su IDHERE it will add a crime..

I think it's something like: PlayerInfo[giveplayerid][pCrimes] += 1;; - or something like that?

Thank you so much for all your help!

EDIT: I have made a simple command /sume and it adds the crime to the /stats, etc but when I do the /su ID it doesnt work since it says unknown 'giveplayerid'? any help?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)