SA-MP Forums Archive
/setlevel yini - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: /setlevel yini (/showthread.php?tid=357538)



/setlevel yini - thefatshizms - 07.07.2012

hello, i guessed on how to make this command but it doesnt work

pawn Code:
CMD:setlevel(playerid, params[])
{
    if(PlayerInfo[playerid][Padmin] >5)
    {
        new id, lvl, string[128], string2[128], string3[128];
        new INI:file = INI_Open(Path(playerid));
        if(sscanf(params,"ui",id,lvl)) return SendClientMessage(playerid, -1, "USAGE: /setlevel <id> <lvl>");
        format(string, sizeof(string), "You have set %s admin level to %d", PlayerName(id), lvl);
        format(string2, sizeof(string2), "Your level has been set to %d by %s", lvl, PlayerName(playerid));
        format(string3, sizeof(string3), "%s is now admin level %d", PlayerName(id), lvl);
        SendClientMessage(playerid, -1, string);
        SendClientMessage(id, -1, string2);
        SendClientMessageToAll(-1, string3);
        INI_WriteInt(file,"Padmin",lvl);
        INI_Close(file);
        return 1;
    }
    else if(PlayerInfo[playerid][Padmin] <5)
    {
        SendClientMessage(playerid, -1, "Your not a admin");
        return 1;
    }
    return 1;
}



Re: /setlevel yini - zT KiNgKoNg - 07.07.2012

Quote:
Originally Posted by thefatshizms
View Post
hello, i guessed on how to make this command but it doesnt work
Try this

pawn Code:
CMD:setlevel(playerid, params[])
{
    if(PlayerInfo[playerid][Padmin] > 5)
    {
        new id, lvl, string[128], string2[128], string3[128];
        new INI:file = INI_Open(Path(playerid));
        if(sscanf(params,"ui",id,lvl)) return SendClientMessage(playerid, -1, "USAGE: /setlevel <id> <lvl>");
        format(string, sizeof(string), "You have set %s admin level to %d", PlayerName(id), lvl);
        format(string2, sizeof(string2), "Your level has been set to %d by %s", lvl, PlayerName(playerid));
        format(string3, sizeof(string3), "%s is now admin level %d", PlayerName(id), lvl);
        SendClientMessage(playerid, -1, string);
        SendClientMessage(id, -1, string2);
        SendClientMessageToAll(-1, string3);
        INI_WriteInt(file,"Padmin",lvl);
        INI_Close(file);
        return 1;
    }
    else if(PlayerInfo[playerid][Padmin] > 5)
    {
        SendClientMessage(playerid, -1, "Your not a admin");
        return 1;
    }
    return 1;
}



Re: /setlevel yini - coole210 - 07.07.2012

I optimised your code.

pawn Code:
CMD:setlevel(playerid, params[])
{
    if(PlayerInfo[playerid][Padmin] < 5) return SendClientMessage(playerid, -1, "Your not a admin");
    new id, lvl, string[128];
    if(sscanf(params,"ui",id,lvl)) return SendClientMessage(playerid, -1, "USAGE: /setlevel <id> <lvl>");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "Invalid playerid");
    if(lvl < 1 || lvl > PlayerInfo[playerid][Padmin] && PlayerInfo[playerid][Padmin] < 5) return SendClientMessage(playerid, -1, "Invalid level");
    format(string, sizeof(string), "You have set %s admin level to %d", PlayerName(id), lvl);
    SendClientMessage(playerid, -1, string);
    format(string, sizeof(string), "Your level has been set to %d by %s", lvl, PlayerName(playerid));
    SendClientMessage(id, -1, string);
    format(string, sizeof(string), "%s is now admin level %d", PlayerName(id), lvl);
    SendClientMessageToAll(-1, string);
    PlayerInfo[id][Padmin] = lvl;
    return 1;
}
I'm assuming player's stats get saved on quit, so I just set their admin VARIABLE to "lvl" and also added a few checks for if player is connected, and a few proper lvl checks, you may change this to your preferences if you wish.


Re: /setlevel yini - thefatshizms - 07.07.2012

Nope doesn't even show "USAGE: /setlevel <id> <lvl>


Re: /setlevel yini - coole210 - 07.07.2012

Maybe you're seeing just a black line (because colour is set to -1 in client messages) or your sscanf doesn't work.


Re: /setlevel yini - thefatshizms - 07.07.2012

soz that was reply to other person with ur code it shows but doesnt write it in my scriptfiles


Re: /setlevel yini - coole210 - 07.07.2012

I know, it shouldn't because I removed the code for doing so. It is pointless to save it to files right away when you can just set the variable and when the player quits it will save to scriptfiles (if you have a saving system).


Quote:
Originally Posted by coole210
View Post
I'm assuming player's stats get saved on quit, so I just set their admin VARIABLE to "lvl" and also added a few checks for if player is connected, and a few proper lvl checks, you may change this to your preferences if you wish.



Re: /setlevel yini - cJMaster_ - 07.07.2012

Code /\
pawn Code:
CMD:setlevel(playerid, params[])
{
    if(PlayerInfo[playerid][Padmin] < 5) return SendClientMessage(playerid, -1, "Your not a admin");
    new id, lvl, string[128];
    if(sscanf(params,"ds", id , lvl)) return SendClientMessage(playerid, -1, "USAGE: /setlevel <id> <lvl>");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "Invalid playerid");
    if(lvl < 1 || lvl > PlayerInfo[playerid][Padmin] && PlayerInfo[playerid][Padmin] < 5) return SendClientMessage(playerid, -1, "Invalid level");
    format(string, sizeof(string), "You have set %s admin level to %d", PlayerName(id), lvl);
    SendClientMessage(playerid, -1, string);
    format(string, sizeof(string), "Your level has been set to %d by %s", lvl, PlayerName(playerid));
    SendClientMessage(id, -1, string);
    format(string, sizeof(string), "%s is now admin level %d", PlayerName(id), lvl);
    SendClientMessageToAll(-1, string);
    PlayerInfo[id][Padmin] = lvl;
    return 1;
}



Re: /setlevel yini - thefatshizms - 08.07.2012

Here is my code
pawn Code:
CMD:setlevel(playerid, params[])
{
    new INI:file = INI_Open(Path(playerid));
    if(!IsPlayerAdmin(playerid)) return 0;
    if(PlayerInfo[playerid][Padmin] < 5) return SendClientMessage(playerid, -1, "Your not a admin");
    new id, lvl, string[128], string2[128], string3[128];
    if(sscanf(params,"us", id , lvl)) return SendClientMessage(playerid, -1, "USAGE: /setlevel <id> <lvl>");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "Invalid playerid");
    format(string, sizeof(string), "You have set %s admin level to %d", PlayerName(id), lvl);
    SendClientMessage(playerid, -1, string);
    format(string2, sizeof(string), "Your level has been set to %d by %s", lvl, PlayerName(playerid));
    SendClientMessage(id, -1, string2);
    format(string3, sizeof(string), "%s is now admin level %d", PlayerName(id), lvl);
    SendClientMessageToAll(-1, string3);
    PlayerInfo[id][Padmin] = lvl;
    INI_WriteInt(file,"Padmin",lvl);
    INI_Close(file);
    return 1;
}
if i do /setlevel 0 1 it will say i set it to 49 and also it still doesnt write it in the file


Re: /setlevel yini - RedJohn - 08.07.2012

Mine one!

pawn Code:
COMMAND:setlevel(playerid,params[])
{
    new id,level;
    if(IsPlayerAdmin(playerid))
    {
   
        if(sscanf(params,"ud",id,level)) return SendClientMessage(playerid,COLOR_RED,"[USAGE]: /setlevel [playerid/name] [level]");
        else
        {
            if(level > 5) return SendClientMessage(playerid, COLOR_RED,"Only 1-5 levels allowed!");
            else
            {
                new string[64], pName[MAX_PLAYER_NAME];
                GetPlayerName(playerid,pName,MAX_PLAYER_NAME);
                format(string,sizeof string,"RCON Administrator promoted %s to administrator!",pName);
                SendClientMessageToAll(COLOR_GREEN,string);
                new INI:File = INI_Open(Path(id));
                INI_WriteInt(File,"Adminlevel",level);
                INI_Close(File);
            }
        }
    }
    else
    {
        return 1;
    }
    return 1;
}