Jump to content

[SOLVED] How to find out if you're aiming at an NPC? [C++ Scripting]


HughJanus
 Share

Recommended Posts

Hey folks,

 

does anyone know how to find out if the player is pointing at an NPC?

I would like the player to do less damage to NPCs (but not creatures), so I would like to lower the weapon damage modifier when pointing at an NPC.

Increasing NPCs health I already tried, but it seems to not have the exact same effect.

 

BR

HJ

Edited by HughJanus
typos, set to "SOLVED"
Link to comment
Share on other sites

Found some stuff in the nativeDB - here are the methods I needed:

 

 

And here's the code I ended up using:

Player player = PLAYER::PLAYER_ID();
if (PLAYER::IS_PLAYER_TARGETTING_ANYTHING(player) || PLAYER::IS_PLAYER_FREE_AIMING(player))
{
	Ped playertarget;
	if (PLAYER::GET_PLAYER_TARGET_ENTITY(player, &playertarget) || PLAYER::GET_ENTITY_PLAYER_IS_FREE_AIMING_AT(player, &playertarget))
	{
		if (!PED::IS_PED_HUMAN(playertarget)) PLAYER::SET_PLAYER_WEAPON_DAMAGE_MODIFIER(player, 1.0);
	} else PLAYER::SET_PLAYER_WEAPON_DAMAGE_MODIFIER(player, 0.05);
}

 

 

Note: What is the difference between lowering the weapon damage modifier and giving peds more health? - I noticed that, for example, if you shoot someone near the neck and the "bleeding and running" task triggers, the ped usually runs for about 10 seconds then lies down to die. This stays the same even if the peds health is set to something as high as 9000. But if you set the damage modifier, the amount of health drained by blood loss will lower too -> peds will run around bleeding for way more than 10 seconds if your damage multiplier is low.

 

 

 

Edited by HughJanus
typos, removed code which wasnt working properly
  • Like 1
Link to comment
Share on other sites

On 1/11/2020 at 7:10 AM, HughJanus said:

Note: What is the difference between lowering the weapon damage modifier and giving peds more health? - I noticed that, for example, if you shoot someone near the neck and the "bleeding and running" task triggers, the ped usually runs for about 10 seconds then lies down to die. This stays the same even if the peds health is set to something as high as 9000. But if you set the damage modifier, the amount of health drained by blood loss will lower too -> peds will run around bleeding for way more than 10 seconds if your damage multiplier is low.

 

 

I suppose the difference is quite simple where one deals more/less damage and the other means the ped has more health to begin with which might delay hitting a threshold to trigger specific behavior.

Link to comment
Share on other sites

5 hours ago, LMS said:

 

I suppose the difference is quite simple where one deals more/less damage and the other means the ped has more health to begin with which might delay hitting a threshold to trigger specific behavior.

 

Yeah, that was my conclusion in the end too.

I first couldnt believe it, because I didnt think that burning or bleeding effects would be affected by player damage modifiers (but more like "do x damage" or "do x% of max_health damage").

Thanks for your continuing input!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...