Problem with a command related to health
#1

Hello.
I made a sethealth command, I know there's plenty of them out there, but I just wanted to figure out another way to do it, so basically, if I do /sethealth [someid] [10] it will automatically set the player's health to some other value instead of 10.
Anyone can figure out what am I doing wrong right below?

PHP код:
CMD:sethealth(playeridparams[])
{
    if(!
IsAdminLevel(playerid1)) return ERROR(playerid"You need a higher administrator level to use this command.");
    if(
sscanf(params"rf"params[0], params[1]))
    {
        
USAGE(playerid"/sethealth [player/name] [health]");
        
CMDHELP(playerid"Will set the specified health to the defined player.");
        return 
1;
    }
    if(
params[0] == INVALID_PLAYER_ID) return ERROR(playerid"The ID or name entered was invalid.");
    if(
params[0] == playerid)
    {
        
AdmCmd(playerid"You have successfully set your health to %.1f."params[1]);
    }
    else
    {
        
AdmCmd(playerid"You have successfully set %s's health to %.1f."GetName(params[0]), params[1]);
        
AdmCmd(playerid"Administrator %s has set your health to %.1f."GetName(playerid), params[1]);
    }
    
CMDMessageToAdmins(playerid"sethealth");
    
SetPlayerHealth(params[0], params[1]);
    return 
1;

Reply
#2

Try something like this:

pawn Код:
CMD:sethealth(playerid, params[])
{
    new user, health
    if(!IsAdminLevel(playerid, 1)) return ERROR(playerid, "You need a higher administrator level to use this command.");
    if(!sscanf(params, "ui", user, health))
    {
        if(user != INVALID_PLAYER_ID)
        {
            SetPlayerHealth(user, health);
        }
        if(user == playerid)
        {
            AdmCmd(playerid, "You have successfully set your health to %.1f.", health);
        }
        else if
        {
            AdmCmd(playerid, "You have successfully set %s's health to %.1f.", GetName(user), health);
            AdmCmd(playerid, "Administrator %s has set your health to %.1f.", GetName(playerid), health);
        }
        else return SendClientMessage(playerid, red, "That player is offline.");
    }
    else return SendClientMessage(playerid, white, "/sethealth [playerid] [amount]");
    return 1;
    CMDMessageToAdmins(playerid, "sethealth");
}
Reply
#3

Try this:
Код:
CMD:sethealth( playerid, params[] ) {

	new targetid,
	    Float:newhealth;
	if(!IsAdminLevel(playerid, 1)) return SendClientMessage(playerid, COLOR_RED, "You need a higher administrator level to use this command!");
	if(sscanf(params, "ui", targetid, newhealth)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /sethealth [playerid] [health]");
	if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Playerid is not an active ID.");
	if(targetid == playerid) {
	
	    format(string, sizeof(string), "You have succesfully set your health to %f", newhealth);
	    SendClientMessage(playerid, COLOR_YELLOW, string);
	    SetPlayerHealth(playerid, newhealth);
	    return 1;
	} else {
		format(string, sizeof(string), "You have succesfully set %s's health to %f", GetName(targetid), newhealth);
		SendClientMessage(playerid, COLOR_YELLOW, string);
		format(string, sizeof(string), "Administrator %s has set your health to %f", GetName(playerid), newhealth);
                SetPlayerHealth(targetid, newhealth);
		return 1;
	}
	return 0;
}
You'd have to edit it so it fits your stocks. I couldn't understand all of them so I did my best.
Reply
#4

I think the problem lies within this line
pawn Код:
SetPlayerHealth(params[0], params[1]);
If you put params[1] as second parameter the script read it as integer because params has no tags and tries to convert that value to a float resulting in very high numbers

That should solve it
pawn Код:
SetPlayerHealth(params[0], Float: params[1]);
Instead you could also change 'f' to 'i' because health / armour values can only be integers
pawn Код:
if(sscanf(params, "ri", params[0], params[1]))
Reply
#5

Ok Thanks Nero_3D.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)