Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • ragnoroker: Brand new server! Less than 1 week old! Nightmare/Raids 1/2/Hydra/Pk Modes/Exp modes/ Unique  Join today - [link]
      July 04, 2020, 06:42:38 PM
    • ragnoroker: Brand new server! Less than 1 week old! Nightmare/Raids 1/2/Hydra/Pk Modes/Exp modes/ Unique  Join today - [link]
      July 04, 2020, 06:42:32 PM
    • iddsyou: PkOwnage 2 worlds, modern OSRS & 2014 server! [link]  Join us on Discord! [link]
      July 04, 2020, 11:07:29 AM
    • slayerpure: kingdom full blown custom server with over 50 custom bosses released last week. play now here     [link]
      July 02, 2020, 08:44:32 PM
    • jgoet: dodian !!
      July 02, 2020, 07:15:44 PM
    • jgoet: join [link]  its back online !!!!
      July 02, 2020, 07:15:37 PM
    • Protojae: RIP moparscape
      July 02, 2020, 03:01:32 PM
    • Protojae: obviously thiswebsite is dead as fudge
      July 02, 2020, 03:01:14 PM
    • ragnoroker: RuneGuild has just been released! 1 Hour old, Come join the fun - [link]
      June 26, 2020, 02:14:21 PM
    • ragnoroker: RuneGuild has just been released! 1 Hour old, Come join the fun - [link]
      June 26, 2020, 02:14:08 PM
    • ragnoroker: RuneGuild has just been released! 1 Hour old, Come join the fun - [link]
      June 26, 2020, 02:14:00 PM
    • Fox2007: rune-nexus.com - FREE advertising, SEO optimized - no registration required
      June 26, 2020, 06:21:47 AM
    • Decimate Returns: trailer video posted for Project Decimate, Official Launch is in a few weeks! watch here: [youtube]LBorsdI-k1Y[/youtube]
      June 24, 2020, 07:18:03 PM
    • slayerpure: 1 week old rsps we need players and potential staff, customs and goku/vegeta sets play here!    [link] join our discord [link]
      June 24, 2020, 05:23:46 PM
    • Decimate Returns: Project Decimate is still in BETA: join our discord to keep up with the new content added: [link]
      June 24, 2020, 01:09:23 PM
    • Decimate Returns: Project Decimate is still in BETA: join our discord to keep up with the new content added: [link]
      June 24, 2020, 01:09:03 PM
    • dan v jad: PkOwnage OSRS Great server great community!  Join us on Discord! [link]  Download: [link]
      June 21, 2020, 09:23:28 AM
    • Lens: Sick Custom RSPS - CrystalPS. Join us on Discord. [link]
      June 20, 2020, 04:35:44 PM
    • Shady Aftermath: check out skyfire317.com gott 3 custom skills, afk zones
      June 19, 2020, 10:22:22 PM
    • Shady Aftermath: check out skyfire317.com gott 3 custom skills, afk zones
      June 19, 2020, 10:22:14 PM

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

    0 Members and 1 Guest 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