ShadowCoderKing Posted May 5, 2017 Share Posted May 5, 2017 hi im new at this and i have a problem, i need to remove a spawned ped ingame if he is dead i dont know the code what comes next please help if you can i really appreciate it if (e.KeyCode == Keys.U) { Ped player = Game.Player.Character; GTA.Math.Vector3 spawnLoc = player.Position + (player.ForwardVector * 20); string model_name = "mp_m_freemode_01"; Ped HostilePed = GTA.World.CreatePed(model_name, spawnLoc); HostilePed.Task.ClearAllImmediately(); HostilePed.Weapons.Give(GTA.Native.WeaponHash.SMG, 1, true, true); HostilePed.Task.FightAgainst(Game.Player.Character); HostilePed.Armor = 40; { if (HostilePed.IsDead) { I dont know the code to remove him } } } }} Link to comment Share on other sites More sharing options...
sollaholla Posted May 6, 2017 Share Posted May 6, 2017 It's good to see you're trying to learn! Here's a few things that I think would make this program work the way you want it to: 1. Start by creating a Tick event listener: You need to subscribe a method to the Script.Tick event in the constructor. Start by writing this code: // This is the constructor.public MyClassNameHere (){ // Same as the KeyUp event, the OnTick method will be listening to the "Tick" event called // from the "Script" class. Tick += OnTick;}private void OnTick(object sender, EventArgs e){ } 2. Now let's keep a variable of the Ped somewhere in our class, so that we can do things with it later. // This goes within the class, and outside of any methods.public Ped HostilePed;// This is psuedo-code so you shouldn't copy paste this directly.// In your OnKeyUp (or your method that listens to the KeyUp event), at the location where you create the ped, replace that line with this.// What we're doing is storing the ped in a variable for later use.HostilePed = GTA.World.CreatePed(model_name, spawnLoc); 3. Inside of the OnTick method, we're going to remove the ped once it's considered dead by the game. private void OnTick(object sender, EventArgs e){ // First we need to make sure the hostile ped exists and is not null. // And then if that's true, we want to delete it once it dies. if (Entity.Exists(HostilePed) && HostilePed.IsDead) { HostilePed.Delete(); }} 4. Now you can remove this piece of code from the KeyUp listener: // Remove this.{ if (HostilePed.IsDead) { I dont know the code to remove him }} 5. It would also be smart to replace the first if statement in the KeyUp listener with this, to avoid any stray peds: if (e.KeyCode == Keys.U && !Entity.Exists(HostilePed)){ // Your other code.} That should be it! Once you go in-game and press the U key, an attacking ped should spawn, and once the ped is killed, it will be deleted, and then you can spawn another one the same way! jedijosh920 1 Link to comment Share on other sites More sharing options...
ShadowCoderKing Posted May 6, 2017 Author Share Posted May 6, 2017 thank you very much i really appreciate your help sollaholla 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now