Save System
#1

If i want to get the player position, when the player disconnect. i Got a float value 0.0000.

Follow my example

Код:
public OnPlayerDisconnect(playerid, reason) {
        GetPlayerHealth(playerid, playerInfo[playerid][pVida]); // i got 0.0000
	playerInfo[playerid][pDinheiro] = GetPlayerMoney(playerid); // it is ok
	GetPlayerPos(playerid, playerInfo[playerid][pPosX], playerInfo[playerid][pPosY], playerInfo[playerid][pPosZ]); // All 0.000
	playerInfo[playerid][pSkin] = GetPlayerSkin(playerid); // 0
	playerInfo[playerid][pInterior] = GetPlayerInterior(playerid); // 0
	
	SaveData(playerid);
	
	return 1;
}
I have a solution, but it is not good.

I can run a timer to do this. Every 1 second.

Код:
setTimer("SaveData".... 1000

public SaveData() {
        for(new i = 0; i < MAX_PLAYERS; i++) {
                if(IsPlayerConnected(i)) {
                        GetPlayerHealth(i, playerInfo[i][pVida]);
	                playerInfo[i][pDinheiro] = GetPlayerMoney(i);
                	GetPlayerPos(i, playerInfo[i][pPosX], playerInfo[i][pPosY], playerInfo[i][pPosZ]);
        	        playerInfo[i][pSkin] = GetPlayerSkin(i);
                	playerInfo[i][pInterior] = GetPlayerInterior(i);
	
                }
        }
	
	return 1;
}
Now, imagine this every second of the life of my server. Oh my Lag.

Anyone have a best solution?
Reply
#2

why do you create a timer? you can just put the savedata thing in the onplayerdissconnect
Reply
#3

Lol, you do realise the timer is constantly calling itself. I'm surprised it isn't actually giving you any errors in your script. Like Cale said, all you need to do is have one save on OnPlayerDisconnect and you're sweet as long as you don't have a lot of server crashes .
Reply
#4

He said when he puts it under OnPlayerDisconnect, GetPlayerPos returns 0.0

/Learn to read.
Reply
#5

Quote:
Originally Posted by JamesC
Посмотреть сообщение
He said when he puts it under OnPlayerDisconnect, GetPlayerPos returns 0.0

/Learn to read.
Make a timer that calls every 5 minutes, then onplayerdisconnect do like this:

pawn Код:
if(x != 0 && y != 0 && z != 0)
{
     // the pos isnt 0.. so you can save.
}
else
{
    // if this gets called the pos is 0.
}
EDIT: didn't see this before now.. but why is SaveData inside SaveData?
Reply
#6

Quote:
Originally Posted by Cameltoe
Посмотреть сообщение
Make a timer that calls every 5 minutes, then onplayerdisconnect do like this:

pawn Код:
if(x != 0 && y != 0 && z != 0)
{
     // the pos isnt 0.. so you can save.
}
else
{
    // if this gets called the pos is 0.
}
EDIT: didn't see this before now.. but why is SaveData inside SaveData?
EDIT: didn't see this before now.. but why is SaveData inside SaveData?
Ops, i delete it now.

JamesC: He said when he puts it under OnPlayerDisconnect, GetPlayerPos returns 0.0
Yes! I got a big 0.00

why do you create a timer? you can just put the savedata thing in the onplayerdissconnect
The JamesC answered.

CamelToe: Make a timer that calls every 5 minutes, then onplayerdisconnect do like this:
if(x != 0 && y != 0 && z != 0){ // the pos isnt 0.. so you can save.}else{ // if this gets called the pos is 0.}


If i do this, i will lose all data information of 5 minutes ago. And this is not good if the player lose money or other controle variable.

---------------------------------------
I will use the timer (SaveData) to savedata and check hack. It is a solution.
Reply
#7

Quote:
Originally Posted by [HiC]TheKiller
Посмотреть сообщение
Lol, you do realise the timer is constantly calling itself. I'm surprised it isn't actually giving you any errors in your script. Like Cale said, all you need to do is have one save on OnPlayerDisconnect and you're sweet as long as you don't have a lot of server crashes .
Oh yeah, i forgot do delete this. But in my server i dont do this ;p
Reply
#8

Well, I just did some tests:

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new Float:pos[4];
    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    GetPlayerHealth(playerid, pos[3]);
    printf("X: %.2f Y: %.2f Z: %.2f Health: %.2f", pos[0], pos[1], pos[2], pos[3]);
    return 1;
}
Printed:

Код:
[16:45:17] X: 406.69 Y: 2531.42 Z: 16.56 Health: 100.00
No problems here, re-check your code is all I can say. Good luck :P
Reply
#9

Quote:
Originally Posted by Hiddos
Посмотреть сообщение
Well, I just did some tests:

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new Float:pos[4];
    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    GetPlayerHealth(playerid, pos[3]);
    printf("X: %.2f Y: %.2f Z: %.2f Health: %.2f", pos[0], pos[1], pos[2], pos[3]);
    return 1;
}
Printed:

Код:
[16:45:17] X: 406.69 Y: 2531.42 Z: 16.56 Health: 100.00
No problems here, re-check your code is all I can say. Good luck :P
I think he's trying to save GMX DC cords thats why the cords are 0. i remember i ran into the very same problem.
Reply
#10

Oh in that case... Well, tested that as well and it does returns 0 indeed. Possible solution is to create a custom GMX command, that first saves ALL the players' files and stats, and after that restart the server. Note that this does require a variable to be set, in order to check if the server was GMX-d or not (Or simply log em out at that moment of the /gmx command)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)