Saving, GMX and Disconnect
#1

I just started to script again recently, maybe 3 days ago or so, and I started a new project. I went through testing everything that I had added before moving on and it all has worked out fine, until I added weapon saving. I have spent plenty of time testing and re-doing my work but I can't seem the find out whats wrong. At first I saved it on both Disconnect and GMX, the values of the ammo and the weapon id are both set to zero. But if I take out saving it on GMX, it works perfectly fine. If you need to see any code let me know and I will post it.

(To long^?)
My weapons will not save the weapon id nor ammo on gmx but only on disconnect.
Reply
#2

Please post your code for the GMX.
Reply
#3

Well on disconnect and gmx I make it do the same thing, calls a function for Saving data. I will post it though.
pawn Code:
stock SavePlayerData(playerid)
{
    new File[200],pName[24],Float:armour,weap[13],ammo[13];
    GetPlayerArmour(playerid,armour);
    GetPlayerName(playerid,pName,24);
    format(File,200,"FreeRoam/Users/%s.sav",pName);
    //if(!IsPlayerConnected(playerid)) return false;
    for (new i = 0; i < 13; i++)
    {
        GetPlayerWeaponData(playerid, i, weap[i], ammo[i]);
    }
    if(dini_Exists(File))
    {
        dini_IntSet(File,"Score",GetPlayerScore(playerid));
        dini_IntSet(File,"Money",GetPlayerMoney(playerid));
        dini_IntSet(File,"Skin",PlayerInfo[playerid][skin]);
        dini_IntSet(File,"Spawn",PlayerInfo[playerid][spawn]);
        dini_FloatSet(File,"Armour",armour);
        dini_IntSet(File,"First Spawn",FirstSpawn[playerid]);
        dini_IntSet(File,"Weap0",weap[0]);      dini_IntSet(File,"Ammo0",ammo[0]);
        dini_IntSet(File,"Weap1",weap[1]);      dini_IntSet(File,"Ammo1",ammo[1]);
        dini_IntSet(File,"Weap2",weap[2]);      dini_IntSet(File,"Ammo2",ammo[2]);
        dini_IntSet(File,"Weap3",weap[3]);      dini_IntSet(File,"Ammo3",ammo[3]);
        dini_IntSet(File,"Weap4",weap[4]);      dini_IntSet(File,"Ammo4",ammo[4]);
        dini_IntSet(File,"Weap5",weap[5]);      dini_IntSet(File,"Ammo5",ammo[5]);
        dini_IntSet(File,"Weap6",weap[6]);      dini_IntSet(File,"Ammo6",ammo[6]);
        dini_IntSet(File,"Weap7",weap[7]);      dini_IntSet(File,"Ammo7",ammo[7]);
        dini_IntSet(File,"Weap8",weap[8]);      dini_IntSet(File,"Ammo8",ammo[8]);
        dini_IntSet(File,"Weap9",weap[9]);      dini_IntSet(File,"Ammo9",ammo[9]);
        dini_IntSet(File,"Weap10",weap[10]);    dini_IntSet(File,"Ammo10",ammo[10]);
        dini_IntSet(File,"Weap11",weap[11]);    dini_IntSet(File,"Ammo11",ammo[11]);
        dini_IntSet(File,"Weap12",weap[12]);    dini_IntSet(File,"Ammo12",ammo[12]);
        SendClientMessage(playerid,lightblue,"Player Data Has Been Automatically Saved");
    }
    return 1;
}
Reply
#4

https://sampforum.blast.hk/showthread.php?tid=273088
pawn Code:
new LoggedIn[MAXPLAYERS];

onplayerspawn = LoggedIn[playerid]

CMD:gmx(playerid, params[])
{
    foreach(Player, i)
    {
        SaveStats();
        LoggedIn[i] = 0;
        SendClientMessage(playerid, -1, "SERVER: The server is being restarted.");
    }
    SendRconCommand("gmx");
    return 1;
}


forward SaveStats();

public SaveStats() //this is a shell on how to do it replace playerid with i
{
Foreach(Player, i)
{
if(LoggedIn[i])
{
// https://sampforum.blast.hk/showthread.php?tid=273088// the disconnect stuff, replace playerid with i
new INI:File = INI_Open(UserPath(i));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(i));
    INI_WriteInt(File,"Admin",PlayerInfo[i][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[i][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[i][pDeaths]);
    INI_Close(File);
}
}
return 1;
}
Reply
#5

Quote:
Originally Posted by Glad2BeHere
View Post
https://sampforum.blast.hk/showthread.php?tid=273088
pawn Code:
new LoggedIn[MAXPLAYERS];

onplayerspawn = LoggedIn[playerid]

CMD:gmx(playerid, params[])
{
    foreach(Player, i)
    {
        SaveStats();
        LoggedIn[i] = 0;
        SendClientMessage(playerid, -1, "SERVER: The server is being restarted.");
    }
    SendRconCommand("gmx");
    return 1;
}


forward SaveStats();

public SaveStats() //this is a shell on how to do it replace playerid with i
{
Foreach(Player, i)
{
if(LoggedIn[i])
{
// https://sampforum.blast.hk/showthread.php?tid=273088// the disconnect stuff, replace playerid with i
new INI:File = INI_Open(UserPath(i));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(i));
    INI_WriteInt(File,"Admin",PlayerInfo[i][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[i][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[i][pDeaths]);
    INI_Close(File);
}
return 1;
}
This is of no help to him. He is using DINI and this is INI.
Reply
#6

It seems GMX'ing doesn't call OnPlayerDisconnect. You'll have to make your own gmx function.

example
pawn Code:
stock gmx()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            SavePlayerData(i); // save the player's account
            Kick(i); // and then kick the player
        }
    }
   
    SendRconCommand("gmx");
}
Reply
#7

I had already thought of that but what if the server would crash? Then they wouldn't save.
Reply
#8

my own saves your stats then restarts the server and i know nothing about dini but everything about y ini thats y i gave him a thread if he wanted to change cant u see :!
stop acting childish @z
Reply
#9

Quote:
Originally Posted by willsuckformoney
View Post
I had already thought of that but what if the server would crash? Then they wouldn't save.
I'm not too sure, but I think server crashes call OnGameModeExit(), you'll have to research to make sure. If not, then run a repeating timer that saves all connected players. There's not much you can really do to counter server crashes.
Reply
#10

Actually the problem is, that OnPlayerDisconnect gets called, but it get's called too late.

pawn Code:
new GMX = 0;//On top of script

CMD:gmx(playerid, params[])
{
    //blah blah
    GMX = 1;
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
            {
                    SavePlayerData(i);
        }
    }
}

public OnPlayerDisconnect(playerid)
{
    if(GMX == 0)
    {
        SavePlayerData(playerid);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)