Help /makeadmin and /admins
#1

So i want to start creating my own script, and ****** some tuturials about creating the cmd's and etc.
So i created /makeadmin, which i login on RCON, and use the cmd on me, then when i use /admins, it does not show my name.

Idk why. that's the only thing i'v done with the script. also i got alot of errors, i'll post the errors and the cmd's.


This are the errors
Код:
C:\Users\User\Desktop\samp03dsvr_R2_win32\gamemodes\Daniel.pwn(7) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\samp03dsvr_R2_win32\gamemodes\Daniel.pwn(101) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\samp03dsvr_R2_win32\gamemodes\Daniel.pwn(146) : warning 217: loose indentation
C:\Users\User\Desktop\samp03dsvr_R2_win32\gamemodes\Daniel.pwn(159) : warning 217: loose indentation
C:\Users\User\Desktop\samp03dsvr_R2_win32\gamemodes\Daniel.pwn(168) : warning 217: loose indentation
C:\Users\User\Desktop\samp03dsvr_R2_win32\gamemodes\Daniel.pwn(174) : warning 217: loose indentation
C:\Users\User\Desktop\samp03dsvr_R2_win32\gamemodes\Daniel.pwn(379) : warning 219: local variable "string" shadows a variable at a preceding level
This is the /makeadmin command

Код:
new cmd[256], idx;
	cmd = strtok(cmdtext, idx);
	if(strcmp(cmd, "/makeadmin", true) == 0)
	{
	       new string[128];
	       new tmp[256];
	       new player[MAX_PLAYER_NAME], giveplayer[MAX_PLAYER_NAME];
	       new giveplayerid;
	       if (IsPlayerAdmin(playerid))
	       {
	               tmp = strtok(cmdtext, idx);
	               if(!strlen(tmp))
	               {
	                       SendClientMessage(playerid, 0x00C2ECFF, "USAGE: /makeadmin [playerid] [level]");
	                       SendClientMessage(playerid, 0x00C2ECFF, "FUNCTION: Player will be an admin.");
	                       return 1;
	               }
	               giveplayerid = ReturnUser(tmp);
	               tmp = strtok(cmdtext, idx);
	               new level = strval(tmp);
	               if(giveplayerid != INVALID_PLAYER_ID)
	               {
	                       GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
	                       GetPlayerName(playerid, player, sizeof(player));
	                       PlayerInfo[giveplayerid][AdminLevel] = level;
	                       printf("Admin %s made %s a level %d admin.", player, giveplayer, level);
	                       format(string, sizeof(string), "You are now an administrator level %d thanks to %s.", level,  player);
	                       SendClientMessage(giveplayerid, 0x00C2ECFF, string);
	                       format(string, sizeof(string), "You have given %s level %d admin.",  giveplayer,PlayerInfo[giveplayerid][AdminLevel]);
	               }
	               else if(giveplayerid == INVALID_PLAYER_ID)
	               {
	                       format(string, sizeof(string), "%i is not an active player.", giveplayerid);
	                       SendClientMessage(playerid, 0xE60000FF, string);
	               }
	       }
	       else
	       {
	           SendClientMessage(playerid, 0xE60000FF, "You are not a lead admin!");
	       }
	       return 1;
	}
And the /admins command

Код:
if (strcmp(cmd, "/admins", true) == 0)
    {
    if(IsPlayerConnected(playerid))
      {
        SendClientMessage(playerid, 0xE60000FF, " ");
        SendClientMessage(playerid, 0xE60000FF, "Online Admins: ");
            for(new i = 0; i < MAX_PLAYERS; i++)
            {
                if(IsPlayerConnected(i))
                {
                  if(PlayerInfo[i][pAdmin] >= 1 && PlayerInfo[i][pAdmin] < 1341)
                  {
                    new admtext[64];
                    if(PlayerInfo[i][pAdmin] == 1337) { admtext = "Lead Admin"; }
                    else if(PlayerInfo[i][pAdmin] == 4) { admtext = "High Admin"; }
                        else if(PlayerInfo[i][pAdmin] == 3) { admtext = "Normal Admin"; }
                        else if(PlayerInfo[i][pAdmin] == 2) { admtext = "Low Admin"; }
                        else if(PlayerInfo[i][pAdmin] == 1) { admtext = "Moderator"; }
                        else { admtext = "Moderator"; }
                        GetPlayerName(i, sendername, sizeof(sendername));
                        if(AdminDuty[i] == 0)
                        {
                            format(string, 256, "%s ( %s )", sendername, admtext);
                            SendClientMessage(playerid, 0xE60000FF, string);
                        }
                        else
                        {
                          format(string, 256, "%s ( %s )", sendername, admtext);
                            SendClientMessage(playerid, 0xE60000FF, string);
                        }
                    }
                }
            }
        }
        return 1;
    }
	return 0;
}
Thanks for the helpers
Reply
#2

About indentation and check about the local variable "string" shadows a variable at a preceding level delete the "new string[ value_here ];" from the lines 7, 101, 379
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[256], idx;
    cmd = strtok(cmdtext, idx);
    if(strcmp(cmd, "/makeadmin", true) == 0) {
        new string[128];
        new tmp[256];
        new player[MAX_PLAYER_NAME], giveplayer[MAX_PLAYER_NAME];
        new giveplayerid;
        if (IsPlayerAdmin(playerid)) {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp)) {
                SendClientMessage(playerid, 0x00C2ECFF, "USAGE: /makeadmin [playerid] [level]");
                SendClientMessage(playerid, 0x00C2ECFF, "FUNCTION: Player will be an admin.");
                return 1;
            }
            giveplayerid = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            new level = strval(tmp);
            if(giveplayerid != INVALID_PLAYER_ID) {
                GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                GetPlayerName(playerid, player, sizeof(player));
                PlayerInfo[giveplayerid][AdminLevel] = level;
                printf("Admin %s made %s a level %d admin.", player, giveplayer, level);
                format(string, sizeof(string), "You are now an administrator level %d thanks to %s.", level,  player);
                SendClientMessage(giveplayerid, 0x00C2ECFF, string);
                format(string, sizeof(string), "You have given %s level %d admin.",  giveplayer,PlayerInfo[giveplayerid][AdminLevel]);
            }
            else if(giveplayerid == INVALID_PLAYER_ID) {
                format(string, sizeof(string), "%i is not an active player.", giveplayerid);
                SendClientMessage(playerid, 0xE60000FF, string);
            }
        }
        else {
            SendClientMessage(playerid, 0xE60000FF, "You are not a lead admin!");
        }
        return 1;
    }
    if (strcmp(cmd, "/admins", true) == 0) {
        if(IsPlayerConnected(playerid)) {
            SendClientMessage(playerid, 0xE60000FF, " ");
            SendClientMessage(playerid, 0xE60000FF, "Online Admins: ");
            for(new i = 0; i < MAX_PLAYERS; i++) {
                if(IsPlayerConnected(i)) {
                    if(PlayerInfo[i][pAdmin] >= 1 && PlayerInfo[i][pAdmin] < 1341) {
                        new admtext[64];
                        if(PlayerInfo[i][pAdmin] == 1337) { admtext = "Lead Admin"; }
                        else if(PlayerInfo[i][pAdmin] == 4) { admtext = "High Admin"; }
                        else if(PlayerInfo[i][pAdmin] == 3) { admtext = "Normal Admin"; }
                        else if(PlayerInfo[i][pAdmin] == 2) { admtext = "Low Admin"; }
                        else if(PlayerInfo[i][pAdmin] == 1) { admtext = "Moderator"; }
                        else { admtext = "Moderator"; }
                        GetPlayerName(i, sendername, sizeof(sendername));
                        if(AdminDuty[i] == 0) {
                            format(string, 256, "%s ( %s )", sendername, admtext);
                            SendClientMessage(playerid, 0xE60000FF, string);
                        }
                        else {
                            format(string, 256, "%s ( %s )", sendername, admtext);
                            SendClientMessage(playerid, 0xE60000FF, string);
                        }
                    }
                }
            }
        }
        return 1;
    }
    return 0;
}
Reply
#3

Oh thanks alot pal

but still got these warnings

Код:
C:\Users\User\Desktop\samp03dsvr_R2_win32\gamemodes\Daniel.pwn(7) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\samp03dsvr_R2_win32\gamemodes\Daniel.pwn(100) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\samp03dsvr_R2_win32\gamemodes\Daniel.pwn(374) : warning 219: local variable "string" shadows a variable at a preceding level
Here are the lines

This is line 7-24

Код:
strtok(const string[], &index)
{
	new length = strlen(string);
	while ((index < length) && (string[index] <= ' '))
	{
		index++;
	}

	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}
Line 100

Код:
new string[128];
And line 309-381
Код:
stock ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
    new pos = 0;
    while (text[pos] < 0x21) // Strip out leading spaces
    {
        if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
        pos++;
    }
    new userid = INVALID_PLAYER_ID;
    if (IsNumeric(text[pos])) // Check whole passed string
    {
        // If they have a numeric name you have a problem (although names are checked on id failure)
        userid = strval(text[pos]);
        if (userid >=0 && userid < MAX_PLAYERS)
        {
            if(!IsPlayerConnected(userid))
            {
                userid = INVALID_PLAYER_ID;
            }
            else
            {
                return userid; // A player was found
            }
        }
    }
    // They entered [part of] a name or the id search failed (check names just incase)
    new len = strlen(text[pos]);
    new count = 0;
    new name[MAX_PLAYER_NAME];
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            GetPlayerName(i, name, sizeof (name));
            if (strcmp(name, text[pos], true, len) == 0) // Check segment of name
            {
                if (len == strlen(name)) // Exact match
                {
                    return i; // Return the exact player on an exact match
                }
                else // Partial match
                {
                    count++;
                    userid = i;
                }
            }
        }
    }
    if (count != 1)
    {
        if (playerid != INVALID_PLAYER_ID)
        {
            if (count)
            {
                SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow search.");
            }
            else
            {
                SendClientMessage(playerid, 0xFF0000AA, "No matching user found.");
            }
        }
        userid = INVALID_PLAYER_ID;
    }
    return userid; // INVALID_PLAYER_ID for bad return
}
IsNumeric(const string[])
{
    for (new i = 0, j = strlen(string); i < j; i++)
    {
        if (string[i] > '9' || string[i] < '0') return 0;
    }
    return 1;
}
Reply
#4

Ye and still i don't see my self on /admins when i make my self admin lvl 1 via Rcon
Reply
#5

Delete the string from line 100 and replace IsNumeric and strtok to
pawn Код:
strtok(const Msg[], &index)
{
    new length = strlen(Msg);
    while ((index < length) && (Msg[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (Msg[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = Msg[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
IsNumeric(const Msg[])
{
    for (new i = 0, j = strlen(Msg); i < j; i++)
    {
        if (Msg[i] > '9' || Msg[i] < '0') return 0;
    }
    return 1;
}
Reply
#6

Maybe because the CMD, set PlayerInfo[giveplayerid][AdminLevel] and the /admins check for PlayerInfo[i][Admin].
Try making it by yourself, instead of copying from 2 different scripts.....
Reply
#7

No more errors but still, when i use /makeadmin [my id] [lvl1]
and then type /admins, i don't see my name there.
Reply
#8

The problem is on your code not on the custom functions: strtok, isnumer etc..
Reply
#9

Okay awesome thanks, Fixed it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)