[HELP]Aheal cmd
#1

Hello, I have this /aheal command but it only heals me and even if I tipe the wrong id still it heals only me and that "That player is offline" doesn't work. Help please.

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(giveplayerid, 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

PHP код:
if(strcmp(cmd"/aheal"true) == 0)
    {
        if(
IsPlayerConnected(playerid))
        {
            
tmp strtok(cmdtextidx);
            new 
giveplayerid;
            
giveplayerid ReturnUser(tmp);
            if(!
strlen(tmp))
            {
                
SendClientMessage(playeridCOLOR_GREY"USAGE: /aheal [playerid]");
                return 
1;
            }
            if(
IsPlayerConnected(giveplayerid))
            {
                if(
giveplayerid != INVALID_PLAYER_ID)
                {
                    
GetPlayerName(giveplayeridgiveplayersizeof(giveplayer));
            
//      GetPlayerName(playerid, sendername, sizeof(sendername));
                    
if(IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdmin] >= 102)
                    {
                            
SetPlayerHealth(giveplayerid100);
                            
SetPlayerArmour(giveplayerid100);
                            
PlayerPlaySound(giveplayerid10520.00.00.0);
                            {
                                 
format(stringsizeof(string), "Server : %s Has been healed by admin %s."PlayerName[giveplayerid], PlayerName[playerid]);
                                 
SendClientMessageToAll(COLOR_REDstring);
                            }
                    }
                    else
                    {
                        
SendClientMessage(playeridCOLOR_GREY"You are not authorized to use that command !");
                        return 
1;
                    }
                }
                else
                {
                    
format(stringsizeof(string), "That player is offline.");
                    
SendClientMessage(playeridCOLOR_GREYstring);
                }
            }
        }
        return 
1;
    } 
Reply
#3

I suggest you to use Sscanf2 it's more easier ....., i hate strtok and strcmp they're laggy as hell.
Reply
#4

@Jafet_Macario Thanks, it works but when I tipe /aheal 1 it doesn't shows that player is offline
Reply
#5

Uhm... try again my first code with ReturnUser(tmp); and add this:
pawn Код:
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
    new pos = 0;
    while (text[pos] < 0x21) // Strip out leading spaces
    {
        if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
        pos++;
    }
    new userid = INVALID_PLAYER_ID;
    if (IsNumeric(text[pos])) // Check whole passed string
    {
        userid = strval(text[pos]);
        if (userid >=0 && userid < MAX_PLAYERS)
        {
            if(!IsPlayerConnected(userid))
            {
                userid = INVALID_PLAYER_ID;
            }
            else
            {
                return userid;
            }
        }
    }
    new len = strlen(text[pos]);
    new count = 0;
    new name[MAX_PLAYER_NAME];
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            GetPlayerName(i, name, sizeof (name));
            if (strcmp(name, text[pos], true, len) == 0)
            { if (len == strlen(name)) { return i;
                } else  {
                    count++;
                    userid = i;
                } } } } if (count != 1)
    { if (playerid != INVALID_PLAYER_ID)
        { if (count)
            { SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow earch");
            } else { SendClientMessage(playerid, 0xFF0000AA, "No matching user found");}
                } userid = INVALID_PLAYER_ID; } return userid;
}
Reply
#6

Still the same thing
Reply
#7

BUMP, anyone knows what this problem is ?
Reply
#8

pawn Код:
CMD:aheal(playerid, params[])
{
    new id;
    if(sscanf(params, "u", id))return SendClientMessage(playerid, COLOR_GREY, "Usage: /aheal [playerid/UserName]");
    if(IsPlayerConnected(id))
    {
        SetPlayerHealth(id, 100);
        SetPlayerArmour(id, 100);
    }
    return 1;
}
here ZCMD/sscanf you can edit it...
Reply
#9

Thank's but I don't need this I want my command to be fixed that's all!
Reply
#10

Quote:
Originally Posted by [Aka]Dragonu
Посмотреть сообщение
Hello, I have this /aheal command but it only heals me and even if I tipe the wrong id still it heals only me and that "That player is offline" doesn't work. Help please. [/pawn]
It will heal only ID 0, because "giveplayerid" has no value assigned

pawn Код:
if(strcmp(cmd, "/aheal", true) == 0)
    {
        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);
            SetPlayerArmour(strval(tmp), 100);
            PlayerPlaySound(strval(tmp), 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 authorised to use this command!");
                }

            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "Player is not connected!");
            }
            return 1;
        }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)