help with /sethealth
#1

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;
	}
Reply
#2

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

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)