Need help - ZCMD /heal [ID]
#1

So basically I tried to script an admin command, called /heal ID. I just started using ZCMD, and I was wondering if anyone could help me with this one.

I get no error when compiling it, but when I try to do /heal 1(no id 1, offline), it shows "ERROR; correct usage /heal [ID]", the same when I do /heal 0(myself).

When I do it as non-admin it works properly giving me the message "ERROR: You're not an administrator".

Here' the code:

pawn Код:
COMMAND:heal(playerid, params[])
{
  if(IsPlayerAdmin(playerid))
  {
      new toplayer, health;
      if(!sscanf(params,"ui",toplayer, health))
      {
        if(IsPlayerConnected(toplayer))
        {
    if(health <= 100)
          {
           new string[64];
           new name[MAX_PLAYER_NAME], PlayerName[MAX_PLAYER_NAME];
           GetPlayerName(playerid, name, sizeof(name));
           GetPlayerName(toplayer, PlayerName, sizeof(PlayerName));
           format(string, sizeof(string), "&s has filled your HP.",name, health);
           SendClientMessage(toplayer, 0xFFFFFF, string);
           format(string, sizeof(string), "You gave %s full HP.",PlayerName, health);
           SendClientMessage(playerid, 0xFFFFFF, string);
           SetPlayerHealth(toplayer, 100);
          }
           else return SendClientMessage(playerid, 0xFFFFFF, "ERROR: This player already has full health!");
        }
        else return SendClientMessage(playerid, 0xFFFFFF, "ERROR: The player is offline.");
      }
      else return SendClientMessage(playerid, 0xFFFFFF, "Correct usage: /heal [ID]");
  }
  else return SendClientMessage(playerid, 0xFFFFFF, "ERROR, You're not an administrator");
  return 1;
}
Reply
#2

Update the sscanf to the latest.
Reply
#3

download link?
Reply
#4

Command fixed, it may work, Just a little thing, your way of scripting is a bit confused, you may lost at your own command. i recommend you try use this way, Simple and direct.
pawn Код:
COMMAND:heal(playerid, params[])
{
    new toplayer,Float:health,string[64],name[MAX_PLAYER_NAME], PlayerName[MAX_PLAYER_NAME];
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFF, "ERROR, You're not an administrator");
    if(sscanf(params,"u",toplayer)) return SendClientMessage(playerid, 0xFFFFFF, "Correct usage: /heal [ID]");
    if(!IsPlayerConnected(toplayer)) return SendClientMessage(playerid, 0xFFFFFF, "ERROR: The player is offline.");
    GetPlayerHealth(toplayer,health);
    if(health == 100) return SendClientMessage(playerid, 0xFFFFFF, "ERROR: This player already has full health!");
    GetPlayerName(playerid, name, sizeof(name));
    GetPlayerName(toplayer, PlayerName, sizeof(PlayerName));
    format(string, sizeof(string), "%s has filled your HP.",name, health);
    SendClientMessage(toplayer, 0xFFFFFF, string);
    format(string, sizeof(string), "You gave %s full HP.",PlayerName, health);
    SendClientMessage(playerid, 0xFFFFFF, string);
    SetPlayerHealth(toplayer, 100);
    return 1;
}
Reply
#5

*sigh* use this but you need to edit a few stuff;
pawn Код:
CMD:sethp(playerid, params[])
{
    new id, health, string[128], string2[128];
    if(sscanf(params, "ui")) return SendClientMessage(playerid, COLOR_RED, "|- [Error] /sethp [playerid] [Amount]");
    if(health > 100) return SendClientMessage(playerid, COLOR_RED, "Dont' even try it, keep it below 100!");
   
    SetPlayerHealth(id, playerVariables[id][pHealth] = health);
    format(string, sizeof(string), "Gamemaster %s has set your health to %i", GetName(playerid), health);
    SendClientMessage(id, COLOR_YELLOW, string);
    format(string2, sizeof(string2), "You have set %s's health to %i", GetName(id), health);
    SendClientMessage(playerid, COLOR_YELLOW, string2);
    return 1;
}
Reply
#6

It's not the problem of sscanf, it's the problem of your code. The message states that the usage is /heal [ID] which in fact it isn't.

pawn Код:
new toplayer, health;
if(!sscanf(params,"ui",toplayer, health))
Well before I explain this, I just want to say that health should be a FLOAT, not an integer.

Anyways, You have 2 parameters here: playerid, and health. It seems like you removed the health part of this code, and it looks like it used to be /sethealth. You have to optimise this a lot more if you want a proper /heal for full HP instead of a customized HP.
Reply
#7

Just give a try using my cmd, it will work.

@windows: he doesn' want a command from another server, he just wanted his cmd fixed. About your command, is wasting 128 cell's which is no good.
Reply
#8

thanks folks! Works now
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)