Quantcast

Jump to content

» «
Photo

[C#]Is It Possible To Make A HEADSHOT Mod?

13 replies to this topic
Rugz007
  • Rugz007

    Scripters ... roll out !

  • Members
  • Joined: 19 Apr 2014
  • India

#1

Posted 13 May 2014 - 04:50 PM

Yeah Which Gives You Points Every Head Shot And You HAve Levels For It Like:

 

1) Begginer Shooter

.

.

.

7) Head Killer

 

 

Is It Possible....if It IS PLz Send Me A Source Code For It ^^

  • Aniton likes this

Wiebrendh
  • Wiebrendh

    Beginning C# programmer

  • Members
  • Joined: 22 Mar 2014
  • Netherlands

#2

Posted 13 May 2014 - 05:09 PM

Well, then u have to check when the player kills a ped. Then u add a certain amount of XP and when he reaches a specific amount he will level up, and then save it into a file or something. You can make this by yourselfe.


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#3

Posted 13 May 2014 - 06:40 PM Edited by LordOfTheBongs, 13 May 2014 - 07:55 PM.

Well, then u have to check when the player kills a ped. Then u add a certain amount of XP and when he reaches a specific amount he will level up, and then save it into a file or something. You can make this by yourselfe.

u have to determine the last bone hit, ill provide u code... for a class that adds damage events to peds...

 

Compiled code: https://dl.dropboxus...shotExample.rar (untested)

namespace DamageHelper
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms;
    using System.IO;
    using GTA;
    using GTA.Native;

    public delegate void VitalsChangedHandler(object sender, VitalsChangedEventArgs e);

    public enum VitalsType
    {
        Health,
        Armor
    }

    public class VitalsChangedEventArgs : EventArgs
    {
        public readonly VitalsType VitalsType;
        public readonly int OldValue, NewValue;
        public readonly Int32 BoneDamaged;
        public readonly bool PlayerDamaged;
        public readonly string Description;
        public readonly MonitoredPed MonitoredPed;
        public readonly bool Lethal;

        public VitalsChangedEventArgs(MonitoredPed mp, VitalsType vitalsType, int oldVal, int newVal, Int32 boneDamaged, bool playerDamaged, string description)
        {
            MonitoredPed = mp;
            VitalsType = vitalsType;
            OldValue = oldVal; NewValue = newVal;
            BoneDamaged = boneDamaged;
            PlayerDamaged = playerDamaged;
            Description = description;
            Lethal = description != "punched or kicked";
        }
    }

    public class VitalsMonitor
    {
        public event VitalsChangedHandler VitalsImprovement;
        public event VitalsChangedHandler VitalsWorsened;

        private int _health;
        public int Health
        {
            get { return _health; }
            set
            {
                Int32 iBone = GetBone();
                string description = GetDescription();
                bool playerDamaged = PlayerDamagedPed();

                Function.Call("CLEAR_CHAR_LAST_DAMAGE_ENTITY", _monitoredPed.Character);
                Function.Call("CLEAR_CHAR_LAST_DAMAGE_BONE", _monitoredPed.Character);

                VitalsChangedEventArgs e = new VitalsChangedEventArgs(_monitoredPed, VitalsType.Health, _health, value, iBone, playerDamaged, description);

                bool raiseIncreaseEvent = _health < value,
                     raiseDecreaseEvent = _health > value;

                _health = value;

                if (raiseIncreaseEvent)
                {
                    OnVitalsImprovement(e);
                }
                else if (raiseDecreaseEvent)
                {
                    OnVitalsWorsened(e);
                }
            }
        }

        private int _armor;
        public int Armor
        {
            get { return _armor; }
            set
            {
                Int32 iBone = GetBone();
                string description = GetDescription();
                bool playerDamaged = PlayerDamagedPed();

                Function.Call("CLEAR_CHAR_LAST_DAMAGE_ENTITY", _monitoredPed.Character);
                Function.Call("CLEAR_CHAR_LAST_DAMAGE_BONE", _monitoredPed.Character);

                VitalsChangedEventArgs e = new VitalsChangedEventArgs(_monitoredPed, VitalsType.Armor, _armor, value, iBone, playerDamaged, description);

                bool raiseIncreaseEvent = _armor < value,
                     raiseDecreaseEvent = _armor > value;

                _armor = value;

                if (raiseIncreaseEvent)
                {
                    OnVitalsImprovement(e);
                }
                else if (raiseDecreaseEvent)
                {
                    OnVitalsWorsened(e);
                }
            }
        }

        private MonitoredPed _monitoredPed;
        public MonitoredPed MonitoredPed
        {
            get { return _monitoredPed; }
        }

        private bool PlayerDamagedPed()
        {
            WeaponSlot[] weaponSlots = new WeaponSlot[]
            {
                WeaponSlot.Unarmed,
                WeaponSlot.Melee,
                WeaponSlot.Handgun,
                WeaponSlot.Shotgun,
                WeaponSlot.SMG,
                WeaponSlot.Rifle,
                WeaponSlot.Sniper,
                WeaponSlot.Heavy,
                WeaponSlot.Special,
                WeaponSlot.Thrown
            };

            foreach (WeaponSlot slot in weaponSlots)
            {
                if (_monitoredPed.Character.HasBeenDamagedBy(Game.LocalPlayer.Character.Weapons.inSlot(slot)))
                {
                    return true;
                }
            }

            return false;
        }
        private string GetDescription()
        {
            return Function.Call<bool>("HAS_CHAR_BEEN_DAMAGED_BY_WEAPON", _monitoredPed.Character, Convert.ToInt32(Weapon.Unarmed)) ? "punched or kicked" :
                      Function.Call<bool>("HAS_CHAR_BEEN_DAMAGED_BY_WEAPON", _monitoredPed.Character, Convert.ToInt32(Weapon.Melee_Knife)) ? "stabbed" :
                      Function.Call<bool>("HAS_CHAR_BEEN_DAMAGED_BY_WEAPON", _monitoredPed.Character, Convert.ToInt32(Weapon.Melee_BaseballBat)) ? "struck with a bat" :
                      Function.Call<bool>("HAS_CHAR_BEEN_DAMAGED_BY_WEAPON", _monitoredPed.Character, Convert.ToInt32(Weapon.Melee_PoolCue)) ? "struck with a pool cue" :
                      "shot";
        }
        private int GetBone()
        {
            Pointer BonePointer = typeof(Int32);
            Function.Call("GET_CHAR_LAST_DAMAGE_BONE", _monitoredPed.Character, BonePointer);
            return Convert.ToInt32(BonePointer.Value);
        }

        public VitalsMonitor(MonitoredPed ped)
        {
            _monitoredPed = ped;
            _health = _monitoredPed.Character.Health;
            _armor = _monitoredPed.Character.Armor;
        }

        public void SetCharacterVitalNoEvent(VitalsType type, int setValue)
        {
            if (type == VitalsType.Health)
            {
                _monitoredPed.Character.Health = _health = setValue;
            }
            else
            {
                _monitoredPed.Character.Armor = _armor = setValue;
            }
        }

        protected virtual void OnVitalsImprovement(VitalsChangedEventArgs e)
        {
            if (VitalsImprovement != null)
                VitalsImprovement(this, e);
        }
        protected virtual void OnVitalsWorsened(VitalsChangedEventArgs e)
        {
            if (VitalsWorsened != null)
                VitalsWorsened(this, e);
        }
    }

    public class MonitoredPed
    {
        private int _interval;
        public int Interval
        {
            get { return _interval; }
            set { _interval = value; }
        }

        private bool _isDisposed;
        public bool IsDisposed
        {
            get { return _isDisposed; }
        }

        private VitalsMonitor _vitalMonitor;
        public VitalsMonitor VitalsMonitor
        {
            get { return _vitalMonitor; }
        }

        private Ped _character;
        public Ped Character
        {
            get { return _character; }
        }

        private Script script;
        private int checkedGameTime;
        private bool isChecking;

        public MonitoredPed(Script s, Ped ped, int interval = 0, bool startNow = true)
        {
            script = s;
            s.Tick += VitalsTick;

            _character = ped;
            _vitalMonitor = new VitalsMonitor(this);
            isChecking = startNow;
            _interval = interval;
        }

        public void Dispose()
        {
            _isDisposed = true;
        }
        public void StartMonitor()
        {
            isChecking = true;
        }
        public void StopMonitor()
        {
            isChecking = false;
        }

        private void VitalsTick(object sender, EventArgs e)
        {
            if (_isDisposed || !Game.Exists(_character))
            {
                _isDisposed = true;
                script.Tick -= VitalsTick;
                return;
            }

            if (isChecking)
            {
                bool zeroInterval = _interval < 1;
                int currentTime = zeroInterval ? 0 : Game.GameTime;
                if (zeroInterval || currentTime - checkedGameTime > _interval)
                {
                    checkedGameTime = currentTime;
                    _vitalMonitor.Health = _character.Health;
                    _vitalMonitor.Armor = _character.Armor;
                }
            }
        }
    }
}

u can use the code or just review it to figure out how to get bones u damaged

 

To use, u can paste this code into a project or compile it yourself and use as a dll reference in another script. You would install the dll in the gtaiv root directory (where GTAIV.exe, scripthookdotnet.asi and scripthook.dll is).

 

to use this code u just create an instance of the Monitored Ped class using the ped u want to track and then hook your event and when he gets damaged u can check which bone was hit

 

here is the code being used...

namespace PlayerHeadshot
{
    using System;
    using GTA;
    using DamageHelper;//above code would need to be compiled and installed
 
    public class Main : Script
    {
        private MonitoredPed targetedPed;
 
        public Main()
        {
            Tick += AimTick;
        }
 
        private void AimTick(object sender, EventArgs e)
        {
            Ped ped = Game.LocalPlayer.GetTargetedPed();
            if (!Game.Exists(ped)) return;
 
            bool isNull = targetedPed == null;
            if (isNull || targetedPed.Character != ped)
            {
                if (!isNull && !targetedPed.IsDisposed) targetedPed.Dispose();
                targetedPed = new MonitoredPed(this, ped);
                targetedPed.VitalsMonitor.VitalsWorsened += (o, ev) =>
                {
                    if (ev.BoneDamaged == (int)Bone.Head) Game.DisplayText("HEADSHOT");
                };
            }
        }
    }
}

julionib
  • julionib

    Coder

  • Members
  • Joined: 13 Sep 2012
  • Brazil

#4

Posted 13 May 2014 - 08:34 PM

you also can use Integer statistics:

http://www.gtamoddin...le=GET_INT_STAT

and directly detect when you perform a headshot and game understand that was a headshot (int stat 289)

http://www.gtamoddin...tistics_(GTA_4)


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#5

Posted 13 May 2014 - 08:43 PM

you also can use Integer statistics:

http://www.gtamoddin...le=GET_INT_STAT

and directly detect when you perform a headshot and game understand that was a headshot (int stat 289)

http://www.gtamoddin...tistics_(GTA_4)

that's no fun lol


julionib
  • julionib

    Coder

  • Members
  • Joined: 13 Sep 2012
  • Brazil

#6

Posted 13 May 2014 - 09:50 PM

^^ why?

dependign on what he plans to do yoru method is the best choice because he probably will know the damaged ped, using Int stat you would need to search and find who was killed to make a effect on this ped or something else related to him


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#7

Posted 13 May 2014 - 11:33 PM Edited by LordOfTheBongs, 13 May 2014 - 11:34 PM.

^^ why?

dependign on what he plans to do yoru method is the best choice because he probably will know the damaged ped, using Int stat you would need to search and find who was killed to make a effect on this ped or something else related to him

it was a joke... since i posted like 1000 lines and u can accomplish in 1 line with your method :facedesk:

 

i just took code from my hardcore mode mod but that does more so the classes i use are helpful


julionib
  • julionib

    Coder

  • Members
  • Joined: 13 Sep 2012
  • Brazil

#8

Posted 13 May 2014 - 11:53 PM

yep, but your code probably is the best choice for what he plans to make that probably will use the damaged ped :)


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#9

Posted 13 May 2014 - 11:59 PM

yeah hopefully it helps him, i compiled so he can test, at least he will see the natives needed to handle damage with ped... but yeah it was funny, i never knew i could check the statistics and i originally made this code to detect headshots :facedesk: :lol:


Aniton
  • Aniton

    Player Hater

  • Members
  • Joined: 13 May 2014
  • India

#10

Posted 14 May 2014 - 07:03 AM

Hehe So Man Hows Your Transformers Mod GOing On ?


Aniton
  • Aniton

    Player Hater

  • Members
  • Joined: 13 May 2014
  • India

#11

Posted 14 May 2014 - 07:17 AM

Hey Lord Of Bongs Cant We Just Mix The 2 Codes And Complie

 

(Sorry But I Am New Here)


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#12

Posted 14 May 2014 - 01:55 PM

Hey Lord Of Bongs Cant We Just Mix The 2 Codes And Complie

 

(Sorry But I Am New Here)

yes u can put all the code inside 1 namespace and compile...

 

i provided a link to the .net file where that is what i did... download the file at the top of the post and i already combined ;)


Rugz007
  • Rugz007

    Scripters ... roll out !

  • Members
  • Joined: 19 Apr 2014
  • India

#13

Posted 14 May 2014 - 02:17 PM

Thaknz man u r gr8ful can you name some of your mods?

LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#14

Posted 14 May 2014 - 08:23 PM

Thaknz man u r gr8ful can you name some of your mods?

well i dont have any mods i released online... i did in the past but i realized i dont like sharing with the public... just people that i talk to and if they are cool and not some whining noob that says i suck because rockstar designed gta a certain way.

 

i have written maybe 100 mods for gta, too many to name ;)

 

but if u think of something u want, just post in the request topic and if i wrote it ill post it ;)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users