i had created a plugin that give hp to player to whom u are spectating by typing "pray" but i had one problem when i say pray to targets if i change my spectating user than plugin also change the target and it give the health to targets2.!!!
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <ColorChat>
#include <fun>
#define PLUGIN "Pray Plugin"
#define VERSION "1.0"
#define AUTHOR "XxXPeRtS"
#define PREFIX "[ZOF 'X]"
new targets_hp
new nHp_max
new health_max
new bool:prayed[33];
new pcvar_hp;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_clcmd("say pray", "cmd_GiveHp");
register_clcmd("pray", "cmd_GiveHp");
health_max = register_cvar("target_max_hp", "100")
pcvar_hp = register_cvar("amx_pray_hp", "20");
register_event("HLTV", "event_NewRound", "a", "1=0", "2=0");
}
public event_NewRound()
{
for(new i=1; i < 33; i++)
{
prayed[i] = false;
}
}
public client_putinserver(id)
{
prayed[id] = false;
}
public cmd_GiveHp(id)
{
new iSpecMode = entity_get_int(id, EV_INT_iuser1);
new player = entity_get_int(id, EV_INT_iuser2);
new name2[32], name[32];
get_user_name(player, name2, charsmax(name2));
get_user_name(id, name, charsmax(name));
if(is_user_alive(id))
{
ColorChat(id, GREEN, "%s ^x01Play or ^x03Pray For Players..xD.!!", PREFIX);
return PLUGIN_CONTINUE;
}
if(prayed[id])
{
ColorChat(id, GREEN, "%s ^x01You Had Already ^x03Prayed This Round..!!", PREFIX);
return PLUGIN_CONTINUE;
}
if(iSpecMode == 0 || iSpecMode == 3)
{
ColorChat(id, GREEN, "%s ^x01You are not a ^x03Spectating a player.!!", PREFIX);
return PLUGIN_CONTINUE;
}
else
{
ColorChat(0, GREEN, "%s ^x03%s ^x04Has Just Prayed For ^x03%s", PREFIX, name, name2);
set_task(2.50, "Praying", id);
}
return PLUGIN_CONTINUE;
}
public Praying(id)
{
new iSpec = entity_get_int(id, EV_INT_iuser2);
new player = entity_get_int(id, EV_INT_iuser2);
new name2[32], name[32];
get_user_name(player, name2, charsmax(name2));
get_user_name(id, name, charsmax(name));
nHp_max = get_pcvar_num (health_max);
targets_hp = get_user_health(player);
nHp_max = get_pcvar_num (health_max);
if(targets_hp == nHp_max)
{
ColorChat(id, GREEN, "%s ^x01Praying Failed. ^x03%s Already Has 100HP ^x04 Please Pray Some Else.!!", PREFIX, name2);
return PLUGIN_CONTINUE;
}
if(!is_user_alive(player))
{
ColorChat(id, GREEN, "%s ^x01 Aww.! %s Has Died Before Your Prayer Was Completed..!", PREFIX, name2)
prayed[id] = true;
return PLUGIN_CONTINUE;
}
set_user_health(iSpec, min((get_user_health(iSpec)+get_pcvar_num(pcvar_hp)), 100))
prayed[id] = true;
return PLUGIN_HANDLED;
}