How can I make this /setadmin command?
#1

Hi. I'm wanting to create a /setadmin command, but I don't really know where to start. I currently have this, and a scripted register system.
pawn Код:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pKills,
    pDeaths
}
new PlayerInfo[MAX_PLAYERS][pInfo];
How could I use make a certain player a admin, and save it to the file for that player? I've tried this.
pawn Код:
CMD:setadmin(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_BRIGHTRED, "You're not authorized to use this command");
    if(sscanf(params,"ui",ID,levels)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /setadmin [playerid] [level 1-4]");
    if(levels > 4) return SendClientMessage(playerid, COLOR_BRIGHTRED, "LEVELS 1-4");
    if(!IsPlayerConnected(ID)) return SendClientMessage(playerid, COLOR_BRIGHTRED, "That player is not connected.");
    if(PlayerData[ID][AdminLevel] == levels) return SendClientMessage(playerid, COLOR_BRIGHTRED, "ERROR: That player is already that Admin Level.");
    GetPlayerName(playerid,Nam, MAX_PLAYER_NAME);
    GetPlayerName(ID,pname,MAX_PLAYER_NAME);
    if(levels == 0)
    {
        format(str, sizeof(str),"%s has set your Administrator level to %d.",Nam,levels);
        SendClientMessage(ID,COLOR_GREENBLUE,str);
        format(str, sizeof(str), "You have set %s's Administrator leevel to %d",pname,levels);
        SendClientMessage(playerid, COLOR_CYAN,str);
        return 1;
    }
    format(str, sizeof(str),"%s has your Admin level to %d on the server.",Nam,levels);
    SendClientMessage(ID,0xFF9900AA,str);
    format(str, sizeof(str),"You had set %s Admin level to %d!",pname,levels);
    SendClientMessage(playerid,0xFF9900AA,str);
    PlayerData[ID][AdminLevel] = levels;
    return 1;
}
And then get errors.
Код:
C:\Users\Luke\Desktop\Unban\gamemodes\updatedurban.pwn(1434) : error 017: undefined symbol "ID"
C:\Users\Luke\Desktop\Unban\gamemodes\updatedurban.pwn(1435) : error 017: undefined symbol "levels"
C:\Users\Luke\Desktop\Unban\gamemodes\updatedurban.pwn(1436) : error 017: undefined symbol "ID"
C:\Users\Luke\Desktop\Unban\gamemodes\updatedurban.pwn(1437) : error 017: undefined symbol "PlayerData"
C:\Users\Luke\Desktop\Unban\gamemodes\updatedurban.pwn(1437) : error 017: undefined symbol "ID"
C:\Users\Luke\Desktop\Unban\gamemodes\updatedurban.pwn(1437) : error 029: invalid expression, assumed zero
C:\Users\Luke\Desktop\Unban\gamemodes\updatedurban.pwn(1437) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


7 Errors.
How could I define "levels" and "ID" and "PlayerData"? Or do I use [PInfo]?... I'm completely lost.
Reply
#2

pawn Код:
COMMAND:setadmin(playerid, params[])
{
    if(PlayerAcc[playerid][AdminLevel] >= 4)
    {
        if(PlayerLogged[playerid] == 1)
        {
            new Target;
            new Level;
            if(!sscanf(params, "ui", Target, Level))
            {
                if(Target == playerid) return SendClientMessage( playerid, COLOR_RED, "SERVER: Cant perform this command on yourself!" );
                if(Level > 4) return SendClientMessage( playerid, COLOR_RED, "SERVER: Maximum level is 4!" );
                if(Target == INVALID_PLAYER_ID) return SendClientMessage(playerid,red,"ERROR: Wrong player ID");
                if(PlayerAcc[Target][AdminLevel] >= PlayerAcc[playerid][AdminLevel]) return SendClientMessage(playerid,red,"ERROR: You cant perform this on Admins that are equal or higher than your level!");
                PlayerAcc[Target][AdminLevel] = Level;
                new tname[MAX_PLAYER_NAME];
                GetPlayerName(Target,tname,sizeof(tname));
                new pname[MAX_PLAYER_NAME];
                GetPlayerName(playerid,pname,sizeof(pname));
                new MyString[128];
                new TargetString[128];
                format(MyString,sizeof MyString, "You have set %s Admin Level to %i!", tname, Level);
                format(TargetString,sizeof TargetString, "You are now Admin Level %i, thanks to %s!", Level, pname);
                SendClientMessage(Target, COLOR_RED, TargetString );
                SendClientMessage(playerid, COLOR_GREEN, MyString);
                new File:Log = fopen(adminPATH, io_append);
                new logData[128];
                new fTime[6];
                getdate(fTime[0], fTime[1], fTime[2]);
                gettime(fTime[3], fTime[4], fTime[5]);
                format(logData, sizeof logData, "[%02d/%02d/%04d || %02d:%02d:%02d]%s made %s Admin Level: %d!\r\n", fTime[2], fTime[1], fTime[0], fTime[3], fTime[4], fTime[5], pname, tname, Level);
                fwrite(Log, logData);
                fclose(Log);
            }
            else SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /setadmin <playerid> <admin-level>");
        }
        else SendClientMessage(playerid,red,"ERROR: You must be logged in to perform this command!");
    }
    else SendClientMessage(playerid, red, "ERROR: You have to be an Admin level 4 or higher to perform this command!");
    return 1;
}
Reply
#3

Those undefined symbols are variables that you never defined using
Код:
new
This is an example of a /setadmin command.
pawn Код:
CMD:setadmin(playerid,params[])
{
    new level, targetid; /* Defines two variables, one is the variable that will hold the desired admin level.
                                The second one holds the variable for the playerid who's admin level you want to set.*/

    if(!IsPlayerAdmin(playerid)) // Checks if the player is logged into RCON. The ! is if IsPlayerAdmin returns false, or he is not logged into RCON
    {
        return SendClientMessage(playerid,-1,"You are not authorised to use that command."); // If he isnt admin then it returns a message which also stops processing the command.
    }
    if(sscanf(params,"ui",targetid,level)) return SendClientMessage(playerid,-1,"USAGE: /setadmin [playerid] [level]"); // If they typed the command wrong, then tell em how to use it.
   
    else // If all of the above has passed
    {
        // The code below makes their admin level equivalent to what the admin typed.
        PlayerInfo[targetid][pAdmin] = level; // Notice how in the playerid parameter we put targetid since that is the desired playerid to turn admin.
        return 1;
    }
    return 1;
}
Reply
#4

PHP код:
CMD:setadmin(playeridparams[])
{
    new 
IDlevelsstr[128];
    if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1"You're not authorized to use this command");
    if(
sscanf(params,"ui",ID,levels)) return SendClientMessage(playerid, -1"USAGE: /setadmin [playerid] [level 1-4]");
    if(
levels 4) return SendClientMessage(playerid, -1"LEVELS 1-4");
    if(!
IsPlayerConnected(ID)) return SendClientMessage(playerid, -1"That player is not connected.");
    if(
PlayerInfo[ID][AdminLevel] == levels) return SendClientMessage(playeridCOLOR_BRIGHTRED"ERROR: That player is already that Admin Level.");
    
GetPlayerName(playerid,NamMAX_PLAYER_NAME);
    
GetPlayerName(ID,pname,MAX_PLAYER_NAME);
    if(
levels == 0)
    {
        
format(strsizeof(str),"%s has set your Administrator level to %d.",Nam,levels);
        
SendClientMessage(ID,COLOR_GREENBLUE,str);
        
format(strsizeof(str), "You have set %s's Administrator leevel to %d",pname,levels);
        
SendClientMessage(playeridCOLOR_CYAN,str);
        return 
1;
    }
    
format(strsizeof(str),"%s has your Admin level to %d on the server.",Nam,levels);
    
SendClientMessage(ID,0xFF9900AA,str);
    
format(strsizeof(str),"You had set %s Admin level to %d!",pname,levels);
    
SendClientMessage(playerid,0xFF9900AA,str);
    
PlayerInfo[ID][AdminLevel] = levels;
    return 
1;

Reply
#5

Thanks for the help guys. I've managed to create this.
pawn Код:
CMD:setadmin(playerid,params[])
{
    new level, Pname, targetid; /* Defines two variables, one is the variable that will hold the desired admin level.
                                The second one holds the variable for the playerid who's admin level you want to set.*/

    if(sscanf(params,"ui",targetid,level)) return SendClientMessage(playerid,-1,"USAGE: /setadmin [playerid] [level]");
    if(level > 4) return SendClientMessage(playerid, COLOR_BRIGHTRED, "SERVER: Maximum Administrator level is 4.");
    if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_BRIGHTRED, "That player is not connected!");
    new MyString[128];
    new TargetString[128];
    format(MyString,sizeof MyString, "You have set %s Admin Level to %i!", targetid, level);
    format(TargetString,sizeof TargetString, "You are now Admin Level %i, thanks to %s!", level, Pname);
    SendClientMessage(targetid, COLOR_RED, TargetString );
    SendClientMessage(playerid, COLOR_GREEN, MyString);
    if(!IsPlayerAdmin(playerid)) // Checks if the player is logged into RCON. The ! is if IsPlayerAdmin returns false, or he is not logged into RCON
    {
        return SendClientMessage(playerid,-1,"You are not authorized to use that command."); // If he isnt admin then it returns a message which also stops processing the command.
    }
    else // If all of the above has passed
    {
        // The code below makes their admin level equivalent to what the admin typed.
        PlayerInfo[targetid][pAdmin] = level; // Notice how in the playerid parameter we put targetid since that is the desired playerid to turn admin.
    }
    return 1;
}
But how could I get these to save at my "UserPath"?
Here's this, if it helps any.
pawn Код:
forward LoadUser_data(playerid,name[],value[]); //Register system, load user data
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    return 1;
}

stock UserPath(playerid) // Stock function, for the register system
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)