How to create a /setkills and /setdeaths command?
#1

This is used for adding 1 more kill (It's on OnPlayerDeath).

PlayerInfo[playerid][Deaths]++;
// +1 Death when getting killed.

PlayerInfo[killerid][Kills]++;
// +1 Kill when killing someone

I want a command were I can do /SetKills [PlayerID] [Kills] and /SetDeaths [PlayerID] [Deaths] but I don't know how to make it :/

By the way!
I am using ZCMD

EDIT:

I tried editing a command I already had that I thought was almost the same (/SetScore) but it didn't work this is how it looks:

pawn Код:
CMD:setkills(playerid,params[]) {
 if(PlayerInfo[playerid][Level] >= 5) {
        new tmp[128], tmp2[128], Index; tmp = strtok(params,Index), tmp2 = strtok(params,Index);
        if(isnull(tmp) || isnull(tmp2) || !IsNumeric(tmp2)) return SendClientMessage(playerid, red, "USAGE: /setkills [playerid] [kills]");
        new player1 = strval(tmp), Kills = strval(tmp2), string[128];
        if(PlayerInfo[player1][Level] == ServerInfo[MaxAdminLevel] && PlayerInfo[playerid][Level] != ServerInfo[MaxAdminLevel]) return SendClientMessage(playerid,red,"ERROR: You cannot use this command on this admin");
        if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID) {
            CMDMessageToAdmins(playerid,"SetKills");
            format(string, sizeof(string), "You have set \"%s's\" kills to '%d' ", pName(player1), Kills); SendClientMessage(playerid,blue,string);
            if(player1 != playerid) { format(string,sizeof(string),"Administrator \"%s\" has set your kills to '%d'", pName(playerid), Kills); SendClientMessage(player1,blue,string); }
            return PlayerInfo[player1, Kills);
        } else return SendClientMessage(playerid,red,"ERROR: Player is not connected");
    } else return SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
}
Only different was that I changed
pawn Код:
return SetPlayerScore(player1, score);
to
pawn Код:
return PlayerInfo[player1, Kills);
Reply
#2

pawn Код:
CMD:setkills(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] == 1337)
    {
        new giveplayerid, kills, string[128];
        if(sscanf(params, "ud", giveplayerid, kills) return SendClientMessage(playerid, -1, "USAGE: /setkills [playerid] [amount]")
       
        if(IsPlayerConnected(giveplayerid))
        {
            new PName[64];
            GetPlayerName(playerid, PName, sizeof(PName));
            PlayerInfo[giveplayerid][Kills] = amount;
            format(string, sizeof(string), "Your kills have been set to %d", amount);
            SendClientMessage(giveplayerid, -1, string);
            format(string, sizeof(string), "You have set %s's kills to %d", PName, amount);
            SendClientMessage(playerid, -1, string);
        }
    }
    else
    {
        SendClientMessage(playerid, -1, "You are not authorized to use this command!");
        return 1;
    }
    return 1;
}
There is /setkills.
You should be able to use that for a guide for /setdeaths, if not, let me know and i'll make that to.

You can also change "1337" to whatever level you want, and "-1" to any color you want.

Hope this helps!
Reply
#3

If you use sscanf as well...


pawn Код:
CMD:set(playerid, params[])
{
    //Check if they're admin
    if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xCC0000AA, "You aren't an admin!"); //replace with your admin stuff
   
    //We create 3 variable to store our params in
    new target, type[10], amount;
   
    //We use sscanf to do it (it returns 1 if nothing is found so we send a usage message if nothing is found)
    if(sscanf(params, "rs[10]i", target, type, amount)) return SendClientMessage(playerid, 0xCC0000AA, "USAGE: /set [player] [kills/deaths] [amount]");
   
    //We compare what they typed for the type parameter with "Kills"
    if(!strcmp(type, "Kills", true)) //it returns 0 if they're the same...true = ignore case
    {
        PlayerInfo[target][Kills] = amount; //We set their kills to the amount parameter
        //Send them some messages or whatever
    }
    else if(!strcmp(type, "Deaths", true)) //same as above but for deaths
    {
        PlayerInfo[target][Deaths] = amount;
        //Send them a message or whatever you want to do
    }
    return 1;
}
/*
    Sscanf params used:
        r - for playerid/player name
        s[stringsize] - for strings
        i - for integers
*/
EDIT: messed up my usage message lol (forgot player) - also forgot to actually use the type variable fail
Reply
#4

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
If you use sscanf as well...


pawn Код:
CMD:set(playerid, params[])
{
    //Check if they're admin
    if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xCC0000AA, "You aren't an admin!"); //replace with your admin stuff
   
    //We create 3 variable to store our params in
    new target, type[10], amount;
   
    //We use sscanf to do it (it returns 1 if nothing is found so we send a usage message if nothing is found)
    if(sscanf(params, "rs[10]i", target, type, amount)) return SendClientMessage(playerid, 0xCC0000AA, "USAGE: /set [kills/deaths] [amount]");
   
    //We compare what they typed for the type parameter with "Kills"
    if(!strcmp(params, "Kills", true)) //it returns 0 if they're the same...true = ignore case
    {
        PlayerInfo[target][Kills] = amount; //We set their kills to the amount parameter
        //Send them some messages or whatever
    }
    else if(!strcmp(params, "Deaths", true)) //same as above but for deaths
    {
        PlayerInfo[target][Deaths] = amount;
        //Send them a message or whatever you want to do
    }
    return 1;
}
/*
    Sscanf params used:
        r - for playerid/player name
        s[stringsize] - for strings
        i - for integers
*/
Ehh. Didn't even think about doing it that way. :P
Nice, should probably use this one.

But I use 'u' for players name, never used 'r'. :P

Good job Antonio.
Reply
#5

Would be nice if you tried editing the command I have as /SetScore (It's in the first post)
Because that would make it alot easier for me to understand.

EDIT:

Problem Solved.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)