Two potential problems with admin system -
admantis - 05.01.2011
First Error:
pawn Код:
error 035: argument type mismatch (argument 1)
if (!IsNumeric(money)) return SendClientMessage(playerid,COLOR_GRAY,"AdmCmd: Invalid ammount.");
stock IsNumeric(const string[])
{
new length=strlen(string);
if (length==0) return false;
for (new i = 0; i < length; i++)
{
if (
(string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-'
|| (string[i]=='-' && i!=0) // A '-' but not at first.
|| (string[i]=='+' && i!=0) // A '+' but not at first.
) return false;
}
if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
return true;
}
2nd Error: When I do a admin command it's uspposed to tell only to admins what he did, but it doesn't.
pawn Код:
if(strcmp(cmd, "/money", true) == 0)
{
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_LIGHTRED, "USAGE: /money [id] [money]");
return 1;
}
new playa;
new money;
playa = strval(tmp);
tmp = strtok(cmdtext, idx);
money = strval(tmp);
if (!IsNumeric(money)) return SendClientMessage(playerid,COLOR_GRAY,"AdmCmd: Invalid ammount.");
if (PlayerInfo[playerid][pAdminLevel] == 3)
{
if(IsPlayerConnected(playa))
{
if(playa != INVALID_PLAYER_ID)
{
new string[128], name[28], giveplayer[28];
GetPlayerName(playerid, name, sizeof(name));
GetPlayerName(playa, giveplayer, sizeof(giveplayer));
PlayerInfo[playerid][pMoney] += money;
format(string,sizeof(string), "AdmWarn: Lead Administrator %s has given %d$ to %s.",name, money, giveplayer);
SendAdminMessage(COLOR_LIGHTBLUE,string);
}
}
}
else
{
SendClientMessage(playerid, COLOR_GRAY, "You don't have authorization.");
}
}
return 1;
}
// Tho it gives money properly, no admin message is sent.
stock SendAdminMessage(color,const string[])
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) == 1) if(PlayerInfo[i][pIsGolden] == 1) SendClientMessage(i, color, string);
}
return 1;
}
Thanks ALOT to whoever fixes my probs.
Re: Two potential problems with admin system -
iggy1 - 05.01.2011
Is "money" a string? it must be for isnumeric.
Re: Two potential problems with admin system -
admantis - 05.01.2011
Not very clear with that, but check the command here.
pawn Код:
if(strcmp(cmd, "/money", true) == 0)
{
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_LIGHTRED, "USAGE: /money [id] [money]");
return 1;
}
new playa;
new money; // Money is defined.
playa = strval(tmp);
tmp = strtok(cmdtext, idx);
money = strval(tmp); // Money is assigned to a value
if (!IsNumeric(money)) return SendClientMessage(playerid,COLOR_GRAY,"AdmCmd: Invalid ammount."); // Error line.
if (PlayerInfo[playerid][pAdminLevel] == 3)
{
if(IsPlayerConnected(playa))
{
if(playa != INVALID_PLAYER_ID)
{
new string[128], name[28], giveplayer[28];
GetPlayerName(playerid, name, sizeof(name));
GetPlayerName(playa, giveplayer, sizeof(giveplayer));
PlayerInfo[playerid][pMoney] += money;
format(string,sizeof(string), "AdmWarn: Lead Administrator %s has given %d$ to %s.",name, money, giveplayer);
SendAdminMessage(COLOR_LIGHTBLUE,string);
}
}
}
else
{
SendClientMessage(playerid, COLOR_GRAY, "You don't have authorization.");
}
}
return 1;
}
Re: Two potential problems with admin system -
veyron - 05.01.2011
why are you using isnumeric for int, ints are always numbers
you can use if(money<=0) return SendClientMessage...
Re: Two potential problems with admin system -
iggy1 - 05.01.2011
Yep money is an integer so thats why you get tag mismatch.
Shouldn't your message function look like this also,
pawn Код:
stock SendAdminMessage(color,const string[])
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i))continue;
if(PlayerInfo[playerid][pAdminLevel] > 0)
SendClientMessage(i, color, string);
}
}
Re: Two potential problems with admin system -
admantis - 05.01.2011
What I want to do is like if he does
'/money 15 onehundred' it will say invalid ammount because onehundred isn't a integer, or its not need?
Re: Two potential problems with admin system -
iggy1 - 05.01.2011
Simple do
EDIT: You might want to check if "tmp" is numeric. And if it is, then give "money" the string value of "tmp".
Re: Two potential problems with admin system -
veyron - 05.01.2011
strval already makes it integer, so you simpy dont need it, just check that it isnt 0 or negative
Re: Two potential problems with admin system -
admantis - 05.01.2011
Ye.. it fixed errors. Thanks you both for your helps !!!!!