Advertisement
Guest User

damage pack from weapon example

a guest
Nov 18th, 2016
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.92 KB | None | 0 0
  1. using GTA; // This is a reference that is needed! do not edit this
  2. using GTA.Native; // This is a reference that is needed! do not edit this
  3. using GTA.Math; // This is a reference that is needed! do not edit this
  4. using System; // This is a reference that is needed! do not edit this
  5. using System.Windows.Forms; // This is a reference that is needed! do not edit this
  6.  
  7. namespace scriptname
  8. {
  9.     public class scriptname : Script // declare Modname as a script
  10.     {
  11.         Ped player;
  12.        
  13.         public scriptname() // main function
  14.         {
  15.             Tick += this.OnTick;
  16.             KeyDown += this.OnKeyDown;
  17.             KeyUp += this.OnKeyUp;
  18.             Interval = 0;
  19.         }
  20.  
  21.         void OnTick(object sender, EventArgs e) // This is where most of your script goes
  22.         {
  23.             player = Game.Player.Character;
  24.            
  25.             if (Function.Call<bool>(Hash.IS_PED_ARMED, player, 1)) //if player is holding any melee weapon
  26.             {
  27.                 //you can get the position of your current weapon by using "getWeaponPosition()". For example:
  28.                
  29.                 //Here, we check if the distance between your weapon and a certain ped is less than or equal to 0.8 units.
  30.                 if (World.GetDistance(getWeaponPosition(), Ped.Position) <= 0.8f) //replace "Ped" with any ped you would like to apply the damage pack to.
  31.                 {
  32.                     //Apply damage pack to ped.
  33.                     Function.Call(Hash.APPLY_PED_DAMAGE_PACK, Ped, "HOSPITAL_0", 1.0f, 1.0f); //again, replace "Ped" with the ped you would like to apply the damage pack to.
  34.                 }
  35.             }
  36.         }
  37.        
  38.         Vector3 getWeaponPosition()
  39.         {
  40.             Entity currentWeapon = Function.Call<Entity>(Hash.GET_CURRENT_PED_WEAPON_ENTITY_INDEX, player); //get current weapon as an Entity
  41.            
  42.             return currentWeapon.Position; //return position of current weapon.
  43.         }
  44.  
  45.         void OnKeyDown(object sender, KeyEventArgs e)
  46.         {
  47.         }
  48.  
  49.         void OnKeyUp(object sender, KeyEventArgs e)
  50.         {
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement