[HELP]HEAL COMMAND
#1

Hi. I made a heal command but it heals only me even if i tipe /aheal 3 and i have id 3 online still i get healed and he doesn't. Here is my code :

pawn Код:
if(strcmp(cmd, "/aheal", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GREY, "USAGE: /aheal [playerid]");
                return 1;
            }
            if(IsPlayerConnected(giveplayerid))
            {
                if(giveplayerid != INVALID_PLAYER_ID)
                {
                    GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
            //      GetPlayerName(playerid, sendername, sizeof(sendername));
                    if(IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdmin] >= 102)
                    {
                            new Float:tempheal;
                            GetPlayerHealth(giveplayerid,tempheal);
                            SetPlayerHealth(giveplayerid, 100);
                            SetPlayerArmour(playerid,100);
                            PlayerPlaySound(giveplayerid, 1052, 0.0, 0.0, 0.0);
                            {
                             format(string, sizeof(string), "Server : %s Has been healed by admin %s.", PlayerName[giveplayerid], PlayerName[playerid]);
                                SendClientMessageToAll(COLOR_RED, string);
                                }
                    }
                    else
                    {
                        SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use that command !");
                        return 1;
                    }
                }
            }
            else
            {
                format(string, sizeof(string), "That player is offline.", giveplayerid);
                SendClientMessage(playerid, COLOR_GREY, string);
            }
        }
        return 1;
    }
Reply
#2

bump topic
Reply
#3

pawn Код:
COMMAND:aheal(playerid, params[])
{
        new otherid;
        if(sscanf(params, "i", otherid)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /aheal [ID]");
        if(!IsPlayerConnected(otherid)) return SendClientMessage(playerid, COLOR_GREY, "That Player Is Not Connected!");
        SetPlayerHealth(otherid, 100);
        return 1;
}
^^ Sped up, More efficient And SO MUCH EASIER.

I suggest ZCMD and SSCANF all the way, strtok Gives me a headache.
Reply
#4

No, I want my command to remain the same but to solve only my problem !
Reply
#5

I did it

pawn Код:
if(strcmp(cmd, "/aheal", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GREY, "USAGE: /aheal [playerid]");
                return 1;
            }
            if(IsPlayerConnected(strval(tmp))
            {
                if(IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdmin] >= 102)
                {
                    SetPlayerHealth(strval(tmp), 100.0);
                    SetPlayerArmour(strval(tmp),100.0);
                    PlayerPlaySound(strval(tmp), 1052, 0.0, 0.0, 0.0);
                    PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
                    format(string, sizeof(string), "Server : %s Has been healed by admin %s.", PlayerName[strval(tmp)], PlayerName[playerid]);
                    SendClientMessageToAll(COLOR_RED, string);
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use that command !");
                    return 1;
                }
            }
            else
            {
                format(string, sizeof(string), "That player is offline.", giveplayerid);
                SendClientMessage(playerid, COLOR_GREY, string);
            }
        }
        return 1;
    }
I hope that i have helped
Reply
#6

try this... (it should work... i tried this on my gamemode and works perfectly!!!
pawn Код:
if(strcmp(cmd, "/aheal", true) == 0){
new tmp[256];
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)){
SendClientMessage(playerid, COLOUR_ORANGE, "Usage: /aheal [playerid]");
return 1;
}
new victim;
victim = strval(tmp);
new playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
new playername2[MAX_PLAYER_NAME];
new string[128];
GetPlayerName(victim, playername2, sizeof(playername2));
if(!IsPlayerConnected(victim) && (victim != INVALID_PLAYER_ID)){
if((IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdmin] >= 102)){
format(string, sizeof(string), "The admin %s healed %s.", playername, playername2);
SendClientMessageToAll(COLOUR_RED, string);
SetPlayerHealth(victim, 100);
}
else{
SendClientMessage(playerid, COLOUR_RED, "You must be an admin to use this command!");
return 1;
}
}
else{
SendClientMessage(playerid, COLOUR_RED, "this player is not connected");
}
return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)