Get where a bullet went?
-
Hello I have a few questions:
- Does anyone know how to get where a bullet went and if it hit a ped?
-
@LeeC2202 @Frazzlee @stillhere @aimless @FoxtrotDelta @Global-Moderators @administrators
-
@NotCrunchyTaco Can you please not use the administrators and moderators tags for modding subjects please, those are for administrator and moderator matters.
-
@LeeC2202 Oh ok sorry
-
I have not tested this but,
to get where a bullet hit:
Vector3 hitPos;
OutputArgument hitOutput = new OutputArgument();
bool bulletHasHit = Function.Call<bool>(Hash.GET_PED_LAST_WEAPON_IMPACT_COORD, hitPos);
if (bulletHasHit) //if bullet hit something
{
hitPos = hitOutput.GetResult<Vector3>(); //get hit position//get closest ped:
Ped p = World.GetClosestPed(hitPos, 1.0f);bool pedIsHit = Function.Call<bool>(Hash.HAS_ENTITY_BEEN_DAMAGED_BY_ENTITY, p, Game.Player.Character, 1); //has ped been damaged by the player character
if (pedIsHit)
{
//do something
//you might have to use CLEAR_ENTITY_LAST_DAMAGE_ENTITY here.
}
}
-
@stillhere Thanks! I need it for yet again another mod I am working on
-
@NotCrunchyTaco One quick thing I need this for a dead entity not alive it says damaged by entity can a dead ped take damage?
-
@NotCrunchyTaco I'm not sure, you can test it. Or instead of "if (pedIsHit)", you can try "if (!p.IsAlive)" and hope that the closest ped to the hitPos is the ped that was hit
-
@stillhere Okay one other thing for the GET_PED_LAST_WEAPON_IMPACT_COORD the hitPos has an error why?
-
@NotCrunchyTaco oh sorry it should be this instead:
bool bulletHasHit = Function.Call<bool>(Hash.GET_PED_LAST_WEAPON_IMPACT_COORD, hitOutput);
-
@stillhere Ah, Thank you. I will try it soon and get back you whether it works or not. I really hope it works, It's an amazing mod idea.
-
@Frazzlee Well I needed help
-
@stillhere Ugh it crashes my game I guess I cannot use it
-
@NotCrunchyTaco okay there is another way to do it with raycasting! I can share it to you later when I'm on my PC if no one else replies.
-
@stillhere Ok do you have skype or anything?
-
@NotCrunchyTaco I never go on skype man, you can find me here though, I check pretty much everyday
-
@stillhere Ok
-
@NotCrunchyTaco I'll send you a PM with the code later bro
-
@stillhere Ok thanks