05.04.2011, 12:13
(
Last edited by sciman001; 05/04/2011 at 12:36 PM.
Reason: update!
)
Ok, i made this admin script in about an hour. CODE:
BUGS:
Doesnt save cash, score, killls, deaths, or logged. When i edit and compile the code and then reload the fs via rcon, and then i do /login and it tells me to register. When i try to register, it tells me i'm lready registered. So i have to delete my user file and re-register. Can someone please help me fix these bugs plz? THX!
pawn Code:
#include <a_samp>
#include <dini>
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
#define GREY 0xAFAFAFAA
#define COLOR_RED 0xFF0000FF
#define GREEN 0x33AA33AA
#define YELLOW 0xFFFF00AA
#define WHITE 0xFFFFFFAA
#define LIGHTBLUE 0x33CCFFAA
#define ORANGE 0xFF9900AA
new muted[MAX_PLAYERS];
enum gPInfo
{
Logged,
Regged,
Level,
Deaths,
Kills,
Cash,
Score
};
new PInfo[MAX_PLAYERS][gPInfo];
public OnFilterScriptExit()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(PInfo[i][Regged] == 1)
{
if(PInfo[i][Logged] == 1)
{
new n[MAX_PLAYER_NAME], file[256];
GetPlayerName(i,n,sizeof(n));
format(file,sizeof(file),"MAdmin/Users/%s.txt",n);
PInfo[i][Logged] = 0;
PInfo[i][Cash] = GetPlayerMoney(i);
PInfo[i][Score] = GetPlayerScore(i);
if(dini_Exists(file))
{
dini_IntSet(file,"Regged",1);
dini_IntSet(file,"Logged",PInfo[i][Logged]);
dini_IntSet(file,"Lelel",PInfo[i][Level]);
dini_IntSet(file,"Deaths",PInfo[i][Deaths]);
dini_IntSet(file,"Kills",PInfo[i][Kills]);
dini_IntSet(file,"Cash",PInfo[i][Cash]);
dini_IntSet(file,"Score",PInfo[i][Cash]);
return 1;
}
}
}
}
return 1;
}
public OnPlayerConnect(playerid)
{
PInfo[playerid][Logged] = 0;
PInfo[playerid][Regged] = 0;
PInfo[playerid][Level] = 0;
PInfo[playerid][Deaths] = 0;
PInfo[playerid][Kills] = 0;
PInfo[playerid][Cash] = 0;
PInfo[playerid][Score] = 0;
new n[MAX_PLAYER_NAME], file[256];
GetPlayerName(playerid,n,sizeof(n));
format(file,sizeof(file),"MAdmin/Users/%s.ini",n);
if(dini_Exists(file))
{
SendClientMessage(playerid,LIGHTBLUE,"You are registered, Please /login!");
PInfo[playerid][Regged] = 1;
PInfo[playerid][Logged] = 0;
return 1;
}
else if(!dini_Exists(file))
{
SendClientMessage(playerid,LIGHTBLUE,"You are not registered, Please /register!");
PInfo[playerid][Regged] = 0;
PInfo[playerid][Logged] = 0;
return 1;
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new n[MAX_PLAYER_NAME], file[256];
GetPlayerName(playerid,n,sizeof(n));
format(file,sizeof(file),"MAdmin/Users/%s.txt",n);
PInfo[playerid][Logged] = 0;
PInfo[playerid][Cash] = GetPlayerMoney(playerid);
PInfo[playerid][Score] = GetPlayerScore(playerid);
if(dini_Exists(file))
{
dini_IntSet(file,"Regged",1);
dini_IntSet(file,"Logged",PInfo[playerid][Logged]);
dini_IntSet(file,"Lelel",PInfo[playerid][Level]);
dini_IntSet(file,"Deaths",PInfo[playerid][Deaths]);
dini_IntSet(file,"Kills",PInfo[playerid][Kills]);
dini_IntSet(file,"Cash",PInfo[playerid][Cash]);
dini_IntSet(file,"Score",PInfo[playerid][Cash]);
return 1;
}
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[256], idx;
cmd = strtok(cmdtext, idx);
dcmd(register,8,cmdtext);
dcmd(login,5,cmdtext);
dcmd(kick,4,cmdtext);
dcmd(ban,3,cmdtext);
dcmd(get,3,cmdtext);
dcmd(say,3,cmdtext);
dcmd(nuke,4,cmdtext);
dcmd(mute,4,cmdtext);
dcmd(unmute,6,cmdtext);
dcmd(logout,6,cmdtext);
return 0;
}
public OnPlayerText(playerid, text[])
{
if(muted[playerid] == 1)
{
SendClientMessage(playerid, COLOR_RED, "You cannot talk while muted!");
return 0;
}
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
PInfo[playerid][Deaths] ++;
PInfo[killerid][Kills] ++;
return 1;
}
dcmd_register(playerid,params[])
{
new file[256],n[MAX_PLAYER_NAME];
GetPlayerName(playerid,n,MAX_PLAYER_NAME);
format(file,sizeof(file),"MAdmin/Users/%s.ini",n);
if(dini_Exists(file)) return SendClientMessage(playerid,YELLOW,"You are already registered!");
if(PInfo[playerid][Regged] == 1) return SendClientMessage(playerid,LIGHTBLUE,"You are already registered!");
if(PInfo[playerid][Logged] == 1) return SendClientMessage(playerid,ORANGE,"You are already registered, and logged in!");
if(strlen(params))
{
if(!dini_Exists(file))
{
new hour, minute, second;
new day, month, year;
new string[64];
getdate(year, month, day);
gettime(hour, minute, second);
format(string, sizeof(string), "%i:%i:%i - %i:%i:%i", day, month, year, hour, minute, second);
dini_Create(file);
dini_Set(file,"REGISTERED",string);
dini_Set(file,"Password",params);
dini_IntSet(file,"Regged",1);
dini_IntSet(file,"Logged",0);
dini_IntSet(file,"Level",0);
dini_IntSet(file,"Deaths",PInfo[playerid][Deaths]);
dini_IntSet(file,"Kills",PInfo[playerid][Kills]);
dini_IntSet(file,"Cash",PInfo[playerid][Cash]);
dini_IntSet(file,"Score",PInfo[playerid][Cash]);
SendClientMessage(playerid,LIGHTBLUE,"Congratulations, you have just registered, please /login");
PInfo[playerid][Regged] = 1;
return 1;
}
}
else
{
SendClientMessage(playerid,GREY,"USAGE: /register <Password>");
return 1;
}
return 1;
}
dcmd_login(playerid,params[])
{
new file[256],n[MAX_PLAYER_NAME];
GetPlayerName(playerid,n,MAX_PLAYER_NAME);
format(file,sizeof(file),"MAdmin/Users/%s.ini",n);
if(!dini_Exists(file)) return SendClientMessage(playerid,YELLOW,"You are not registered! Please /register");
if(PInfo[playerid][Logged] == 1) return SendClientMessage(playerid,LIGHTBLUE,"You are already logged in!");
if(PInfo[playerid][Regged] == 0) return SendClientMessage(playerid,ORANGE,"You are not registered! Please /register");
if(strlen(params))
{
new pass[256];
pass = dini_Get(file,"Password");
if(dini_Exists(file))
{
if(strcmp(params,pass,false) != 0)
{
SendClientMessage(playerid,YELLOW,"Wrong Password!");
}
else
{
dini_IntSet(file,"Logged",1);
PInfo[playerid][Logged] = 1;
PInfo[playerid][Level] = dini_Int(file,"Level");
PInfo[playerid][Deaths] = dini_Int(file,"Deaths");
PInfo[playerid][Kills] = dini_Int(file,"Kills");
PInfo[playerid][Cash] = dini_Int(file,"Cash");
PInfo[playerid][Score] = dini_Int(file,"Score");
GivePlayerMoney(playerid, PInfo[playerid][Cash]);
SetPlayerScore(playerid, PInfo[playerid][Score]);
SendClientMessage(playerid,YELLOW,"You have now logged in!");
return 1;
}
}
}
else
{
SendClientMessage(playerid,GREY,"USAGE: /login <Password>");
return 1;
}
return 1;
}
dcmd_kick(playerid,params[])
{
new id,n[MAX_PLAYER_NAME],on[MAX_PLAYER_NAME];
new tmp[256], Index, str[49];
tmp = strtok(params,Index), id = strval(tmp);
GetPlayerName(id,on,sizeof(on));
GetPlayerName(playerid,n,sizeof(n));
if(PInfo[playerid][Level] < 3) return SendClientMessage(playerid,ORANGE,"You need to be level 3 to use this command!");
if(!strlen(params)) return SendClientMessage(playerid,GREY,"USAGE: /kick <ID> ");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,GREY,"Invalid ID");
format(str,sizeof(str),"%s has kicked %s",n,on);
SendClientMessageToAll(LIGHTBLUE,str);
Kick(id);
return 1;
}
dcmd_ban(playerid,params[])
{
new id, n[MAX_PLAYER_NAME],on[MAX_PLAYER_NAME];
new tmp[256], Index, str[49];
tmp = strtok(params,Index), id = strval(tmp);
GetPlayerName(id,on,sizeof(on));
GetPlayerName(playerid,n,sizeof(n));
if(PInfo[playerid][Level] < 4) return SendClientMessage(playerid,ORANGE,"You need to be level 4 to use this command!");
if(!strlen(params)) return SendClientMessage(playerid,GREY,"USAGE: /ban <ID> ");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,GREY,"Invalid ID");
format(str,sizeof(str),"%s has banned %s",n,on);
SendClientMessageToAll(ORANGE,str);
Ban(id);
return 1;
}
dcmd_get(playerid,params[])
{
new id, n[MAX_PLAYER_NAME],on[MAX_PLAYER_NAME];
new tmp[256], Index;
tmp = strtok(params,Index), id = strval(tmp);
GetPlayerName(id,on,sizeof(on));
GetPlayerName(playerid,n,sizeof(n));
if(PInfo[playerid][Level] < 1) return SendClientMessage(playerid,ORANGE,"You need to be level 1 to use this command!");
if(!strlen(params)) return SendClientMessage(playerid,GREY,"USAGE: /get <ID> ");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,GREY,"Invalid ID");
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
SetPlayerPos(id, x, y, z+3);
return 1;
}
dcmd_say(playerid,params[])
{
new tmp[256], Index;
tmp = strtok(params,Index);
if(PInfo[playerid][Level] < 1) return SendClientMessage(playerid,ORANGE,"You need to be level 1 to use this command!");
if(!strlen(params)) return SendClientMessage(playerid,GREY,"USAGE: /get <text> ");
for(new i=0; i < MAX_PLAYERS; i++) //loop
{
GameTextForPlayer(playerid,tmp,3000,4);
}
return 1;
}
dcmd_nuke(playerid,params[])
{
new id, n[MAX_PLAYER_NAME],on[MAX_PLAYER_NAME];
new tmp[256], Index;
tmp = strtok(params,Index), id = strval(tmp);
GetPlayerName(id,on,sizeof(on));
GetPlayerName(playerid,n,sizeof(n));
if(PInfo[playerid][Level] < 3) return SendClientMessage(playerid,ORANGE,"You need to be level 3 to use this command!");
if(!strlen(params)) return SendClientMessage(playerid,GREY,"USAGE: /nuke <ID> ");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,GREY,"Invalid ID");
new Float:x,Float:y,Float:z;
GetPlayerPos(id,x,y,z);
CreateExplosion(x,y,z,7,100);
CreateExplosion(x,y,z,7,100);
CreateExplosion(x,y,z,7,100);
CreateExplosion(x,y,z+10,7,100);
CreateExplosion(x,y+10,z,7,100);
CreateExplosion(x,y-10,z,7,100);
CreateExplosion(x+10,y,z,7,100);
CreateExplosion(x-10,y,z,7,100);
SetPlayerHealth(id, -100);
return 1;
}
dcmd_mute(playerid,params[])
{
new id,n[MAX_PLAYER_NAME],on[MAX_PLAYER_NAME];
new tmp[256], Index, str[49];
tmp = strtok(params,Index), id = strval(tmp);
GetPlayerName(id,on,sizeof(on));
GetPlayerName(playerid,n,sizeof(n));
if(PInfo[playerid][Level] < 2) return SendClientMessage(playerid,ORANGE,"You need to be level 2 to use this command!");
if(!strlen(params)) return SendClientMessage(playerid,GREY,"USAGE: /mute <ID> ");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,GREY,"Invalid ID");
if(muted[id] == 0)
{
format(str,sizeof(str),"%s has muted %s",n,on);
SendClientMessageToAll(LIGHTBLUE,str);
muted[id] = 1;
SendClientMessage(id, COLOR_RED, "You were muted!");
}
else
{
SendClientMessage(playerid, COLOR_RED, "This player is already muted!");
}
return 1;
}
dcmd_unmute(playerid,params[])
{
new id,n[MAX_PLAYER_NAME],on[MAX_PLAYER_NAME];
new tmp[256], Index, str[49];
tmp = strtok(params,Index), id = strval(tmp);
GetPlayerName(id,on,sizeof(on));
GetPlayerName(playerid,n,sizeof(n));
if(PInfo[playerid][Level] < 2) return SendClientMessage(playerid,ORANGE,"You need to be level 2 to use this command!");
if(!strlen(params)) return SendClientMessage(playerid,GREY,"USAGE: /unmute <ID> ");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,GREY,"Invalid ID");
if(muted[id] == 1)
{
format(str,sizeof(str),"%s has unmuted %s",n,on);
SendClientMessageToAll(LIGHTBLUE,str);
muted[id] = 0;
SendClientMessage(id, COLOR_RED, "You were unmuted!");
}
else
{
SendClientMessage(playerid, COLOR_RED, "That player is already unmuted!");
}
return 1;
}
dcmd_logout(playerid,params[])
{
#pragma unused params
if(PInfo[playerid][Logged] == 1)
{
new n[MAX_PLAYER_NAME], file[256];
GetPlayerName(playerid,n,sizeof(n));
format(file,sizeof(file),"MAdmin/Users/%s.txt",n);
if(dini_Exists(file))
{
PInfo[playerid][Logged] = 0;
PInfo[playerid][Cash] = GetPlayerMoney(playerid);
PInfo[playerid][Score] = GetPlayerScore(playerid);
dini_IntSet(file,"Regged",1);
dini_IntSet(file,"Logged",PInfo[playerid][Logged]);
dini_IntSet(file,"Lelel",PInfo[playerid][Level]);
dini_IntSet(file,"Deaths",PInfo[playerid][Deaths]);
dini_IntSet(file,"Kills",PInfo[playerid][Kills]);
dini_IntSet(file,"Cash",PInfo[playerid][Cash]);
dini_IntSet(file,"Score",PInfo[playerid][Cash]);
SendClientMessage(playerid, COLOR_RED, "You are logged out!");
return 1;
}
}
else
{
SendClientMessage(playerid, COLOR_RED, "You need to be logged in to log out!");
}
return 1;
}
Doesnt save cash, score, killls, deaths, or logged. When i edit and compile the code and then reload the fs via rcon, and then i do /login and it tells me to register. When i try to register, it tells me i'm lready registered. So i have to delete my user file and re-register. Can someone please help me fix these bugs plz? THX!