Tested and works. I used the colorchat.inc, because it was much easier. If you want, you could replace the ColorMessages with whatever you want, doesn't matter for the functions. I think I explained the important stuff in the code. Take a look
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <colorchat>
#include <fun>
#define PLUGIN "Give HP"
#define VERSION "1.0"
#define AUTHOR "Flicker"
new const Prefix[] = {"^3[^4GiveHP^3] "} // A prefix constant for all the messages
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
//Registering only say and say_team commands, because otherwise the admin will
//not be able to write different names and amounts of HP
register_clcmd("say","Say")
register_clcmd("say_team","Say")
}
public Say(id)
{
//The new stuff needed
new args[129], arg_cmd[11], arg2[32],arg3[32]
new name[32],target_name[32], target, num_hp
//Removing quotes and parsing the whole message args
read_args(args,128)
remove_quotes(args)
parse(args, arg_cmd,10, arg2,31, arg3,31) // end of that
num_hp = str_to_num(arg3) //Here we transform the third arg (the num) to a variable to use
target = cmd_target(id,arg2,0) //Here we get the cmd_target index, in target
//Getting the command writer's and command target's names
get_user_name(id,name,31)
get_user_name(target,target_name,31)
if(equali(arg_cmd, "/hp")) //The main check if the first arg, the arg_cmd, is /hp
{
//Here is the check for the admin flag for ban. The most important
//If the player hasn;t got the flag, the message will appear and we return
if(!(get_user_flags(id) & ADMIN_BAN))
{
ColorChat(id, NORMAL, "%s^1Only ^3admins^1 can use the command^4!", Prefix)
return
}
//If the command is writen, but the second arg (the target) is missing
//The following message will appear to say the amdin, that he should enter a name
//No that important check, but for info
if(equali(arg2, ""))
{
ColorChat(id, NORMAL, "%s^1You should enter some name^4!", Prefix)
return
}
//If in the server there is not a player, with the name added in the arg2
//Important check... The message will say that there is no such a player
if(!target)
{
ColorChat(id, NORMAL, "%s^1There is not a player wit this name^4:^3 %s^4!", Prefix, arg2)
return
}
//If the cmd is writen and there is a player with this name, but there is
//no amount of HP writen. The message will appear to say, and we return again
if(equali(arg3, ""))
{
ColorChat(id, NORMAL, "%s^1You should enter some amount of ^4HP^1 to give^4!", Prefix)
return
}
//If the amount of HP is 0 or less than 0
//Very important check, because otherwise, the admin could set negative amounts of
//of HP, which will cause errors
if(num_hp < 1)
{
ColorChat(id, NORMAL, "%s^1You cant give negative amount of ^4HP^1, or^3 0^4!", Prefix)
return
}
//And this check isn't important. It's about if the admin could give HP to himself
//In this case, he can't, but if you want your admins to can give themselves HP,
//just remove the check.
if(id == target)
{
ColorChat(id, NORMAL, "%s^1You cant give ^4HP^1 to yourself^4!", Prefix)
return
}
/* And in the following lines we set the HP if all the conditions above are OK*/
//set_user_health(id, arg3) // - In this case you set the player the amount writen in the command
set_user_health(target, get_user_health(target) + num_hp) //- In this case you add the amount, writen in the command, to the current player HP
//Colormessages to the admin and to the player he gave the HP
ColorChat(id, NORMAL, "%sYou gave ^4%d ^1HP to ^3%s", Prefix, num_hp, target_name)
ColorChat(target, NORMAL, "%s^3%s ^1gave you ^4%d^1 HP", Prefix, name, num_hp)
}
//I tink that's all!
}