Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. Gameplay
      2. Missions
      3. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Arena War
      2. After Hours
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA Next

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. News

    2. Forum Support

    3. Site Suggestions

Charles_Manson

C# - How do i detect HeadShots ?

Recommended Posts

Charles_Manson

Anyway to detect a headshot ?

thanks in advance

Share this post


Link to post
Share on other sites
Jitnaught

Try these natives:

 

HAS_ENTITY_BEEN_DAMAGED_BY_ENTITY

GET_PED_LAST_DAMAGE_BONE

Share this post


Link to post
Share on other sites
Charles_Manson
On 12/22/2018 at 11:44 AM, Jitnaught said:

Try these natives:

 

HAS_ENTITY_BEEN_DAMAGED_BY_ENTITY

GET_PED_LAST_DAMAGE_BONE

thanks 

also how to detect Whether player picked up money or not ?

Share this post


Link to post
Share on other sites
Jitnaught

If you created the pickup, you can use this:

if (myPickup.IsCollected) { }

 

And the native for that is:

OBJECT::HAS_PICKUP_BEEN_COLLECTED

 

If you didn't create the pickup, then I'm not sure.

Edited by Jitnaught
c# info

Share this post


Link to post
Share on other sites
LeeC2202

This is what I use for money collection in my addon peds. I have just pulled out all the relevant code into a standalone project... which seems to work. If you saw what I posted here earlier, sorry, that just turned into a mess.

 

I can't say if this is the best way, or even the right way but it seems to work okay.

 

Edit: I probably should have said, this is a system I use in my Players Extended mod, that gives addon peds a money system to buy things and pay for activities. With the normal players, you might have access to more money related info. At the very least, you could monitor the player's money changing and if it coincides with a pickup occuring, you will know how much they have picked up.

 

using System;
using System.Collections.Generic;

using GTA;
using GTA.Math;
using GTA.Native;
using System.Linq;

namespace MoneyPickups
{
    public struct MoneyPickup
    {
        public MoneyPickup(Prop prop, Vector3 position)
        {
            MoneyProp = prop;
            Position = position;
        }

        public Prop MoneyProp;
        public Vector3 Position;
    }

    public class cMoneyPickups : Script
    {
        private Ped PlayerPed;

        private List<int> MoneyHashes;
        private List<string> MoneyPropNames = new List<string>() { "prop_ld_wallet_01", "prop_ld_wallet_01_s", "prop_ld_wallet_02", "prop_ld_wallet_pickup", "prop_cash_pile_01", "prop_cash_pile_02" };
        private Dictionary<int, MoneyPickup> DroppedCash = new Dictionary<int, MoneyPickup>();

        public cMoneyPickups()
        {
            Tick += onTick;
            Aborted += onAborted;

            Interval = 0;
            CreateMoneyHashes();
        }

        private void CreateMoneyHashes()
        {
            MoneyHashes = new List<int>();

            for (int i = 0; i < MoneyPropNames.Count; i++)
            {
                MoneyHashes.Add(Function.Call<int>(Hash.GET_HASH_KEY, MoneyPropNames[i]));
            }
        }

        private void onTick(object sender, EventArgs e)
        {
            // Exits from the loop if the game is loading
            if (Game.IsLoading) return;

            // A collection of lines that process the player's current state, along with the player's vehicle
            if (PlayerPed != Game.Player.Character) PlayerPed = Game.Player.Character;

            DoCashPickupWatch();
            WatchForMoneyCollection();

        }

        private void DoCashPickupWatch()
        {
            for (int i = 0; i < MoneyHashes.Count; i++)
            {
                if (DoesObjectExist(PlayerPed.Position, 5f, MoneyHashes[i]))
                {
                    Prop money = GetClosestObjectofType<Prop>(PlayerPed.Position, 5f, MoneyHashes[i], false);

                    if (!DroppedCash.ContainsKey(money.Handle))
                    {
                        DroppedCash.Add(money.Handle, new MoneyPickup(money, money.Position));
                    }
                }
            }
        }

        private void WatchForMoneyCollection()
        {
            foreach (int key in DroppedCash.Keys.ToList())
            {
                if (!DroppedCash[key].MoneyProp.Exists())
                {
                    // This is to make sure we're not given the cash for missed pickups that just stop existing. Not sure on the 2f range yet
                    // though, will have to watch for any collections that get missed
                    if (World.GetDistance(DroppedCash[key].Position, PlayerPed.Position) < 2f)
                    {
                        UI.Notify("Picked up: " + key.ToString());
                        DroppedCash.Remove(key);
                    }
                }
            }
        }

        private bool DoesObjectExist(Vector3 position, float radius, int hash)
        {
            return Function.Call<bool>(Hash.DOES_OBJECT_OF_TYPE_EXIST_AT_COORDS, position.X, position.Y, position.Z, radius, hash, 0);
        }

        private T GetClosestObjectofType<T>(Vector3 position, float radius, int hash, bool isMission)
        {
            return Function.Call<T>(Hash.GET_CLOSEST_OBJECT_OF_TYPE, position.X, position.Y, position.Z, radius, hash, isMission, 0, 0);
        }

        private void onAborted(object sender, EventArgs e)
        {
			// Should do cleanup of any props held in the dictionary here...
        }
    }
}

 

Edited by LeeC2202

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • 2 Users Currently Viewing
    0 Members, 0 Anonymous, 2 Guests

×

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.