help with /a command -
Michael_Cuellar - 14.04.2013
pawn Код:
CMD:a(playerid, params[])
{
new result[128],name[MAX_PLAYER_NAME],string[128];
if(sscanf(params, "s[128]", result)) return SendClientMessage(playerid, COLOR_WHITE, "Use: /a [Text]");
if(PlayerInfo[playerid][pAdmin] >=2 || IsPlayerAdmin(playerid)) //
{
format(string, sizeof(string), "Trial Admin %s: %s.",name,result);
SendAdminMessage(COLOR_GREEN,string);
}
if(PlayerInfo[playerid][pAdmin] >=3)
{
format(string, sizeof(string), "Admin %s: %s.",name,result);
SendAdminMessage(COLOR_GREEN,string);
}
if(PlayerInfo[playerid][pAdmin] >=4)
{
format(string, sizeof(string), "Senior Admin %s: %s.",name,result);
SendAdminMessage(COLOR_GREEN,string);
}
if(PlayerInfo[playerid][pAdmin] >=5)
{
format(string, sizeof(string), "Owner %s: %s.",name,result);
SendAdminMessage(COLOR_GREEN,string);
}
return 1;
}
When I say something in admin chat it says it for all ranks,
can someone tell me what im doing wrong?
Re: help with /a command -
zDivine - 14.04.2013
Show me your code for SendAdminMessage
Re: help with /a command -
Michael_Cuellar - 14.04.2013
pawn Код:
stock SendAdminMessage( color, string[] )
{
foreach (Player,i)
{
if( PlayerInfo[ i] [ pAdmin ] > 1 )
{
SendClientMessage( i, color, string );
}
}
}
Re: help with /a command -
Jessyy - 14.04.2013
I don't understand this line "if(PlayerInfo[playerid][pAdmin] >=2 || IsPlayerAdmin(playerid))" an trial admin he can shutdown your server from rcon

how come !!!
Try this:
Код:
CMD:a(playerid, params[])
{
new result[128],
name[MAX_PLAYER_NAME], // this variable is not initialized in your code
string[128];
// get the name of the player that connected
GetPlayerName(playerid, name, sizeof(name));
if(sscanf(params, "s[128]", result)) {
return SendClientMessage(playerid, COLOR_WHITE, "Use: /a [text]");
}
// an alternative for your code "if(PlayerInfo[playerid][pAdmin] >=2 || IsPlayerAdmin(playerid))"
// when the player is logged whit RCON
if(IsPlayerAdmin(playerid)) {
format(string, sizeof(string), "Rcon Admin %s: %s.", name, result);
SendAdminMessage(COLOR_GREEN, string);
}
// otherwise will check his PlayerInfo[playerid][pAdmin] level
else {
switch(PlayerInfo[playerid][pAdmin]) {
// PlayerInfo[playerid][pAdmin] == 2
case 2: {
format(string, sizeof(string), "Trial Admin %s: %s.", name, result);
SendAdminMessage(COLOR_GREEN, string);
}
// PlayerInfo[playerid][pAdmin] == 3
case 3: {
format(string, sizeof(string), "Admin %s: %s.", name, result);
SendAdminMessage(COLOR_GREEN, string);
}
// PlayerInfo[playerid][pAdmin] == 4
case 4: {
format(string, sizeof(string), "Senior Admin %s: %s.", name, result);
SendAdminMessage(COLOR_GREEN, string);
}
// PlayerInfo[playerid][pAdmin] == 5
case 5: {
format(string, sizeof(string), "Owner %s: %s.", name, result);
SendAdminMessage(COLOR_GREEN, string);
}
// if the value of (PlayerInfo[playerid][pAdmin]) is not 2, 3, 4, or 5, the default case is executed
default: {
SendClientMessage(playerid, COLOR_WHITE, "You must have admin permission.");
}
}
}
return 1;
}
stock SendAdminMessage(color, string[])
{
foreach(Player, i) {
if(PlayerInfo[i][pAdmin] > 1) {
SendClientMessage(i, color, string);
}
}
}
A switch statement is basically a structured if/else if/else system (similar to how for is a structured while). The easiest way to explain it is with an example:
Код:
new a = 5;
switch (a) {
case 1: {
// Won't be called
}
case 2: {
// Won't be called
}
case 5: {
// Will be called
}
default: {
// Won't be called
}
}
This is functionally equivalent to:
Код:
new a = 5;
if (a == 1) {
// Won't be called
}
else if (a == 2) {
// Won't be called
}
else if (a == 5) {
// Will called
}
else {
// Won't be called
}
Read more right here
https://sampwiki.blast.hk/wiki/Control_Structures