Need help - DJson
#1

Hey guys. I made a gamemode with a login/register system using DJson.
I know i have been posting threads with this question before, but i never got it working.
My proplem is, i dont know how to save the user data when the server shuts down (Closing the server window).
This is a major problem, because the last thing i want is players losing data.

The question in short:
How do i make sure that all user data get saved when the server shuts down?

Hope you can help me. Thank you.
Reply
#2

then post your system and scripters see it and fix it so u can go to scriptfiles\your-folder-that-saved-inyour-members-data\%s.ini or .txt thats all
Reply
#3

I guess there is bugs when you use gmx command or close the server. Try to use gmxfix include and make it call the OnPlayerDisconnect before OnGameModeExit.
Basically if you save the player data properly in OnPlayerDisconnect it should be fine.

I was using DJson months ago and I find the player data usually disappears and even mixed up. Also it freezes my server for around 10 seconds when the players disconnect at the same time(for example gmx, close the server, etc.). Therefore I changed to another system.
Reply
#4

Create a restart command, RCON GMX's are completely bugged.

Here's mine, feel free to mess around with it, it's obviously not going to work for you at the moment.

pawn Код:
COMMAND:restart(playerid, params[])
{
    new
        File[50],
        string[128];

    if(PVar[playerid][AuthLvl] <= 4) return AuthError(playerid, 5);

    print("[PROCESS: RESTART - STARTING]");
    printf("[-] Saving %d player file(s)", global_ConnectedPlayers);
    for(new i = 0; i < global_ConnectedPlayers; i++)
    {
        if(IsPlayerConnected(i))
        {
            format(File, sizeof(File), PFiles, GetTheirName(i));
            GetPlayerPos(i, PVar[i][LastX], PVar[i][LastY], PVar[i][LastZ]);
            GetPlayerFacingAngle(playerid, PVar[playerid][LastRot]);
            GetPlayerHealth(playerid, PVar[playerid][LastHealth]);
            GetPlayerArmour(playerid, PVar[playerid][LastArmour]);
            PVar[playerid][Interior] = GetPlayerInterior(playerid);
            PVar[playerid][Cash] = GetPlayerMoney(playerid);
            djSetInt        (File, "Interior",  PVar[playerid][Interior]);
            djSetInt        (File, "Kills",     PVar[i][Kills]);
            djSetInt        (File, "Deaths",    PVar[i][Deaths]);
            djSetInt        (File, "Authorization",     PVar[i][AuthLvl]);
            djSetInt        (File, "Cash",     PVar[i][Cash]);
            djSetInt        (File, "BankMoney",     PVar[i][BankMoney]);
            djSetInt        (File, "BankAccount",     PVar[i][BankAccount]);
            djSetInt        (File, "BankSavings",     PVar[i][BankSavings]);
            djSetInt        (File, "BankPIN",     PVar[i][BankPIN]);
            djSetInt        (File, "Skin",      PVar[i][Skin]);
            djSetInt        (File, "Age",       PVar[i][Age]);
            djSetInt        (File, "PhoneNumber", PVar[i][PhoneNumber]);
            djSetInt        (File, "Faction",   PVar[i][Faction]);
            djSetInt        (File, "FactionRank", PVar[i][FRank]);
            djSetInt        (File, "VIPLevel", PVar[i][VIPLevel]);
            djSetInt        (File, "Job", PVar[i][Job]);
            djSetInt        (File, "Materials", PVar[i][Materials]);
            djSetInt        (File, "Drugs", PVar[i][Drugs]);
            djSetInt        (File, "JoinLeaveDisplay", PVar[i][JoinLeaveDisplay]);
            djSetInt        (File, "DeathDisplay", PVar[i][DeathDisplay]);
            djSetFloat      (File, "LastX",     PVar[i][LastX]);
            djSetFloat      (File, "LastY",     PVar[i][LastY]);
            djSetFloat      (File, "LastZ",     PVar[i][LastZ]);
            djSetFloat      (File, "LastRot",   PVar[playerid][LastRot]);
            djSetFloat      (File, "LastArmour", PVar[playerid][LastArmour]);
            djSetFloat      (File, "LastHealth", PVar[playerid][LastHealth]);
            djSetInt        (File, "Player_Record_Kicks", PVar[playerid][PRecord_Kicks]);
            djSetInt        (File, "Player_Record_Bans", PVar[playerid][PRecord_Bans]);
            djSetInt        (File, "Player_Record_Jails", PVar[playerid][PRecord_Jails]);
            djSetInt        (File, "Player_Record_Mutes", PVar[playerid][PRecord_Mutes]);
            djSetInt        (File, "Level", PVar[i][Level]);
            djSetInt        (File, "Experience", PVar[i][Experience]);
            djSetInt        (File, "PlayingHours", PVar[i][PlayingHours]);
            //printf("[save] %s position: %f, %f, %f", GetTheirName(playerid), PVar[playerid][LastX], PVar[playerid][LastY], PVar[playerid][LastZ]);
            printf("[%d] %s has been saved.", i, GetTheirName(i));
            Delete3DTextLabel(NameTag[i]);
        }
    }
    format(string, sizeof(string), "{0FA0D1}Server: {FFFFFF}Successfully saved {0FA0D1}%d {FFFFFF}user file(s).", global_ConnectedPlayers);
    SendClientMessageToAll(-1, string);
    ServerHasJustBeenRestarted = 1;
    print("[PROCESS: RESTART - COMPLETE]");
    GameModeExit();
    return 1;
}
Reply
#5

Thank you for helping. I used dini in my script before, but i changed it to Djson. My gamemode saves and loads the players position, and when im in the server and closing the server window, i just respawn and die, and nothing is saved. I made a function called "SaveUserData(playerid);", and its called in the "OnPlayerDisconnect" callback, but this peoblem occurs. And by the way; it didnt work with dini either.
Reply
#6

Quote:
Originally Posted by leong124
Basically if you save the player data properly in OnPlayerDisconnect it should be fine.
Well, I made a function called "SaveUserData(playerid);" which is called in the "OnPlayerDisconnect" callback.
Here is my function:
pawn Код:
public SaveUserData(playerid)
{
    new name[MAX_PLAYER_NAME], file[128];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), UserFile, name);
    if(gPlayerLogged[playerid] == 1)
    {
        if(fexist(file))
        {
            PlayerInfo[playerid][pActivity] = GetPlayerScore(playerid);
            PlayerInfo[playerid][pVirtualWorld] = GetPlayerVirtualWorld(playerid);
            PlayerInfo[playerid][pInterior] = GetPlayerInterior(playerid);
            GetPlayerWeaponData(playerid, 1, PlayerInfo[playerid][pWeapon1], PlayerInfo[playerid][pAmmo1]);
            GetPlayerWeaponData(playerid, 2, PlayerInfo[playerid][pWeapon2], PlayerInfo[playerid][pAmmo2]);
            GetPlayerWeaponData(playerid, 3, PlayerInfo[playerid][pWeapon3], PlayerInfo[playerid][pAmmo3]);
            GetPlayerWeaponData(playerid, 4, PlayerInfo[playerid][pWeapon4], PlayerInfo[playerid][pAmmo4]);
            GetPlayerWeaponData(playerid, 5, PlayerInfo[playerid][pWeapon5], PlayerInfo[playerid][pAmmo5]);
            GetPlayerWeaponData(playerid, 6, PlayerInfo[playerid][pWeapon6], PlayerInfo[playerid][pAmmo6]);
            GetPlayerWeaponData(playerid, 7, PlayerInfo[playerid][pWeapon7], PlayerInfo[playerid][pAmmo7]);
            GetPlayerWeaponData(playerid, 8, PlayerInfo[playerid][pWeapon8], PlayerInfo[playerid][pAmmo8]);
            GetPlayerWeaponData(playerid, 9, PlayerInfo[playerid][pWeapon9], PlayerInfo[playerid][pAmmo9]);
            GetPlayerWeaponData(playerid, 10, PlayerInfo[playerid][pWeapon10], PlayerInfo[playerid][pAmmo10]);
            GetPlayerWeaponData(playerid, 11, PlayerInfo[playerid][pWeapon11], PlayerInfo[playerid][pAmmo11]);
            GetPlayerWeaponData(playerid, 12, PlayerInfo[playerid][pWeapon12], PlayerInfo[playerid][pAmmo12]);
            djSetInt(file, "Money", PlayerInfo[playerid][pMoney]);
            new Float:Health;
            GetPlayerHealth(playerid, Health);
            djSetFloat(file, "Health", floatround(Health));
            new Float:Armour;
            GetPlayerArmour(playerid, Armour);
            djSetFloat(file, "Armour", floatround(Armour));
            djSetInt(file, "Activity", PlayerInfo[playerid][pActivity]);
            djSetInt(file, "Job", PlayerInfo[playerid][pJob]);
            djSetInt(file, "Duty", PlayerInfo[playerid][pDuty]);
            new Float:x, Float:y, Float:z;
            GetPlayerPos(playerid, x, y, z);
            djSetFloat(file, "PosX", (x));
            djSetFloat(file, "PosY", (y));
            djSetFloat(file, "PosZ", (z));
            djSetInt(file, "VirtualWorld", PlayerInfo[playerid][pVirtualWorld]);
            djSetInt(file, "Interior", PlayerInfo[playerid][pInterior]);
            djSetInt(file, "Weapon1", PlayerInfo[playerid][pWeapon1]);
            djSetInt(file, "Weapon2", PlayerInfo[playerid][pWeapon2]);
            djSetInt(file, "Weapon3", PlayerInfo[playerid][pWeapon3]);
            djSetInt(file, "Weapon4", PlayerInfo[playerid][pWeapon4]);
            djSetInt(file, "Weapon5", PlayerInfo[playerid][pWeapon5]);
            djSetInt(file, "Weapon6", PlayerInfo[playerid][pWeapon6]);
            djSetInt(file, "Weapon7", PlayerInfo[playerid][pWeapon7]);
            djSetInt(file, "Weapon8", PlayerInfo[playerid][pWeapon8]);
            djSetInt(file, "Weapon9", PlayerInfo[playerid][pWeapon9]);
            djSetInt(file, "Weapon10", PlayerInfo[playerid][pWeapon10]);
            djSetInt(file, "Weapon11", PlayerInfo[playerid][pWeapon11]);
            djSetInt(file, "Weapon12", PlayerInfo[playerid][pWeapon12]);
            djSetInt(file, "Ammo1", PlayerInfo[playerid][pAmmo1]);
            djSetInt(file, "Ammo2", PlayerInfo[playerid][pAmmo2]);
            djSetInt(file, "Ammo3", PlayerInfo[playerid][pAmmo3]);
            djSetInt(file, "Ammo4", PlayerInfo[playerid][pAmmo4]);
            djSetInt(file, "Ammo5", PlayerInfo[playerid][pAmmo5]);
            djSetInt(file, "Ammo6", PlayerInfo[playerid][pAmmo6]);
            djSetInt(file, "Ammo7", PlayerInfo[playerid][pAmmo7]);
            djSetInt(file, "Ammo8", PlayerInfo[playerid][pAmmo8]);
            djSetInt(file, "Ammo9", PlayerInfo[playerid][pAmmo9]);
            djSetInt(file, "Ammo10", PlayerInfo[playerid][pAmmo10]);
            djSetInt(file, "Ammo11", PlayerInfo[playerid][pAmmo11]);
            djSetInt(file, "Ammo12", PlayerInfo[playerid][pAmmo12]);
        }
    }
    return 1;
}
Hope you can help me. Thank you.
Reply
#7

Bump (12 hours +)
Reply
#8

Bump (24 hours +)
Reply
#9

Bump (10 days +)
Thread re-opened, haven't got a solution yet.
Reply
#10

pawn Код:
//Try these
public OnGameModeExit()
{
    for(new i = 0; i<MAX_PLAYERS;i++)
    {
        SaveUserData(i);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)