/aheal cmd
#1

Hello, i have a problem with my /a(dmin)heal

pawn Код:
if(strcmp("/aheal", cmdtext, true, 6) == 0)
    {
        new temp[128];
        new giveplayerid;
        new giveplayer[MAX_PLAYER_NAME];
        new playername[MAX_PLAYER_NAME];
        new str[128];
        new idx;
        temp = strtok(cmdtext[5], idx);

        if(!strlen(temp))
            {
                SendClientMessage(playerid, -1, "** [Utilisation]: /aheal [playerid/PartOfName]");
                return 1;
            }


        if(IsPlayerAdmin(playerid))
        {
            giveplayerid = ReturnUser(temp);
            GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
            GetPlayerName(playerid, playername, sizeof(playername));
            if(IsPlayerConnected(giveplayerid))
            {
                format(str, sizeof(str), "L'admin %s a soignй le joueur %s", playername, giveplayer);
                SendClientMessageToAll(COLOR_RED, str);
                return 1;
            }
            else SendClientMessage(playerid, -1, "Le joueur n'est pas connectй/n'existe pas");
            return 1;
        }
        else SendClientMessage(playerid, -1, "Vous n'йtes pas admin.");
        return 1;
    }
When i'm in game, i /rcon login, and when i type /aheal, /aheal 0, /aheal 1, it always show: "Le joueur n'est pas connectй/n'existe pas", which mean "The player is not connected/doesn't exist"
(my in game's ID is 0)

Thanks for help
Reply
#2

pawn Код:
CMD:aheal(playerid, params[])
{
    new targetid, Float:health, targetname[MAX_PLAYER_NAME], adminname[MAX_PLAYER_NAME], string[70], string2[70];
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "Vous n'йtes pas admin.");
    if(sscanf(params,"ui", targetid, health)) return SendClientMessage(playerid, COLOR_RED, "** [Utilisation]: /aheal [playerid/PartOfName]");
    if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Invalid player ID!");
    SetPlayerHealth(targetid, health);
    GetPlayerName(targetid, targetname, sizeof(targetname));
    GetPlayerName(playerid, adminname, sizeof(adminname));
    format(string, sizeof(string), "L'admin %s a soignй le joueur %s.", targetname, targetid, health);
    SendClientMessage(playerid,COLOR_WHITE,string);
    format(string2, sizeof(string2), "%s has set your health to %d.", adminname, health);
    return SendClientMessage(targetid,COLOR_WHITE,string2);
}
Reply
#3

Thanks for the answer.

But, what is sscanf ? and INVALID_PLAYER_ID is a variable ?
Reply
#4

sscanf is a plugin it can be downloaded from here
Sscanf
put the sscanf.dll in your plugins folder (for windows)
and put the sscanf.so in your plugins folder if you have linux
and Also put the sscanf2.inc in your pawno/includes folder
and on the top of your script add
pawn Код:
#include <sscanf2>
Reply
#5

Thanks, but i cannot see what is wrong in my code :/
Reply
#6

Ok, it was because of my strtok, correct value was temp = strtok(cmdtext[6], idx); and not cmdtext[5]
Reply
#7

Hello

try this

pawn Код:
if(strcmp(cmd, "/aheal", true) == 0)
    {
        if(IsPlayerAdmin(playerid))
        {
            new tmp[256], plid, pname[MAX_PLAYER_NAME], aname[MAX_PLAYER_NAME];
            tmp = strtok(cmdtext, idx);
           
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, -1, "** [Utilisation]: /aheal [playerid]");
                return 1;
            }
            plid = strval(tmp);
            if(IsPlayerConnected(plid))
            {
                new length = strlen(cmdtext);
                while((idx < length) && (cmdtext[idx] <= ' '))
                {
                    idx++;
                }
               
                GetPlayerName(plid, pname, MAX_PLAYER_NAME);
                GetPlayerName(playerid, aname, MAX_PLAYER_NAME);
                format(string, sizeof(string), "L'admin %s a soignй le joueur %s", pname, aname);
                SendClientMessageToAll(COLOR_RED, string);
            }
            else
            {
                format(string, sizeof(string), "Le joueur n'est pas connectй/n'existe pas", plid);
                SendClientMessage(playerid, -1, string);
            }
        }
        else
        {
            SendClientMessage(playerid, -1, "Vous n'йtes pas admin.");
        }
        return 1;
    }
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)