setplayerhealth
#1

i searched alot but i couldn't find anything, i want a basic sethealth command, like this /sethealth id amount
i searched the wiki but i only found the /heal commands that set your health to a preset number, which i don't need them.

Код:
Public onplayerCommandText (playerid,cmdtext[])
{
	 if(strcmp(cmdtext, "/setplayerhealth))
	  SetPlayerHealth(playerid, float);
	  return 1;
	  
  }
this isn't working, i'm new to scripting.
Reply
#2

First, if you're new you should know that strcmp is very slow and outdated.

I suggest you to use ZCMD and SSCANF.

Heres a command in ZCMD and sscanf.

PHP код:
CMD:sethealth(playeridparams[])
{
    new 
Float:health;
    if(
sscanf(parmas"h"health)) return SendClientMessage(playerid, -1"[Server]: /sethealth [value]");
    
SetPlayerHealth(playeridhealth);

Not tested.

PHP код:
CMD:sethealth(playeridparams[])
{
    new 
idFloat:health;
    if(
sscanf(parmas"uh"idhealth)) return SendClientMessage(playerid, -1"[Server]: /sethealth [id] [value]");
    if(!
IsPlayerConnected(id)) return SendClientMessage(playerid, -1"[Server]: Player is offline.");
    
SetPlayerHealth(idhealth);

Heres one with ID, not tested.
Reply
#3

Is it a HEALME command or Admin SetHealth command ?
BTW I suggest you to use ZCMD its easier and faster to use.

ZCMD: https://sampforum.blast.hk/showthread.php?tid=91354
Reply
#4

As the above members already suggested, ZCMD and sscanf is a very good combination for commands.

PHP код:
CMD:sethealth(playeridparams[])
{
    new
        
id,
        
Floatamount;
    
    if (
sscanf(params"rf"idamount)) return SendClientMessage(playerid, -1"Usage: /sethealth <ID/Part Of Name> <amount>");
    if (
id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1"Invalid player");
    
//if (!(0.0 <= amount <= 100.0)) return SendClientMessage(playerid, -1, "You can set an amount of health between 0.0 and 100.0");
    
    
SetPlayerHealth(idamount);
    return 
1;

@Jamester: "h" specifier is for hex.
Reply
#5

PHP код:
if(strcmp(cmd"/sethp"true) == 0)
    {
        if(
IsPlayerConnected(playerid))
        {
            
tmp strtok(cmdtextidx);
            if(!
strlen(tmp))
            {
                
SendClientMessage(playeridCOLOR_WHITE"USAGE: /sethp [playerid/PartOfName] [health]");
                return 
1;
            }
            new 
playa;
            new 
health;
            
playa ReturnUser(tmp);
            
tmp strtok(cmdtextidx);
            if(!
strlen(tmp))
            {
                
SendClientMessage(playeridCOLOR_WHITE"USAGE: /sethp [playerid/PartOfName] [health]");
                return 
1;
            }
            
health strvalEx(tmp);
            if(
PlayerInfo[playerid][pAdmin] >= 4)
            {
                if(
IsPlayerConnected(playa))
                {
                    if(
playa != INVALID_PLAYER_ID)
                    {
                        if(
PlayerInfo[playa][pAdmin] > PlayerInfo[playerid][pAdmin] && health == 0)
                        {
                            
format(stringsizeof(string), "{AA3333}AdmCmd{FFFF00}: %s was killed, reason: Attempting to set a higher admin's health to 0."PlayerName(playerid));
                            
ABroadCast(COLOR_LIGHTREDstring1);
                            
SetPlayerHealth(playerid,0);
                            return 
1;
                        }
                        
SetPlayerHealth(playahealth);
                        
format(stringsizeof(string), "   You have set %s's health to %d !",PlayerName(playa),health);
                        
SendClientMessage(playeridCOLOR_GREYstring);
                    }
                }
            }
            else
            {
                
SendClientMessage(playeridCOLOR_GRAD1"   You are not authorized to use that command !");
            }
        }
        return 
1;
    } 
Use this cmd for help ppl
Reply
#6

Quote:
Originally Posted by SoFahim
Посмотреть сообщение
PHP код:
if(strcmp(cmd"/sethp"true) == 0)
    {
        if(
IsPlayerConnected(playerid))
        {
            
tmp strtok(cmdtextidx);
            if(!
strlen(tmp))
            {
                
SendClientMessage(playeridCOLOR_WHITE"USAGE: /sethp [playerid/PartOfName] [health]");
                return 
1;
            }
            new 
playa;
            new 
health;
            
playa ReturnUser(tmp);
            
tmp strtok(cmdtextidx);
            if(!
strlen(tmp))
            {
                
SendClientMessage(playeridCOLOR_WHITE"USAGE: /sethp [playerid/PartOfName] [health]");
                return 
1;
            }
            
health strvalEx(tmp);
            if(
PlayerInfo[playerid][pAdmin] >= 4)
            {
                if(
IsPlayerConnected(playa))
                {
                    if(
playa != INVALID_PLAYER_ID)
                    {
                        if(
PlayerInfo[playa][pAdmin] > PlayerInfo[playerid][pAdmin] && health == 0)
                        {
                            
format(stringsizeof(string), "{AA3333}AdmCmd{FFFF00}: %s was killed, reason: Attempting to set a higher admin's health to 0."PlayerName(playerid));
                            
ABroadCast(COLOR_LIGHTREDstring1);
                            
SetPlayerHealth(playerid,0);
                            return 
1;
                        }
                        
SetPlayerHealth(playahealth);
                        
format(stringsizeof(string), "   You have set %s's health to %d !",PlayerName(playa),health);
                        
SendClientMessage(playeridCOLOR_GREYstring);
                    }
                }
            }
            else
            {
                
SendClientMessage(playeridCOLOR_GRAD1"   You are not authorized to use that command !");
            }
        }
        return 
1;
    } 
Use this cmd for help ppl
Congratulations, you know how to copy stuff from your script! Who's to say he has a PlayerInfo variable?
Reply
#7

Quote:
Originally Posted by Jamester
Посмотреть сообщение
Congratulations, you know how to copy stuff from your script! Who's to say he has a PlayerInfo variable?
-_- He need to check this cmd and match his cmd . So that he can see what problem he did. I don't mean to give him the cmd . -_-
Reply
#8

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
As the above members already suggested, ZCMD and sscanf is a very good combination for commands.

PHP код:
CMD:sethealth(playeridparams[])
{
    new
        
id,
        
Floatamount;
    
    if (
sscanf(params"rf"idamount)) return SendClientMessage(playerid, -1"Usage: /sethealth <ID/Part Of Name> <amount>");
    if (
id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1"Invalid player");
    
//if (!(0.0 <= amount <= 100.0)) return SendClientMessage(playerid, -1, "You can set an amount of health between 0.0 and 100.0");
    
    
SetPlayerHealth(idamount);
    return 
1;

@Jamester: "h" specifier is for hex.
since samp 0.3 the SetPlayerHealth amount is not float. As I know
Reply
#9

Quote:
Originally Posted by bgedition
Посмотреть сообщение
since samp 0.3 the SetPlayerHealth amount is not float. As I know
Health and Armour will always be floating point numbers (floats).

pawn Код:
native SetPlayerHealth(playerid, Float:health);
native GetPlayerHealth(playerid, &Float:health);
native SetPlayerArmour(playerid, Float:armour);
native GetPlayerArmour(playerid, &Float:armour);
Reply
#10

Yea, but you can use normal integer for that, too. Right?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)