make commands in SELF-ONLY commands
#1

Ok so im trying to make a donator rank and i want some commands to work ONLY on self ,for example we have the /setskin command which u can use to set someones skin ,i want to make a command like /myskin to be able to change only MY skin (the one that types)


anyone can help modify this command? and explain if you can pls,ill have to remake more commands .

pawn Код:
if(strcmp(cmd, "/setskin", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /setskin [playerid/PartOfName] [skin id]");
                return 1;
            }
            new para1;
            new level;
            para1 = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            level = strval(tmp);
            if(level > 299 || level < 1) { SendClientMessage(playerid, COLOR_GREY, "Wrong skin ID!"); return 1; }
            if(PlayerInfo[playerid][pAdmin] >= 1 || PlayerInfo[playerid][pHelper] >= 2 || PlayerInfo[playerid][pDonateRank] >= 2)
            {
                if(IsPlayerConnected(para1))
                {
                    if(para1 != INVALID_PLAYER_ID)
                    {
                        GetPlayerName(para1, giveplayer, sizeof(giveplayer));
                        GetPlayerName(playerid, sendername, sizeof(sendername));
                        PlayerInfo[para1][pChar] = level;
                        format(string, sizeof(string), "Your skin has been changed by Admin %s", sendername);
                        SendClientMessage(para1, COLOR_WHITE, string);
                        format(string, sizeof(string), "You have given %s skin to %d.", giveplayer,level);
                        SendClientMessage(playerid, COLOR_WHITE, string);
                        SetPlayerSkin(para1, PlayerInfo[para1][pChar]);
                    }
                }//not connected
            }
            else
            {
                SendClientMessage(playerid, COLOR_GRAD1, "   you are not authorized to use that command!");
            }
        }
        return 1;
    }

EDIT : also how could i add a timer so the commands work only once every 10 minutes (per player ofc )
Reply
#2

Hi,

I'll do this for you:

Here we got the /myskin [SkinID] command:
pawn Код:
if(strcmp(cmd, "/myskin", true) == 0)
{
    if(LastMySkin[playerid]+600 > gettime()) return SendClientMessage(playerid, COLOR_GRAD2, "ERROR: You can only use this command once every 10 minutes!"); //600 seconds = 10 minutes
    //I wouldn't use IsPlayerConnected at commands, because a player who is not connected won't type any commands.
    //As there is no second parameter, we can use this command without strtok.
    if(!strlen(cmdtext[strlen(cmd)+1]) //If nothing follows after /myskin (The parameter).
    {
        SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /myskin [SkinID]");
        return 1;
    }
    new skin; //We take a new variable
    skin = strval(cmdtext[strlen(cmd)+1]); //and set the value (integer) of the parameter into it.
    if(skin > 299 || skin < 1) return SendClientMessage(playerid, COLOR_GREY, "Wrong skin ID!"); //Checks if valid SkinID
    if(PlayerInfo[playerid][pDonateRank] >= 2) //Checks for the donation Rank
    {
        //Executes the actual command
        PlayerInfo[playerid][pChar] = skin;
        format(string, sizeof(string), "Your changed your skin to %d", skin);
        SendClientMessage(para1, COLOR_WHITE, string);
        SetPlayerSkin(playerid, PlayerInfo[playerid][pChar]);
        LastMySkin[playerid] = gettime(); //Checks when the player typed the command (This is better than timers).
    }
    //Returns an error message if the Rank is too low.
    else SendClientMessage(playerid, COLOR_GRAD1, "ERROR: You need to be Donator Rank #2 to use this command. Please check /donate .");
    return 1;
}
That would be the command, no you need to define the new Player-Variable 'LastMySkin':
pawn Код:
//Just place this at top of your GameMode or FilterScript, whatever you use...
new LastMySkin[MAX_PLAYERS];
And last but not least, we set the variable to 0 when the player connects:
pawn Код:
//Under OnPlayerConnect:
LastMySkin[playerid] = 0;
I hope I have explained everything, and that I haven't forgotten anything for the command, by writing the explanations.

I hope this helps you.
If you have any questions, feel free to ask.

Regards,
Jeffry
Reply
#3

I already found a myskin command and figured out the timer myself,but ill keep the one above for example ,thanks for your help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)