Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

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

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

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

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

    2. Support

    3. Suggestions

C# - How do i detect HeadShots ?


Charles_Manson
 Share

Recommended Posts

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 ?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 Guest
Link to comment
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
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

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