Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • hardcore22: are there any kind of silabsoft servers like back in the days i miss that
      May 25, 2020, 05:44:08 AM
    • Amcora: @ dr house contact me; greetings celien :)
      May 24, 2020, 03:16:21 PM
    • Amcora: Stop shouting around please
      May 24, 2020, 03:13:26 PM
    • iddsyou: PkOwnage OSRSPS [link]  Join us on Discord! [link]  Download: [link]
      May 17, 2020, 11:44:17 AM
    • Decimate Returns: PROJECT DECIMATE RETURNS !! 300+ PLAYERS BACK IN 2012 - NOW WITH ALOT OF UPDATES ! JOIN NOW! [link]
      May 17, 2020, 02:48:19 AM
    • Decimate Returns: PROJECT DECIMATE RETURNS !! 300+ PLAYERS BACK IN 2012 - NOW WITH ALOT OF UPDATES ! JOIN NOW! [link]
      May 17, 2020, 02:48:12 AM
    • Decimate Returns: PROJECT DECIMATE RETURNS !! 300+ PLAYERS BACK IN 2012 - NOW WITH ALOT OF UPDATES ! JOIN NOW! [link]
      May 17, 2020, 02:47:56 AM
    • Decimate Returns: PROJECT DECIMATE RETURNS !! 300+ PLAYERS BACK IN 2012 - NOW WITH ALOT OF UPDATES ! JOIN NOW! [link]
      May 17, 2020, 02:47:49 AM
    • Decimate Returns: PROJECT DECIMATE RETURNS !! 300+ PLAYERS BACK IN 2012 - NOW WITH ALOT OF UPDATES ! JOIN NOW! [link]
      May 17, 2020, 02:47:42 AM
    • Decimate Returns: PROJECT DECIMATE RETURNS !! 300+ BACK IN 2012 - NOW WITH ALOT OF UPDATES ! JOIN NOW! [link]
      May 17, 2020, 02:47:29 AM
    • ragnoroker: BRAND NEW SERVER - PRE EOC - UNIQUE - JOIN TODAY :) - [link]
      May 15, 2020, 11:18:03 AM
    • ragnoroker: BRAND NEW SERVER - PRE EOC - UNIQUE - JOIN TODAY :) - [link]
      May 15, 2020, 11:17:53 AM
    • ragnoroker: BRAND NEW SERVER - PRE EOC - UNIQUE - JOIN TODAY :) - [link]
      May 15, 2020, 11:17:50 AM
    • Decimate Returns: Project Decimate 474 OSRS ; [link]
      May 13, 2020, 07:27:00 PM
    • hardcore22: are there any silabsoft servers left? of the good old days like hackscape
      May 12, 2020, 07:53:18 AM
    • iddsyou: yo guys check out this instagram post #pkownage  [link]
      May 06, 2020, 02:35:58 PM
    • fishingsheep: any servers like project catasrophe or frugoo scape been remade ?
      May 04, 2020, 05:01:00 PM
    • asshole_rule: relmitos the legend
      May 04, 2020, 04:28:54 PM
    • iddsyou: PkOwnage 317 OSRS, Vote4donor, [link] Download now: [link] Discord: [link]
      May 04, 2020, 11:15:11 AM
    • relmitos: is anyone familiar with 317 packet opcodes? Im confused about opcode 3 (wich appears to send wether or not the client window is currently focused). is it safe to ignore?
      May 03, 2020, 08:47:40 AM

    Author Topic: kill all NPC's on specific Height lvl?  (Read 1204 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