to get the aiming player's HP?

YEA
✔️ HL Verified
Joined
Oct 31, 2014
Messages
201
Best answers
0
Location
CHINA
May I ask a question here? (I'm sorry for I have no Steam ID, so I'm afraid that I can't send the post to that 'help' forum:rolleyes:)

it's this: I'm aiming the player, and I want to get the player's HP, but the plugin has appeared a wrong...It's only working at I'm attacking the target in beam weapons:-/

Code:
/* AMX MOD X 1.8.1*/

#include <amxmodx>
#include <fakemeta>

new g_Aim_HudId, cvar_x, cvar_y

public plugin_init()
{
	
	register_forward(FM_TraceLine, "fwTraceLinePost", 1)
	
	g_Aim_HudId = CreateHudSyncObj(8)
	
	cvar_x = register_cvar("amx_aim_x", "-1.0")
	cvar_y = register_cvar("amx_aim_y", "0.6")
}

public fwTraceLinePost(Float:fStart[3], Float:fEnd[3], iConditions, id, iPtr)
{
	if(!is_user_alive(id))
	return
	
	new iEnemy = get_tr2(iPtr, TR_pHit)
	if(!is_user_alive(iEnemy))
	return
	
	new Float:fHealth
	pev(iEnemy, pev_health, fHealth)
	
	set_hudmessage(250, 0, 0, get_pcvar_float(cvar_x), get_pcvar_float(cvar_y), 0, 0.1, 0.1)
	ShowSyncHudMsg(id, g_Aim_HudId, "%d", floatround(fHealth))
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ ansicpg936\\ deff0{\\ fonttbl{\\ f0\\ fnil\\ fcharset134 Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang2052\\ f0\\ fs16 \n\\ par }
*/
 
Last edited:
NOT IN THE MANGA™
★ Black Lounger ★
✔️ HL Verified
🚂 Steam Linked
💻 Oldtimer
Joined
Jan 5, 2008
Messages
3,276
Best answers
0
Location
Lithuania
I don't think TraceLine is called all the time (more like when certain conditions are met, like when you're attacking?), so you probably need to hook PreThink/PostThink and then do the aim check there. Did you try get_user_aiming()?

I wonder if there's a radar-related game message in ESF from which you can extract the target's ID? Probably not, but could be worth checking. I'll see what I can do later when I get back from work.
 
Last edited:
YEA
✔️ HL Verified
Joined
Oct 31, 2014
Messages
201
Best answers
0
Location
CHINA
Thank u for ur answer, and I've just tried to use 'PostThink'get all the time of the target, however, I got the fail again:-/
it's this:
[ 2] get_aiming_HP unknown unknown targetHP.amxx running
Code:
public client_PostThink(Float:fStart[3], Float:fEnd[3], iConditions, id, iPtr)
{
	if(!is_user_alive(id))
	return
	
	new iEnemy = get_tr2(iPtr, TR_pHit)
	if(!is_user_alive(iEnemy))
	return
	
	new Float:fHealth
	pev(iEnemy, pev_health, fHealth)
	
	set_hudmessage(250, 0, 0, get_pcvar_float(cvar_x), get_pcvar_float(cvar_y), 0, 0.1, 0.1, 20.0)
	ShowSyncHudMsg(id, g_Aim_HudId, "%d", floatround(fHealth))
}
it's so late I must go to sleep...waiting for your redress of the code xD
 
Last edited:
NOT IN THE MANGA™
★ Black Lounger ★
✔️ HL Verified
🚂 Steam Linked
💻 Oldtimer
Joined
Jan 5, 2008
Messages
3,276
Best answers
0
Location
Lithuania
Can't test it with players at the moment, doesn't work with bots though.

Give this a try if you can ask another player to help you.

PHP:
#include <amxmodx>
#include <engine>

public client_PostThink(plr)
{
	if (!is_user_alive(plr))
		return;
	
	new target, body;
	get_user_aiming(plr, target, body);
	
	if (is_user_alive(target))
	{		
		set_hudmessage(255, 255, 255, -1.0, 0.45, _, _, 0.1, _, _, 1);
		show_hudmessage(plr, "%d", get_user_health(target));
	}
}
 

Users who are viewing this thread

Top Bottom