nitanmarcel Posted December 23, 2015 Share Posted December 23, 2015 Hi! How to detect peds and then save them into a database. What I want to do is to target multiple targets and then kill them. Thanks and sorry if I can't tell more, I don't speak english so good Link to comment Share on other sites More sharing options...
AHK1221 Posted December 23, 2015 Share Posted December 23, 2015 If you use scripthookVDotNet then the code should be something like this: List<Ped> unluckyPeds = new List<Ped>;public yourClassName(){ this.OnKeyUp += onKeyUp;}private void onKeyUp(object sender, KeyEventArgs e){ if(e.KeyCode == Keys.N) { Ped onePed = Game.Player.GetTargetedEntity() as Ped; // Get The targeted ped if(onePed == null) return; // Check if targeted ped is not null unluckyPeds.Add(onePed); } if(e.KeyCode == Keys.M && unluckyPeds.Count > 0) { for(int i = 0; i < unluckyPeds.Count; i++) { unluckyPeds[i].Kill(); } }} Link to comment Share on other sites More sharing options...
nitanmarcel Posted December 24, 2015 Author Share Posted December 24, 2015 If you use scripthookVDotNet then the code should be something like this: List<Ped> unluckyPeds = new List<Ped>;public yourClassName(){ this.OnKeyUp += onKeyUp;}private void onKeyUp(object sender, KeyEventArgs e){ if(e.KeyCode == Keys.N) { Ped onePed = Game.Player.GetTargetedEntity() as Ped; // Get The targeted ped if(onePed == null) return; // Check if targeted ped is not null unluckyPeds.Add(onePed); } if(e.KeyCode == Keys.M && unluckyPeds.Count > 0) { for(int i = 0; i < unluckyPeds.Count; i++) { unluckyPeds[i].Kill(); } }} Thanks is working. But if I do that multiple times the mod is stopping working. Is a way to delete that list if the unluckyPeds.Count is bigger than 5? Thanks again! Link to comment Share on other sites More sharing options...
AHK1221 Posted December 24, 2015 Share Posted December 24, 2015 (edited) If you use scripthookVDotNet then the code should be something like this: List<Ped> unluckyPeds = new List<Ped>;public yourClassName(){ this.OnKeyUp += onKeyUp;}private void onKeyUp(object sender, KeyEventArgs e){ if(e.KeyCode == Keys.N) { Ped onePed = Game.Player.GetTargetedEntity() as Ped; // Get The targeted ped if(onePed == null) return; // Check if targeted ped is not null unluckyPeds.Add(onePed); } if(e.KeyCode == Keys.M && unluckyPeds.Count > 0) { for(int i = 0; i < unluckyPeds.Count; i++) { unluckyPeds[i].Kill(); } }} Thanks is working. But if I do that multiple times the mod is stopping working. Is a way to delete that list if the unluckyPeds.Count is bigger than 5? Thanks again! Just put this in the keyDown event: if (e.KeyCode == Keys.X) { if (unluckyPeds.Count > 5) { //for (int i = 0; i < unluckyPeds.Count; i++) I have doubt about this method //{ But the below one should work // unluckyPeds.RemoveAt(i); //} unluckyPeds.RemoveAt(0); unluckyPeds.RemoveAt(1); unluckyPeds.RemoveAt(2); unluckyPeds.RemoveAt(3); unluckyPeds.RemoveAt(4); } } Or if you want it to happen automatically: public yourClass(){ this.Tick += onTick; this.KeyDown += onKeyDown;}private void onTick(object sender, EventArgs e){ if (unluckyPeds.Count > 5) { //for (int i = 0; i < unluckyPeds.Count; i++) //{ // unluckyPeds.RemoveAt(i); //} unluckyPeds.RemoveAt(0); unluckyPeds.RemoveAt(1); unluckyPeds.RemoveAt(2); unluckyPeds.RemoveAt(3); unluckyPeds.RemoveAt(4); }} Edited December 24, 2015 by AHK1221 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