SA-MP Forums Archive
help with /sethealth - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: help with /sethealth (/showthread.php?tid=170295)



help with /sethealth - mrcoolballs - 22.08.2010

can somebody tell me what is wrong with this, wheni try it in game if i type /sethealth 0 100, it only reads it like im saying /sethealth 0 and it sets my health to 0 heres the code

Код:
if(strcmp(cmd,"/sethealth",true) == 0)
{
	new tmp[256];
	new otherplayer = strval(tmp);
	tmp = strtok(cmdtext, idx);
	new health = strval(tmp);
	new name[MAX_PLAYER_NAME], nname[MAX_PLAYER_NAME];
	new string[128];
	GetPlayerName(playerid, name, sizeof(name));
	GetPlayerName(otherplayer, nname, sizeof(nname));
	if(!strlen(tmp)) return SendClientMessage(playerid,ORANGE,"USAGE: /sethealth id health");
	if(health < 0 || health > 100) return SendClientMessage(playerid,ORANGE,"Invalid Health");
 	if(PlayerInfo[playerid][Level] > 2)
  	{
	        if(IsPlayerConnected(otherplayer))
	        {
	            SetPlayerHealth(otherplayer,health);
	            format(string,sizeof(string),"You have set %s's health to %d",nname,health);
	            SendClientMessage(playerid,ORANGE,string);
	            format(string,sizeof(string),"Admin %s has set your health to %d",name,health);
	            SendClientMessage(otherplayer,ORANGE,string);
			}
			else
			{
			    SendClientMessage(playerid,ORANGE,"Invalid ID");
			    return 1;
			}
	}
	else
	{
	    SendClientMessage(playerid,ORANGE,"You have to be level 3 to use this command");
	    return 1;
	}



Re: help with /sethealth - ZeRo_HUN - 22.08.2010

Use sscanf and zcmd; They are much more easier and faster.


Re: help with /sethealth - Sky4D - 22.08.2010

Quote:
Originally Posted by ZeRo_HUN
Посмотреть сообщение
Use sscanf and zcmd; They are much more easier and faster.
Agreed. Here's an example with ZCMD & sscanf:

pawn Код:
COMMAND:sethealth(playerid, params[])
{
    new user, health;
    if(!sscanf(params, "ui", user, health))
    {
        if(user != INVALID_PLAYER_ID)
        {
            SetPlayerHealth(user, health);
        }
        else return SendClientMessage(playerid, red, "Player offline.");
    }
    else return SendClientMessage(playerid, white, "/sethealth id health");
    return 1;
}