Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • ragnoroker: Brand new unique server just released! - Awesome Community - [link]
      October 14, 2019, 11:11:32 AM
    • ragnoroker: Brand new unique server just released! - Awesome Community - [link]
      October 14, 2019, 11:11:28 AM
    • ragnoroker: Brand new unique server just released! - Awesome Community - [link]
      October 14, 2019, 11:11:23 AM
    • marquise:[link]
      October 11, 2019, 12:24:21 PM
    • marquise: hey guys try autoscape.org [link]
      October 11, 2019, 12:19:08 PM
    • Rash: is this site still ded
      October 08, 2019, 07:54:22 PM
    • The Meek: Just Uploaded New Server ~Phusion~
      October 01, 2019, 03:30:31 AM
    • ragnoroker: Pre-EOC New server just dropped today! Come check it out :) - [link]
      September 27, 2019, 08:43:43 PM
    • ragnoroker: Pre-EOC New server just dropped today! Come check it out :) - [link]
      September 27, 2019, 08:43:40 PM
    • ragnoroker: Pre-EOC New server just dropped today! Come check it out :) - [link]
      September 27, 2019, 08:43:33 PM
    • PavSwag: try autoscape,0rg today i will personally help you get RICH and well KNOWN - pav
      September 26, 2019, 09:02:13 AM
    • PavSwag: try autoscape,0rg today i will personally help you get RICH and well KNOWN - pav
      September 26, 2019, 08:52:25 AM
    • ragnoroker: Brand new server! Join today - Good Eco/Nice Players - [link]
      September 25, 2019, 08:59:33 AM
    • ragnoroker: Brand new server! Join today - Good Eco/Nice Players - [link]
      September 25, 2019, 08:59:24 AM
    • ragnoroker: Brand new server! Join today - Good Eco/Nice Players - [link]
      September 25, 2019, 08:59:15 AM
    • PavSwag: bopalini
      September 23, 2019, 10:08:02 PM
    • PavSwag: Join autoscape,0rg fun events daily for infernal mystery boxes only server with Infernal Twisted Bow
      September 23, 2019, 03:05:33 PM
    • Frostydapure: Upcoming dmm/open pvp world server, 2006 style (different and fun trus me) [link] join join!
      September 23, 2019, 08:05:52 AM
    • Frostydapure: Upcoming dmm/open pvp world server, 2006 style (different and fun trus me) [link] join join!
      September 23, 2019, 08:05:45 AM
    • PavSwag: try autoscape,0rg today i will personally help you get RICH and well KNOWN - pav
      September 22, 2019, 02:55:32 PM

    Author Topic: kill all NPC's on specific Height lvl?  (Read 1161 times)

    0 Members and 2 Guests are viewing this topic.

    OfflineJadefx

    • First Time Poster
    • *
    • Posts: 4
    • Thanks: +10/-10
      • View Profile
    kill all NPC's on specific Height lvl?
    « on: May 16, 2016, 08:25:48 AM »
    is their a way to kill all the npcs on a designated hightlevel?
    Runescape Gambling

    Offlinerunescape sucks

    • Member
    • ****
    • Posts: 2,797
    • Thanks: +0/-0
      • View Profile
    Re: kill all NPC's on specific Height lvl?
    « Reply #1 on: May 16, 2016, 08:47:18 AM »
    Loop through all the npcs, check their height, then kill the ones that match what you're looking for.
    Roy132

    OfflineJadefx

    • First Time Poster
    • *
    • Posts: 4
    • Thanks: +10/-10
      • View Profile
    Re: kill all NPC's on specific Height lvl?
    « Reply #2 on: May 16, 2016, 09:08:56 AM »
    feel like thats a little over kill for what im doing, anyways let me try to explain a little more my bad,

    its PI source BTW

    im doing instanced NPC's based of Highlevel and PID i just need to know were to look to find a way to KILL the spawned NPC i can figure out how to do it based on if the player died or leaves the area, i just need to know what code to use to actually Kill THAT npc

    so pretty much i just need the line that would delete NPC(X) on Hightelevel(x)

    EG


    ondeath if playerposhight = pid*4
    if npcins = 1 // bandos
    commandtokillNPCHERE

    thats just a rough outline of an example of what im trying to do, the only part i need help with is the commandtokillnpc
    « Last Edit: May 16, 2016, 09:44:19 AM by Jadefx »

    OfflineX-J-K-X

    • Member
    • ****
    • Posts: 1,951
    • Thanks: +0/-0
      • View Profile
    Re: kill all NPC's on specific Height lvl?
    « Reply #3 on: May 16, 2016, 10:55:53 AM »
    Unless you're storing the slot in the array for the instanced npc, well, how else are you meant to find the 'specific' npc you're looking for without looping through all of them

    Providing the slot the spawned npc uses never changes until the npc dies or whatever, you can use that. But then you have to look into whether or not the slot gets changed upon death and such

    Offlinesk8rdude461

    • MOPARSCAPE WAS HACKED
    • Member
    • ****
    • *
    • Posts: 12,471
    • Thanks: +0/-0
      • View Profile
    Re: kill all NPC's on specific Height lvl?
    « Reply #4 on: May 16, 2016, 12:25:56 PM »
    x-j-k-x and runescape sucks are both right.

    You'll either have to store the npcs in a list/map of some form, or you have to loop the existing array in your npchandler.

    Yes, you can use a variable to declare whether or not the npc is in the instance, but that should already be covered in your PI (The "barrows npc spawn" sets the npc to your pid.. so doing similar to that works). All you'd have to check for is if it's not a summoning npc (if your server has it).

    A quick mock-up of searching through the npcs:
    Code: Java
    1. publicvoid killNpcs(int playerId){
    2.      for(NPC npc : NPCHandler.npcs){
    3.           if(npc !=null&& npc.spawnedBy== playerId){// the npc was spawned by this playerid.
    4.                // kill the npc here.
    5.           }
    6.      }
    7. }
    Note: Variables are assumed.

    OfflinexXSh0ckXx

    • Member
    • ****
    • Posts: 642
    • Thanks: +0/-0
      • View Profile
    Re: kill all NPC's on specific Height lvl?
    « Reply #5 on: May 26, 2016, 10:32:03 AM »
    x-j-k-x and runescape sucks are both right.

    You'll either have to store the npcs in a list/map of some form, or you have to loop the existing array in your npchandler.

    Yes, you can use a variable to declare whether or not the npc is in the instance, but that should already be covered in your PI (The "barrows npc spawn" sets the npc to your pid.. so doing similar to that works). All you'd have to check for is if it's not a summoning npc (if your server has it).

    A quick mock-up of searching through the npcs:
    Code: Java
    1. publicvoid killNpcs(int playerId){
    2.      for(NPC npc : NPCHandler.npcs){
    3.           if(npc !=null&& npc.spawnedBy== playerId){// the npc was spawned by this playerid.
    4.                // kill the npc here.
    5.           }
    6.      }
    7. }
    Note: Variables are assumed.

    Might aswell go with Streams.

    Code: Java
    1. publicvoid killNpcs(){
    2.  NPCHandler.npcs.stream().filter(Objects::nonNull).forEach(npc ->{
    3.    if(npc.spawnedBy== playerId && npc.height== h){//replace h with the height you'd like to check for
    4.     npc.die());
    5.   }
    6.  }
    7. }
    8.  
    ^not sure if the code works correctly, didn't test and I can just assume that NPCHandler.npcs is a List. Perhaps, the NPC will still stay in the List, which could cause problems.

    If you want to know how to cause the NPC to die, take a look into your NPC class / NPC handler. It should be NPC, hence NPC is a child of Entity, and if PI would be atleast in some point good, Entity should abstract that kind of method (maybe called 'die') which get's inherited into NPC. I can't tell tho, get used to the source, would be a solution for you then.
    « Last Edit: May 26, 2016, 10:41:42 AM by xXSh0ckXx »
    Drop me a pm.

    They got money for wars, but can't feed the poors. - Tupac Shakur
    Old, but Gold.

    Offlinesk8rdude461

    • MOPARSCAPE WAS HACKED
    • Member
    • ****
    • *
    • Posts: 12,471
    • Thanks: +0/-0
      • View Profile
    Re: kill all NPC's on specific Height lvl?
    « Reply #6 on: May 26, 2016, 10:55:21 PM »
    x-j-k-x and runescape sucks are both right.

    You'll either have to store the npcs in a list/map of some form, or you have to loop the existing array in your npchandler.

    Yes, you can use a variable to declare whether or not the npc is in the instance, but that should already be covered in your PI (The "barrows npc spawn" sets the npc to your pid.. so doing similar to that works). All you'd have to check for is if it's not a summoning npc (if your server has it).

    A quick mock-up of searching through the npcs:
    Code: Java
    1. publicvoid killNpcs(int playerId){
    2.      for(NPC npc : NPCHandler.npcs){
    3.           if(npc !=null&& npc.spawnedBy== playerId){// the npc was spawned by this playerid.
    4.                // kill the npc here.
    5.           }
    6.      }
    7. }
    Note: Variables are assumed.

    Might aswell go with Streams.

    Code: Java
    1. publicvoid killNpcs(){
    2.  NPCHandler.npcs.stream().filter(Objects::nonNull).forEach(npc ->{
    3.    if(npc.spawnedBy== playerId && npc.height== h){//replace h with the height you'd like to check for
    4.     npc.die());
    5.   }
    6.  }
    7. }
    8.  
    ^not sure if the code works correctly, didn't test and I can just assume that NPCHandler.npcs is a List. Perhaps, the NPC will still stay in the List, which could cause problems.

    If you want to know how to cause the NPC to die, take a look into your NPC class / NPC handler. It should be NPC, hence NPC is a child of Entity, and if PI would be atleast in some point good, Entity should abstract that kind of method (maybe called 'die') which get's inherited into NPC. I can't tell tho, get used to the source, would be a solution for you then.
    That won't work. You need to use the arrays class to stream it. And if you're going to filter it, you might as well add the code that's in your if statement in your filter.
    Code: Java
    1.         publicvoid killAll(int index, int height){
    2.                 Arrays.stream(NPCHandler.npcs).filter(n ->(n !=null&& n.spawnedBy== index && n.heightLevel== height))
    3.                                 .forEach(n -> n.kill());
    4.         }

    You also don't need to declare a method to kill the npc. You could just do it right in the forEach:
    Code: Java
    1.  
    2.         publicvoid killAll(int index, int height){
    3.                 Arrays.stream(NPCHandler.npcs).filter(n ->(n !=null&& n.spawnedBy== index && n.heightLevel== height))
    4.                                 .forEach(n ->{
    5.                                         n.HP=0;
    6.                                 });
    7.         }
    8.  

    OfflinexXSh0ckXx

    • Member
    • ****
    • Posts: 642
    • Thanks: +0/-0
      • View Profile
    Re: kill all NPC's on specific Height lvl?
    « Reply #7 on: May 27, 2016, 02:28:10 AM »
    x-j-k-x and runescape sucks are both right.

    You'll either have to store the npcs in a list/map of some form, or you have to loop the existing array in your npchandler.

    Yes, you can use a variable to declare whether or not the npc is in the instance, but that should already be covered in your PI (The "barrows npc spawn" sets the npc to your pid.. so doing similar to that works). All you'd have to check for is if it's not a summoning npc (if your server has it).

    A quick mock-up of searching through the npcs:
    Code: Java
    1. publicvoid killNpcs(int playerId){
    2.      for(NPC npc : NPCHandler.npcs){
    3.           if(npc !=null&& npc.spawnedBy== playerId){// the npc was spawned by this playerid.
    4.                // kill the npc here.
    5.           }
    6.      }
    7. }
    Note: Variables are assumed.

    Might aswell go with Streams.

    Code: Java
    1. publicvoid killNpcs(){
    2.  NPCHandler.npcs.stream().filter(Objects::nonNull).forEach(npc ->{
    3.    if(npc.spawnedBy== playerId && npc.height== h){//replace h with the height you'd like to check for
    4.     npc.die());
    5.   }
    6.  }
    7. }
    8.  
    ^not sure if the code works correctly, didn't test and I can just assume that NPCHandler.npcs is a List. Perhaps, the NPC will still stay in the List, which could cause problems.

    If you want to know how to cause the NPC to die, take a look into your NPC class / NPC handler. It should be NPC, hence NPC is a child of Entity, and if PI would be atleast in some point good, Entity should abstract that kind of method (maybe called 'die') which get's inherited into NPC. I can't tell tho, get used to the source, would be a solution for you then.
    That won't work. You need to use the arrays class to stream it. And if you're going to filter it, you might as well add the code that's in your if statement in your filter.
    Code: Java
    1.         publicvoid killAll(int index, int height){
    2.                 Arrays.stream(NPCHandler.npcs).filter(n ->(n !=null&& n.spawnedBy== index && n.heightLevel== height))
    3.                                 .forEach(n -> n.kill());
    4.         }

    You also don't need to declare a method to kill the npc. You could just do it right in the forEach:
    Code: Java
    1.  
    2.         publicvoid killAll(int index, int height){
    3.                 Arrays.stream(NPCHandler.npcs).filter(n ->(n !=null&& n.spawnedBy== index && n.heightLevel== height))
    4.                                 .forEach(n ->{
    5.                                         n.HP=0;
    6.                                 });
    7.         }
    8.  
    How wouldn't NPCHandler.npcs#stream work?
    Any kind of List implements Collection, which inherit streaming and parallel-streaming.
    See docs as reference

    https://docs.oracle.com/javase/8/docs/api/java/util/List.html

    And I was stating that I am unsure of the correctness, but it should look something similar to the code I wrote (you wrote it out correctly).

    That put beside, yeah, n.HP = 0; could work too. I can't tell, I already said that he (the Thread operator) should look it up, variable names can differ..
    Drop me a pm.

    They got money for wars, but can't feed the poors. - Tupac Shakur
    Old, but Gold.

    Offlinesk8rdude461

    • MOPARSCAPE WAS HACKED
    • Member
    • ****
    • *
    • Posts: 12,471
    • Thanks: +0/-0
      • View Profile
    Re: kill all NPC's on specific Height lvl?
    « Reply #8 on: May 27, 2016, 12:57:22 PM »
    How wouldn't NPCHandler.npcs#stream work?
    Any kind of List implements Collection, which inherit streaming and parallel-streaming.
    See docs as reference

    https://docs.oracle.com/javase/8/docs/api/java/util/List.html

    And I was stating that I am unsure of the correctness, but it should look something similar to the code I wrote (you wrote it out correctly).

    That put beside, yeah, n.HP = 0; could work too. I can't tell, I already said that he (the Thread operator) should look it up, variable names can differ..

    Because it's an array, not a list. Hence the use of the Arrays class.
    And the "n.HP = 0" was an example to show you can modify the npc object in the stream without relying on an outside method.

     

    Copyright © 2017 MoparScape. All rights reserved.
    Powered by SMFPacks SEO Pro Mod |
    SimplePortal 2.3.5 © 2008-2012, SimplePortal