08.10.2013, 14:12
Hello Everyone I've created an mysql administration system but it doesnt saves the Admin LEVEL
Enums
setadmin command
onplayerdisconnect
SaveStats Function
i tried to makemyself admin via /setadmin and then i disconnected and Joined again but it didnt saved my Admin level
database
Enums
pawn Код:
enum pInfo
{
pScore,
pMoney,
pLevel,
pVIP,
pKMA,
pRank,
pKills,
pDeaths,
pMuted,
pJailed,
pFrozen,
pMutedTimes,
pJailedTimes,
pFrozenTimes,
pLogins,
pCookies,
Float:pPosX,
Float:pPosY,
Float:pPosZ,
Float:pPosA
}
pawn Код:
CMD:setadmin(playerid,params[])
{
new targetid; new l;
if(PlayerInfo[playerid][pLevel] >= 4 || IsPlayerAdmin(playerid))
{
if(sscanf(params,"ui",targetid,l)) return SendClientMessage(playerid,COLOR_RED,"Usage: /setadmin (playerid) (level)");
{
PlayerInfo[targetid][pLevel] = l;
new st[128];
format(st,128,"UPDATE `playerdata` SET level='%d' WHERE user='%s'",l,GetName(targetid));
mysql_query(st);
format(st,128,"SELECT level='%d' FROM `playerdata`",PlayerInfo[playerid][pLevel]);
mysql_query(st);
GameTextForPlayer(playerid,"Promoted to an ~g~admin.",10000,5);
}
}
else return SendClientMessage(targetid,COLOR_ORANGERED,notknown);
return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
//================================================================//
// MySQL part //
//================================================================//
if(Logged[playerid] == 1)
{
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
PlayerInfo[playerid][pPosX] = x;
PlayerInfo[playerid][pPosY] = y;
PlayerInfo[playerid][pPosZ] = z;
PlayerInfo[playerid][pPosA] = a;
new score = GetPlayerScore(playerid);
new money = GetPlayerMoney(playerid);
new query[300], pname[24]; new nquery[300];
GetPlayerName(playerid, pname, 24);
format(query, sizeof(query), "UPDATE `playerdata` SET score='%d', money='%d', level='%d', vip='%d', kma='%d', rank='%d', kills='%d', deaths='%d', muted='%d', jailed='%d', frozen='%d' WHERE user='%s'",
score,
money,
PlayerInfo[playerid][pLevel],
PlayerInfo[playerid][pVIP],
PlayerInfo[playerid][pKMA],
PlayerInfo[playerid][pRank],
PlayerInfo[playerid][pKills],
PlayerInfo[playerid][pDeaths],
PlayerInfo[playerid][pMuted],
PlayerInfo[playerid][pJailed],
PlayerInfo[playerid][pFrozen],
pname);
format(nquery,300,"UPDATE `playerdata` SET mutedtimes='%d', jailedtimes='%d', frozentimes='%d', logins='%d', posx='%f', posy='%f', posz='%f', posa='%f' WHERE user='%s'",PlayerInfo[playerid][pMutedTimes],
PlayerInfo[playerid][pJailedTimes],
PlayerInfo[playerid][pFrozenTimes],
PlayerInfo[playerid][pLogins],
PlayerInfo[playerid][pPosX],
PlayerInfo[playerid][pPosY],
PlayerInfo[playerid][pPosZ],
PlayerInfo[playerid][pPosA],
pname);
mysql_query(query);
mysql_query(nquery);
}
return 1;
}
pawn Код:
public SaveStats(playerid)
{
if(Logged[playerid] == 1)
{
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
PlayerInfo[playerid][pPosX] = x;
PlayerInfo[playerid][pPosY] = y;
PlayerInfo[playerid][pPosZ] = z;
PlayerInfo[playerid][pPosA] = a;
new score = GetPlayerScore(playerid);
new money = GetPlayerMoney(playerid);
new query[300], pname[24]; new nquery[300];
GetPlayerName(playerid, pname, 24);
format(query, sizeof(query), "UPDATE `playerdata` SET score='%d', money='%d', level='%d', vip='%d', kma='%d', rank='%d', kills='%d', deaths='%d', muted='%d', jailed='%d', frozen='%d WHERE user='%s'",
score,
money,
PlayerInfo[playerid][pLevel],
PlayerInfo[playerid][pVIP],
PlayerInfo[playerid][pKMA],
PlayerInfo[playerid][pRank],
PlayerInfo[playerid][pKills],
PlayerInfo[playerid][pDeaths],
PlayerInfo[playerid][pMuted],
PlayerInfo[playerid][pJailed],
PlayerInfo[playerid][pFrozen],
pname);
format(nquery,300,"UPDATE `playerdata` SET mutedtimes='%d', jailedtimes='%d', frozentimes='%d', logins='%d', posx='%f', posy='%f', posz='%f', posa='%f', IP=%d WHERE user='%s'",PlayerInfo[playerid][pMutedTimes],
PlayerInfo[playerid][pJailedTimes],
PlayerInfo[playerid][pFrozenTimes],
PlayerInfo[playerid][pLogins],
PlayerInfo[playerid][pPosX],
PlayerInfo[playerid][pPosY],
PlayerInfo[playerid][pPosZ],
PlayerInfo[playerid][pPosA],
GetIP(playerid),
pname
);
mysql_query(query);
mysql_query(nquery);
}
return 1;
}
database