Error with my SaveAccount
#1

Hi. Two hours ago I scripted a SaveAccount for my new GameMode RP. I use SII and my SaveAccount is:

pawn Код:
if(INI_Exist(PlayerInfo[playerid][Account]))
    {
        new Float: Pos[4], Float: Vita, Float: Armatura, soldi = GetPlayerMoney(playerid);
        GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
        GetPlayerFacingAngle(playerid, Pos[3]);
        GetPlayerHealth(playerid, Vita);
        GetPlayerArmour(playerid, Armatura);
        INI_Open(PlayerInfo[playerid][Account]);
        INI_WriteInt("Soldi", soldi); // Money
        INI_WriteInt("Skin", PlayerInfo[playerid][Skin]);
        INI_WriteFloat("Vita", Vita); // HP
        INI_WriteFloat("Armatura", Armatura); // Armour
        if(PlayerInfo[playerid][SpawnCase] == 1)
        {
            INI_WriteFloat("SpawnX", Pos[0]);
            INI_WriteFloat("SpawnY", Pos[1]);
            INI_WriteFloat("SpawnZ", Pos[2]);
            INI_WriteFloat("SpawnA", Pos[3]);
            INI_WriteInt("InteriorSpawn", GetPlayerInterior(playerid));
            INI_WriteInt("WorldSpawn", GetPlayerVirtualWorld(playerid));
        }
        INI_WriteInt("Droga", PlayerInfo[playerid][Droga]); // Other...
        INI_WriteInt("Materiali", PlayerInfo[playerid][Materiali]);
        INI_WriteInt("Fazione", PlayerInfo[playerid][Fazione]);
        INI_WriteInt("Rank", PlayerInfo[playerid][Rank]);
        INI_WriteInt("TempoJail", PlayerInfo[playerid][TempoJail]);
        INI_WriteInt("BigliettoTreno", PlayerInfo[playerid][BigliettoTreno]);
        INI_Save();
        INI_Close();
    }
    return 1;
I insert it into callback OnPlayerDisconnect, but when the Server crash Skin, Money and Pos = 0. So in my account's file Skin, Money and Pos are 0. Why?

IMPORTANT: When the Player logout, SaveAccount is good!
Reply
#2

You could try putting a loop under OnGameModeExit. I'm not sure if that gets called or not during a crash tough.
Reply
#3

I use this script:

Under OnGameModeExit:

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
OnPlayerDisconnect(i, 0);
}
And in OnPlayerDisconnect I insert the SaveAccount function. Now the skin is correct, but Health, Armour and Pos are 0.

Only the floats are setting to 0. Why?
Reply
#4

Quote:
Originally Posted by mitosking
Посмотреть сообщение
I use this script:

Under OnGameModeExit:

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
OnPlayerDisconnect(i, 0);
}
And in OnPlayerDisconnect I insert the SaveAccount function. Now the skin is correct, but Health, Armour and Pos are 0.

Only the floats are setting to 0. Why?
Output the data to the console upon disconnect, see what values are being changed/saved.
Reply
#5

I print the Float. They are = 0 ._. (When crash).
Reply
#6

Doesn't surprise me, might not be an issue with your script but that some values go berserk if it crashes.

Use a timer to save accounts at a reasonable time I guess *shrugs*.
Reply
#7

I insert the timer into OnPlayerDisconnect? Or OnGameModeExit?
Reply
#8

He means like an independent timer to save all skins. Position, health, etc. may already be reset by SA-MP in the event of a crash. How about you just make it to where it doesn't crash?
Reply
#9

When it doesn't crash all is ok!

EDIT: But when I write /rcon exit or /rcon gmx the Floats are 0!
Reply
#10

Unless someone has come across this specifically, you'll have to use your own debug code (such as printf statements) to find a way around this, if there is one.

Best suggestion I can give is the SA:MP Wiki, see what kind of call backs are available to you, such as:

OnGameModeExit - https://sampwiki.blast.hk/wiki/OnGameModeExit
OnPlayerDisconnect - https://sampwiki.blast.hk/wiki/OnPlayerDisconnect
OnRconCommand - https://sampwiki.blast.hk/wiki/OnRconCommand

OnPlayerDisconnect (reason) will return 0 on a crash. But I guess you have already tried that and you get your floats as 0.

Other than those, a timer is your only option, all you have to do is:

Create a public function that saves only what your having trouble saving upon crashing (you could save all data this way, but it's probably better to minimize it as much as possible). Let us for examples sake, say that you named this public function "SaveCrashData", to use a timer, probably best to put this in OnGameModeInit or OnFilterScriptInit, whichever is applicable:

pawn Код:
SetTimer("SaveCrashData", 60000, true);
If this was in OnGameModeInit, it would call SaveCrashData every 60 seconds (you have to supply it time in ms) and will loop indefinitely (on GameMode/FilterScript Exit you would call KillTimer to kill it).

The wiki for SetTimer: https://sampwiki.blast.hk/wiki/SetTimer
and for KillTimer: https://sampwiki.blast.hk/wiki/KillTimer

You can also use SetTimerEx, if you want to pass values to it (as many as you want, similarly to using format).

So if you end up using a timer, set an appropriate ms value (whether you want it to save non saveable crash data every 10, 20, 30, 60 seconds etc, in ms of course) and in your function just loop through players and save that float data or any other data you have trouble with .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)