User data doesn't save
#1

Hi,i have problem with saving data system.
I'm using Dini2 by Gammix, but i don't know why it's doesn't save when player disconnect.

PHP код:
//Include
#include <a_samp>
#include <foreach>
#include <dini2>
#include <streamer>
#include <sscanf2>
#include <izcmd>
#include <mSelection>
#include <md5>
#include <timestamptodate>
//Define
#define USER_PATH "/Users/%s.ini"
#define COLOR_GRAD1         0xB4B5B7FF
#define COLOR_GRAD2         0xBFC0C2FF
#define COLOR_GRAD3         0xCBCCCEFF
#define COLOR_GRAD4         0xD8D8D8FF
#define COLOR_GRAD5         0xE3E3E3FF
#define COLOR_GRAD6         0xF0F0F0FF
#define COLOR_FADE1         0xE6E6E6E6
#define COLOR_FADE2         0xC8C8C8C8
#define COLOR_FADE3         0xAAAAAAAA
#define COLOR_FADE4         0x8C8C8C8C
#define COLOR_FADE5         0x6E6E6E6E
#define COLOR_PURPLE         0xC2A2DAAA
#define COLOR_RED             0xAA3333AA
#define COLOR_GREY             0xAFAFAFAA
#define COLOR_GREEN         0x33AA33AA
#define COLOR_BLACK         0x000001FF
#define COLOR_BLUE             0x007BD0FF
#define COLOR_LIGHTORANGE     0xFFA100FF
#define COLOR_FLASH         0xFF000080
#define COLOR_LIGHTRED         0xFF6347AA
#define COLOR_LIGHTBLUE     0x33CCFFAA
#define COLOR_LIGHTGREEN     0x9ACD32AA
#define COLOR_YELLOW         0xFFFF00AA
#define COLOR_LIGHTYELLOW    0xFFFF91FF
#define COLOR_YELLOW2         0xF5DEB3AA
#define COLOR_WHITE         0xFFFFFFAA
#define COLOR_ORANGE         0xFF8000FF
#define COLOR_NEWBIE         0x7DAEFFFF
#define COLOR_GOLD             0xF6C861AA
//Server Side Money (Money Anti-Cheat)
#define GivePlayerCash(%0,%1) SetPVarInt(%0,"Money",GetPlayerCash(%0)+%1),GivePlayerMoney(%0,%1)
#define ResetPlayerCash(%0) SetPVarInt(%0,"Money",0), ResetPlayerMoney(%0)
#define GetPlayerCash(%0) GetPVarInt(%0,"Money")
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define DIALOG_GENDER 3
//Forward
forward UserRegister(playeridpassword[]);
forward UserLogin(playeridpassword[]);
forward UserSave(playerid);
forward UserCheckBanned(playerid);
forward SafeConnect(playerid);
//Variables
new bool:loggedin[MAX_PLAYERS] = false;
//Array
new MaleSkin[59] = { 1,2,4,5,6,7,14,15,20,21,22,23,24,25,26,29,30,44,46,47,48,58,59,60,66,67,72,73,98,101,134,135,136,149,170,183,184,185,186,187,212,213,217,221,222,223,235,236,240,241,242,250,261,262,290,291,299 };
new 
FemaleSkin[39] = { 9,10,12,13,38,39,40,41,54,55,56,69,76,88,989,93,148,150,151,169,190,191,192,193,195,211,214,215,216,218,219,224,225,226,231,232,233,298 };
//Enum
enum pInfo
{
    
pPass[256],
    
pRegister,
    
pCash,
    
pAccount,
    
pLevel,
    
pExp,
    
pSkin,
    
pGender,
    
Float:pHealth,
    
Float:pArmour,
    
Float:pPosX,
    
Float:pPosY,
    
Float:pPosZ,
    
Float:pRot,
    
pInt,
    
pVW,
    
pAdmin,
    
pBan,
    
pBanEnd
}
new 
PlayerInfo[MAX_PLAYERS][pInfo];
//Stock
stock GetPlayerNameEx(playerid)
{
    new 
playername[MAX_PLAYER_NAME];
    
GetPlayerName(playeridplayernamesizeof(playername));
    return 
playername;
}
stock ResetPlayerVariables(playerid)
{
    
loggedin[playerid] = false;
    
PlayerInfo[playerid][pRegister] = 0;
    
PlayerInfo[playerid][pCash] = 0;
    
PlayerInfo[playerid][pAccount] = 0;
    
PlayerInfo[playerid][pLevel] = 0;
    
PlayerInfo[playerid][pExp] = 0;
    
PlayerInfo[playerid][pSkin] = 0;
    
PlayerInfo[playerid][pGender] = 0;
    
PlayerInfo[playerid][pHealth] = 0.0;
    
PlayerInfo[playerid][pArmour] = 0.0;
    
PlayerInfo[playerid][pPosX] = 0.0;
    
PlayerInfo[playerid][pPosY] = 0.0;
    
PlayerInfo[playerid][pPosZ] = 0.0;
    
PlayerInfo[playerid][pRot] = 0.0;
    
PlayerInfo[playerid][pInt] = 0;
    
PlayerInfo[playerid][pVW] = 0;
    
PlayerInfo[playerid][pAdmin] = 0;
    
PlayerInfo[playerid][pBan] = 0;
    
PlayerInfo[playerid][pBanEnd] = 0;
    return 
1;
}
stock SetupPlayerRegister(playerid)
{
    
loggedin[playerid] = true;
    
PlayerInfo[playerid][pPosX] = 1753.8188;
    
PlayerInfo[playerid][pPosY] = -1921.2356;
    
PlayerInfo[playerid][pPosZ] = 13.5722;
    
PlayerInfo[playerid][pRot] = 280.000;
    
PlayerInfo[playerid][pInt] = 0;
    
PlayerInfo[playerid][pVW] = 0;
    
SetPlayerFacingAngle(playerid280.0000);
    
SendClientMessage(playeridCOLOR_GRAD2"Selamat datang di Haikal-Roleplay.");
    
SendClientMessage(playeridCOLOR_GRAD2"Gunakan /commands untuk mengetahui informasi lebih lanjut tentang server.");
    
GivePlayerCash(playerid50000);
    
SetPlayerScore(playerid1);
    
PlayerInfo[playerid][pLevel] = 1;
    
SpawnPlayer(playerid);
    return 
1;
}
main()
{
    print(
"\n----------------------------------");
    print(
" H-RP powered by Haikal Bintang");
    print(
"----------------------------------\n");
}
public 
OnGameModeInit()
{
    
// Don't use these lines if it's a filterscript
    
DisableInteriorEnterExits();
    
SetGameModeText("H-RP v0.1");
    return 
1;
}
public 
OnGameModeExit()
{
    return 
1;
}
public 
OnPlayerRequestClass(playeridclassid)
{
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
    
UserCheckBanned(playerid);
    
ResetPlayerVariables(playerid);
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    
UserSave(playerid);
    return 
1;
}
public 
OnPlayerSpawn(playerid)
{
    if(
PlayerInfo[playerid][pRegister] == 1)
    {
        
SetPlayerSkin(playeridPlayerInfo[playerid][pSkin]);
        
SetPlayerPos(playeridPlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ]);
        
SetPlayerFacingAngle(playeridPlayerInfo[playerid][pRot]);
        
SetPlayerInterior(playeridPlayerInfo[playerid][pInt]);
        
SetPlayerVirtualWorld(playeridPlayerInfo[playerid][pVW]);
        
SetPlayerHealth(playeridPlayerInfo[playerid][pHealth]);
    }
    else
    {
        
PlayerInfo[playerid][pRegister] = 1;
        
SetPlayerSkin(playeridPlayerInfo[playerid][pSkin]);
        
SetPlayerPos(playeridPlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ]);
        
SetPlayerFacingAngle(playeridPlayerInfo[playerid][pRot]);
        
SetPlayerInterior(playeridPlayerInfo[playerid][pInt]);
        
SetPlayerVirtualWorld(playeridPlayerInfo[playerid][pVW]);
    }
    return 
1;
}
public 
OnPlayerDeath(playeridkilleridreason)
{
    return 
1;
}
public 
OnVehicleSpawn(vehicleid)
{
    return 
1;
}
public 
OnVehicleDeath(vehicleidkillerid)
{
    return 
1;
}
public 
OnPlayerText(playeridtext[])
{
    return 
1;
}
public 
OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    return 
1;
}
public 
OnPlayerExitVehicle(playeridvehicleid)
{
    return 
1;
}
public 
OnPlayerStateChange(playeridnewstateoldstate)
{
    return 
1;
}
public 
OnPlayerEnterCheckpoint(playerid)
{
    return 
1;
}
public 
OnPlayerLeaveCheckpoint(playerid)
{
    return 
1;
}
public 
OnPlayerEnterRaceCheckpoint(playerid)
{
    return 
1;
}
public 
OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 
1;
}
public 
OnRconCommand(cmd[])
{
    return 
1;
}
public 
OnPlayerRequestSpawn(playerid)
{
    if(
loggedin[playerid] == false)
    {
        
Kick(playerid);
    }
    return 
1;
}
public 
OnObjectMoved(objectid)
{
    return 
1;
}
public 
OnPlayerObjectMoved(playeridobjectid)
{
    return 
1;
}
public 
OnPlayerPickUpPickup(playeridpickupid)
{
    return 
1;
}
public 
OnVehicleMod(playeridvehicleidcomponentid)
{
    return 
1;
}
public 
OnVehiclePaintjob(playeridvehicleidpaintjobid)
{
    return 
1;
}
public 
OnVehicleRespray(playeridvehicleidcolor1color2)
{
    return 
1;
}
public 
OnPlayerSelectedMenuRow(playeridrow)
{
    return 
1;
}
public 
OnPlayerExitedMenu(playerid)
{
    return 
1;
}
public 
OnPlayerInteriorChange(playeridnewinterioridoldinteriorid)
{
    return 
1;
}
public 
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    return 
1;
}
public 
OnRconLoginAttempt(ip[], password[], success)
{
    return 
1;
}
public 
OnPlayerUpdate(playerid)
{
    return 
1;
}
public 
OnPlayerStreamIn(playeridforplayerid)
{
    return 
1;
}
public 
OnPlayerStreamOut(playeridforplayerid)
{
    return 
1;
}
public 
OnVehicleStreamIn(vehicleidforplayerid)
{
    return 
1;
}
public 
OnVehicleStreamOut(vehicleidforplayerid)
{
    return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == DIALOG_REGISTER)
    {
        if(
response)
        {
            if(
strlen(inputtext))
            {
                new 
hashpassword[64];
                
format(hashpasswordsizeof(hashpassword), "%s"MD5_Hash(inputtext));
                
UserRegister(playeridhashpassword);
            }
            else
            {
                
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_PASSWORD,"Haikal Roleplay - Register","Password tidak boleh kosong!\nMasukan password di bawah ini:","Daftar","Keluar");
            }
        }
        else
        {
            
Kick(playerid);
        }
    }
    if(
dialogid == DIALOG_LOGIN)
    {
        if(
response)
        {
            if(
strlen(inputtext))
            {
                new 
hashpassword[64];
                
format(hashpasswordsizeof(hashpassword), "%s"MD5_Hash(inputtext));
                
UserLogin(playeridhashpassword);
            }
            else
            {
                
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD,"Haikal Roleplay - Login","Password tidak boleh kosong!\nMasukan password di bawah ini:","Masuk","Keluar");
            }
        }
        else
        {
            
Kick(playerid);
        }
    }
    if(
dialogid == DIALOG_GENDER)
    {
        if(
response)
        {
            
PlayerInfo[playerid][pGender] = 1;
            
PlayerInfo[playerid][pSkin] = MaleSkin[random(sizeof(MaleSkin))];
            
SendClientMessage(playeridCOLOR_WHITE"Kamu adalah seorang {2BFF00}Pria{FFFFFF}.");
            
GameTextForPlayer(playerid"~r~Pilih ~w~Skin"50005);
            
SetupPlayerRegister(playerid);
        }
        else
        {
            
PlayerInfo[playerid][pGender] = 2;
            
PlayerInfo[playerid][pSkin] = FemaleSkin[random(sizeof(FemaleSkin))];
            
SendClientMessage(playeridCOLOR_WHITE"Kamu adalah seorang {2BFF00}Wanita{FFFFFF}.");
            
GameTextForPlayer(playerid"~r~Pilih ~w~Skin"50005);
            
SetupPlayerRegister(playerid);
        }
    }
    return 
1;
}
public 
OnPlayerClickPlayer(playeridclickedplayeridsource)
{
    return 
1;
}
//Unofficial Public
public UserRegister(playeridpassword[])
{
    if(
IsPlayerConnected(playerid))
    {
        new 
file[64];
        
format(filesizeof(file), USER_PATHGetPlayerNameEx(playerid));
        if(!
dini_Exists(file))
        {
            
dini_Create(file);
            
format(PlayerInfo[playerid][pPass], 255"%s"password);
            
dini_Set(file"Password"PlayerInfo[playerid][pPass]);
            
dini_IntSet(file"Register"PlayerInfo[playerid][pRegister]);
            
dini_IntSet(file"Cash"PlayerInfo[playerid][pCash]);
            
dini_IntSet(file"Account"PlayerInfo[playerid][pAccount]);
            
dini_IntSet(file"Level"PlayerInfo[playerid][pLevel]);
            
dini_IntSet(file"Exp"PlayerInfo[playerid][pExp]);
            
dini_IntSet(file"Skin"PlayerInfo[playerid][pSkin]);
            
dini_IntSet(file"Gender"PlayerInfo[playerid][pGender]);
            
dini_FloatSet(file"Health"PlayerInfo[playerid][pHealth]);
            
dini_FloatSet(file"Armour"PlayerInfo[playerid][pArmour]);
            
dini_FloatSet(file"PosX"PlayerInfo[playerid][pPosX]);
            
dini_FloatSet(file"PosY"PlayerInfo[playerid][pPosY]);
            
dini_FloatSet(file"PosZ"PlayerInfo[playerid][pPosZ]);
            
dini_FloatSet(file"Rot"PlayerInfo[playerid][pRot]);
            
dini_IntSet(file"Interior"PlayerInfo[playerid][pInt]);
            
dini_IntSet(file"VW"PlayerInfo[playerid][pVW]);
            
dini_IntSet(file"Admin"PlayerInfo[playerid][pAdmin]);
            
dini_IntSet(file"Ban"PlayerInfo[playerid][pBan]);
            
dini_IntSet(file"BanEnd"PlayerInfo[playerid][pBanEnd]);
            
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD,"Haikal Roleplay - Login","Masukan password untuk bergabung ke dalam server:","Masuk","Keluar");
        }
    }
    return 
1;
}
public 
UserLogin(playeridpassword[])
{
    new 
file[64];
    
format(filesizeof(file), USER_PATHGetPlayerNameEx(playerid));
    if(
dini_Exists(file))
    {
        if(
strcmp(dini_Get(file"Password"), passwordfalse) == 0)
        {
            
PlayerInfo[playerid][pRegister] = dini_Int(file"Register");
            
PlayerInfo[playerid][pCash] = dini_Int(file"Cash");
            
PlayerInfo[playerid][pAccount] = dini_Int(file"Acccount");
            
PlayerInfo[playerid][pLevel] = dini_Int(file"Level");
            
PlayerInfo[playerid][pExp] = dini_Int(file"Exp");
            
PlayerInfo[playerid][pSkin] = dini_Int(file"Skin");
            
PlayerInfo[playerid][pGender] = dini_Int(file"Gender");
            
PlayerInfo[playerid][pHealth] = dini_Float(file"Health");
            
PlayerInfo[playerid][pArmour] = dini_Float(file"Armour");
            
PlayerInfo[playerid][pPosX] = dini_Float(file"PosX");
            
PlayerInfo[playerid][pPosY] = dini_Float(file"PosY");
            
PlayerInfo[playerid][pPosZ] = dini_Float(file"PosZ");
            
PlayerInfo[playerid][pRot] = dini_Float(file"Rot");
            
PlayerInfo[playerid][pInt] = dini_Int(file"Interior");
            
PlayerInfo[playerid][pVW] = dini_Int(file"VW");
            
PlayerInfo[playerid][pAdmin] = dini_Int(file"Admin");
            
PlayerInfo[playerid][pBan] = dini_Int(file"Ban");
            
PlayerInfo[playerid][pBanEnd] = dini_Int(file"BanEnd");
            if(
dini_Int(file"Register") == 0)
            {
                
ShowPlayerDialog(playeridDIALOG_GENDERDIALOG_STYLE_MSGBOX"Haikal Roleplay - Gender""Pilih jenis kelamin anda:""Pria""Wanita");
            }
            else
            {
                
loggedin[playerid] = true;
                
GivePlayerCash(playeridPlayerInfo[playerid][pCash]);
                
SetPlayerScore(playeridPlayerInfo[playerid][pLevel]);
                
SetSpawnInfo(playerid0PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ], PlayerInfo[playerid][pRot], -1, -1, -1, -1, -1, -1);
                
SpawnPlayer(playerid);
            }
        }
        else
        {
            
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD,"Republic Kingdom - Login","Masukan password untuk bergabung ke dalam server:","Masuk","Keluar");
        }
    }
    return 
1;
}
public 
UserSave(playerid)
{
    if(
IsPlayerConnected(playerid))
    {
        if(
loggedin[playerid] == true)
        {
            new 
file[64], Float:XFloat:YFloat:ZFloat:RotFloat:HealthFloat:Armour;
            
format(filesizeof(file), USER_PATHGetPlayerNameEx(playerid));
            
GetPlayerPos(playeridXYZ);
            
GetPlayerFacingAngle(playeridRot);
            
GetPlayerHealth(playeridHealth);
            
GetPlayerArmour(playeridArmour);
            
dini_IntSet(file"Register"PlayerInfo[playerid][pRegister]);
            
dini_IntSet(file"Cash"GetPlayerCash(playerid));
            
dini_IntSet(file"Account"PlayerInfo[playerid][pAccount]);
            
dini_IntSet(file"Level"PlayerInfo[playerid][pLevel]);
            
dini_IntSet(file"Exp"PlayerInfo[playerid][pExp]);
            
dini_IntSet(file"Skin"PlayerInfo[playerid][pSkin]);
            
dini_IntSet(file"Gender"PlayerInfo[playerid][pGender]);
            
dini_FloatSet(file"Health"Health);
            
dini_FloatSet(file"Armour"Armour);
            
dini_FloatSet(file"PosX"X);
            
dini_FloatSet(file"PosY"Y);
            
dini_FloatSet(file"PosZ"Z);
            
dini_FloatSet(file"Rot"Rot);
            
dini_IntSet(file"Interior"GetPlayerInterior(playerid));
            
dini_IntSet(file"VW"GetPlayerVirtualWorld(playerid));
            
dini_IntSet(file"Admin"PlayerInfo[playerid][pAdmin]);
            
dini_IntSet(file"Ban"PlayerInfo[playerid][pBan]);
            
dini_IntSet(file"BanEnd"PlayerInfo[playerid][pBanEnd]);
        }
    }
    return 
1;
}
public 
UserCheckBanned(playerid)
{
    new 
string[128], playername[MAX_PLAYER_NAME], file[64], date[6];
    
GetPlayerName(playeridplayernamesizeof(playername));
    
format(filesizeof(file), USER_PATHplayername);
    if(
dini_Exists(file))
    {
        if(
PlayerInfo[playerid][pBan] == 1)
        {
            if(
gettime() > dini_Int(file"BanEnd"))
            {    
                
PlayerInfo[playerid][pBan] = 0;
                
PlayerInfo[playerid][pBanEnd] = 0;
                
SendClientMessage(playeridCOLOR_WHITE"[INFO]: Masa bannedmu telah berakhir, silahkan masukan password untuk login ke dalam server.");
                
SafeConnect(playerid);
            }
            else
            {
                
TimestampToDate(dini_Int(file"BanEnd"), date[0],date[1],date[2],date[3],date[4],date[5],7);
                
format(stringsizeof(string), "[WARNING]: Kamu masih di banned dari server ini. Akunmu akan di unban pada tanggal %02d/%02d/%02d."date[2], date[1], date[0]);
                
SendClientMessage(playeridCOLOR_LIGHTREDstring);
            }
        }
        else
        {
            
SafeConnect(playerid);
        }
    }
    else
    {
        
SafeConnect(playerid);
    }
    return 
1;
}
public 
SafeConnect(playerid)
{
    new 
file[64], playername[MAX_PLAYER_NAME];
    
GetPlayerName(playeridplayernamesizeof(playername));
    
format(filesizeof(file), USER_PATHplayername);
    if(
dini_Exists(file))
    {
        
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD,"Haikal Roleplay - Login","Masukan password untuk bergabung ke dalam server:","Masuk","Keluar");
    }
    else
    {
        
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_PASSWORD,"Haikal Roleplay - Register","Masukan password untuk mendaftar ke dalam server:","Daftar","Keluar");
    }
    return 
1;

Reply


Messages In This Thread
User data doesn't save - by haikalbintang - 15.12.2017, 11:37
Re: User data doesn't save - by xMoBi - 15.12.2017, 11:51
Re: User data doesn't save - by haikalbintang - 15.12.2017, 11:55
Re: User data doesn't save - by jasperschellekens - 15.12.2017, 13:16

Forum Jump:


Users browsing this thread: 1 Guest(s)