15.12.2017, 11:37
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.
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(playerid, password[]);
forward UserLogin(playerid, password[]);
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(playerid, playername, sizeof(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(playerid, 280.0000);
SendClientMessage(playerid, COLOR_GRAD2, "Selamat datang di Haikal-Roleplay.");
SendClientMessage(playerid, COLOR_GRAD2, "Gunakan /commands untuk mengetahui informasi lebih lanjut tentang server.");
GivePlayerCash(playerid, 50000);
SetPlayerScore(playerid, 1);
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(playerid, classid)
{
return 1;
}
public OnPlayerConnect(playerid)
{
UserCheckBanned(playerid);
ResetPlayerVariables(playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
UserSave(playerid);
return 1;
}
public OnPlayerSpawn(playerid)
{
if(PlayerInfo[playerid][pRegister] == 1)
{
SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
SetPlayerPos(playerid, PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ]);
SetPlayerFacingAngle(playerid, PlayerInfo[playerid][pRot]);
SetPlayerInterior(playerid, PlayerInfo[playerid][pInt]);
SetPlayerVirtualWorld(playerid, PlayerInfo[playerid][pVW]);
SetPlayerHealth(playerid, PlayerInfo[playerid][pHealth]);
}
else
{
PlayerInfo[playerid][pRegister] = 1;
SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
SetPlayerPos(playerid, PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ]);
SetPlayerFacingAngle(playerid, PlayerInfo[playerid][pRot]);
SetPlayerInterior(playerid, PlayerInfo[playerid][pInt]);
SetPlayerVirtualWorld(playerid, PlayerInfo[playerid][pVW]);
}
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}
public OnPlayerText(playerid, text[])
{
return 1;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
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(playerid, objectid)
{
return 1;
}
public OnPlayerPickUpPickup(playerid, pickupid)
{
return 1;
}
public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}
public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}
public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}
public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}
public OnPlayerExitedMenu(playerid)
{
return 1;
}
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}
public OnRconLoginAttempt(ip[], password[], success)
{
return 1;
}
public OnPlayerUpdate(playerid)
{
return 1;
}
public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}
public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}
public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}
public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_REGISTER)
{
if(response)
{
if(strlen(inputtext))
{
new hashpassword[64];
format(hashpassword, sizeof(hashpassword), "%s", MD5_Hash(inputtext));
UserRegister(playerid, hashpassword);
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_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(hashpassword, sizeof(hashpassword), "%s", MD5_Hash(inputtext));
UserLogin(playerid, hashpassword);
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_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(playerid, COLOR_WHITE, "Kamu adalah seorang {2BFF00}Pria{FFFFFF}.");
GameTextForPlayer(playerid, "~r~Pilih ~w~Skin", 5000, 5);
SetupPlayerRegister(playerid);
}
else
{
PlayerInfo[playerid][pGender] = 2;
PlayerInfo[playerid][pSkin] = FemaleSkin[random(sizeof(FemaleSkin))];
SendClientMessage(playerid, COLOR_WHITE, "Kamu adalah seorang {2BFF00}Wanita{FFFFFF}.");
GameTextForPlayer(playerid, "~r~Pilih ~w~Skin", 5000, 5);
SetupPlayerRegister(playerid);
}
}
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
//Unofficial Public
public UserRegister(playerid, password[])
{
if(IsPlayerConnected(playerid))
{
new file[64];
format(file, sizeof(file), USER_PATH, GetPlayerNameEx(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(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"Haikal Roleplay - Login","Masukan password untuk bergabung ke dalam server:","Masuk","Keluar");
}
}
return 1;
}
public UserLogin(playerid, password[])
{
new file[64];
format(file, sizeof(file), USER_PATH, GetPlayerNameEx(playerid));
if(dini_Exists(file))
{
if(strcmp(dini_Get(file, "Password"), password, false) == 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(playerid, DIALOG_GENDER, DIALOG_STYLE_MSGBOX, "Haikal Roleplay - Gender", "Pilih jenis kelamin anda:", "Pria", "Wanita");
}
else
{
loggedin[playerid] = true;
GivePlayerCash(playerid, PlayerInfo[playerid][pCash]);
SetPlayerScore(playerid, PlayerInfo[playerid][pLevel]);
SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ], PlayerInfo[playerid][pRot], -1, -1, -1, -1, -1, -1);
SpawnPlayer(playerid);
}
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_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:X, Float:Y, Float:Z, Float:Rot, Float:Health, Float:Armour;
format(file, sizeof(file), USER_PATH, GetPlayerNameEx(playerid));
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, Rot);
GetPlayerHealth(playerid, Health);
GetPlayerArmour(playerid, Armour);
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(playerid, playername, sizeof(playername));
format(file, sizeof(file), USER_PATH, playername);
if(dini_Exists(file))
{
if(PlayerInfo[playerid][pBan] == 1)
{
if(gettime() > dini_Int(file, "BanEnd"))
{
PlayerInfo[playerid][pBan] = 0;
PlayerInfo[playerid][pBanEnd] = 0;
SendClientMessage(playerid, COLOR_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(string, sizeof(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(playerid, COLOR_LIGHTRED, string);
}
}
else
{
SafeConnect(playerid);
}
}
else
{
SafeConnect(playerid);
}
return 1;
}
public SafeConnect(playerid)
{
new file[64], playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
format(file, sizeof(file), USER_PATH, playername);
if(dini_Exists(file))
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"Haikal Roleplay - Login","Masukan password untuk bergabung ke dalam server:","Masuk","Keluar");
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,"Haikal Roleplay - Register","Masukan password untuk mendaftar ke dalam server:","Daftar","Keluar");
}
return 1;
}