Jump to content

Musicmasta

Member
  • Content count

    638
  • Joined

  • Last visited

About Musicmasta

  • Rank
    Adamant Member
  • Birthday 10/29/1996
  1. If I'm not mistaken it's in your NPC Update masks, there should just be a while loop, you can just add a check for the npc id like [code] if (!player.startedLightLantern && npc.getId() == id) { continue; } [/code] You've gotta locate your own NPCUpdate file though, I'm adapted to 639s hierarchy.
  2. Great updates in store, come check us out!
  3. Recently released this elsewhere under the alias Roflmaodude1, figured I might as well bring it to Runelocus. There was a single flaw I found in my code, but I have now resolved it. Enjoy. The title may be a little misleading, let me clarify. This snippet is simply to add a counter to prevent your players from sitting idly in a highly-populated NPC zone and being able to kill AFK to level up. Note: This is a very simple addition, and I'm not really sure why it hasn't been released yet(or as far as I know it hasn't). Also, I am personally Working on my 639, [URL="http://www.runelocus.com/forums/showthread.php?97121-Ambience-639"]Ambience 639 - The Good ol' Days[/URL], but once you see the code you should quickly realize how simple it is to convert this to work on any revision. Concepts: HashMap, Type Casting. Files Modified: Player.java, NPC.java, NPCTickTask.java, WalkingQueue.java, RegionData.java Alright, here we go. First off open up [b][u]Player.java[/u][/b] Import the following: [code] import java.util.HashMap; [/code] Following that, construct a new HashMap instance, we're going to name it killMap. For those of you new to HashMaps: [spoiler="Quick HashMap Explanation"] The HashMap class is just an implementing class of Map. Maps are similar to Lists in some ways, however with a Map; instead of associating an instance of a object(Integer, string, double, byte, char, class, etc.) to an Integer index increasing the size as new values are continuously added(Lists), you can associate an object instance with another object instance. Maps are kind of like relative location with geography, if a hash map were sprucewood street and the street had Steve's house at 5349, Courtney's house at 5354, Taylor's House at 5355, and John's house at 5358, assuming the hashmap's identifier were sprucewood; would look something like this in the java programming language [code] import java.util.HashMap public class Home { private static HashMap<String, Integer> sprucewood = new HashMap<String, Integer>(); static { sprucewood.put("Steve", 5349); sprucewood.put("Courtney", 5354); sprucewood.put("Taylor", 5355); sprucewood.put("John", 5358); } public static void main(String[] args) { int john = ((Integer) sprucewood.get("John")), courtney = ((Integer) sprucewood.get("Courtney")), taylor = ((Integer) sprucewood.get("Taylor")), steve = ((Integer) sprucewood.get("Steve")); System.out.println("John live's at: "+john+ " sprucewood street."); System.out.println("Courtney lives at: "+courtney+" sprucewood street."); System.out.println("Taylor lives at: "+taylor+" sprucewood street."); System.out.println("Steve lives at: "+steve+" sprucewood street."); } } [/code] The previous code would output: John live's at: 5358 sprucewood street. Courtney lives at: 5354 sprucewood street. Taylor lives at: 5355 sprucewood street. Steve lives at: 5349 sprucewood street. [/spoiler] There are many ways to utilize Hashmaps, and the previous example only skims the surface. However, lets get back to the NPC Aggression. We left off in Player.java constructing a new HashMap instance, naming it killMap: [code] public HashMap<Integer, Integer> killMap = new HashMap<Integer, Integer>(); [/code] Now that we've constructed the killMap object, locate your updateMap() method. We are modifying updateMap() because this NPC aggression is going to function very similarly to runescapes, npcs will not attack you after a certain amount have been killed unless you leave the area and come back, or re loggin. Now add the following method [code] public void resetKillMap() { killMap.clear(); } [/code] That'll sum up Player.java, go ahead and save your file. Open up RegionData.java and locate the method [code] teleport(int coordX, int coordY, int height) { [/code] locate: [code] player.updateMap(); [/code] and Below that add: [code] player.resetKillMap(); [/code] Save and close that file. Now open WalkingQueue.java Locate the method: [code]differentMap(Player player) {[/code] beneath [code] if (diffX >= 4 || diffY >= 4) { [/code] add [code] player.resetKillMap(); [/code] [B][U]If you're thinking why didn't I just add the resetKillMap() in the updateMap() method in Player.java, it's because updateMap() is called at random intervals for the player, so this would nullify this tutorials actions.[/U][/B] Now, head over to NPC.java and locate your sendDead() method. In the sendDead method, below [code] final Mob killer = getDamageManager().getKiller(); [/code] We're going to instantiate a new player player instance: [code] Player player = ((killer != null) ? killer.getPlayer() : null; [/code] Following that we'll add the following [code] if (player != null) { if (player.killMap == null) { player.killMap = new HashMap<Integer, Integer>(); player.killMap.put(getId(), 1); } else { int streak = (player.killMap.containsKey(getId()) ? ((Integer) player.killMap.get(getId())) + 1 : 1); player.killMap.put(getId(), streak); } } [/code] Here's a brief evaluation of the code you've just added. [code] Player player = ((killer != null) ? killer.getPlayer() : null; [/code] If the killer variable was successfully assigned, then it will attempt to retrieve an instance of the player class, which will return either null or an instance of the player class. However, if killer is null, then it always returns null. [code] if (player != null) { [/code] Check's to ensure that player isn't a null, if we didn't add this check point then errors would be thrown, in the situation of NvN, or the getKiller() method returns null. If either the NPC was killed by another NPC, or getKiller() returns null, and this was called, the server would be unable to find killMap because it's pointing to a null object reference. [code][code] if (player.killMap == null) { player.killMap = new HashMap<Integer, Integer>(); player.killMap.put(getId(), 1); } [/code] Should some loophole occur and killMap is not initialized, we throw a checkpoint in there to save our butts and initialize killMap. [code][code] } else { int streak = (player.killMap.containsKey(getId()) ? ((Integer) player.killMap.get(getId())) + 1 : 1); player.killMap.put(getId(), streak); [/code] This code is executed any time that killMap has already been constructed. The variable streak just defining what will be added into the HashMap. We [B][U]MUST[/U][/B] cast [code] player.killMap.get(getId()) [/code] To type Integer, otherwise you will not be able to compile because the HashMap method get(Object key) returns an Object, not an Integer. It's not really possible to add 1 to an Object. The Streak value determines its value using the ternary operator, the ternary has appeared in every programming language I've experienced so far, and I'd have to assume it's universal. It's a very nice feature to escape those blocky if else statements. The code I've used essentially narrows down the following: [code] int streak = 1; if (player.killMap.containsKey(getId())) { streak = ((Integer) player.killMap.get(getId())) + 1; } player.killMap.put(getId(), streak); [/code] Converting 5 lines of code to 2, it also looks neater and you can use it for an infinitely large if/else check, as long as you don't get lost working your way through the statements. And the final code: [code] player.killMap.put(getId(), streak); [/code] This code is simply inserting the value of streak at position getId(). HashMap's put(Object, Object) Method will overwrite the previous value of an objects position in the map, not insert in a new column, unlike ArrayLists. Consider the following code: [code] player.killMap.put(getId(), 900); player.killMap.put(getId(), 15000); [/code] Then: [code] System.out.println(player.killMap.get(getId())); [/code] Outputs 15000, [B][U]Overwriting 900[/U][/B]. Alright, we're in that final stretch, I promise. Head over to NPCTickTask.java - Method execute() In the execute method locate: [code] for (Player player : Region.getLocalPlayers [/code] Immediately below that add: [code] if (player.killMap == null) { player.killMap = new HashMap<Integer, Integer>(); } if (player.killMap.containsKey(npcId)) { if (((Integer)player.killMap.get(npcId)) > 20) { continue; } } [/code] If you've read my previous explanation, for NPC.java this should make sense to you. You're now finished, compile and update your server and you'll be good to go. Before you kill 20: [img]http://i977.photobucket.com/albums/ae252/roflmaodude1/aggressive_zps7fca46be.png[/img] After: [img]http://i977.photobucket.com/albums/ae252/roflmaodude1/nomoreaggression_zpse5d825db.png[/img] Enjoy! Any questions, feel free to contact me on skype: Musicmasta This tutorial has been released for educational purposes, I would appreciate credit for those who use it.
  4. Here are some updates that have recently been added: Updated Dungeon Minigame, NPCs no longer attack outside of their dens. Development begun on Quest Tab Swap Books Interface Added, Change prayer and Magic Books. Corporeal Beast Fixed Nex has been fixed Prayer Altar has been added at home Banking Glitch has been fixed Added Vote points shop Added vote points Added and fixed a few things, fixed some bugs and glitches we find Planning on the new quest Making better ways to receive items Fixing the Economy One by One Tinkering with some more things to add more cut-scenes into the game maybe, for special quests we add Adding more items into the game that people want to mess with Possibly adding a timer to some items based on player definitions to add degradable weapons to reduce over-poweredness. Updated the game as usual
  5. Come check out the server! Prestiging has been added! More updates to come!
  6. A lot of neat updates this week, come check them out! [url]http://ambience639.com/home/[/url] Register and get started today!
  7. [quote name='ratio']Nice.[/QUOTE] Thank you, We've added a Tutorial Cutscene and Updated some of our shops. Much easier for players to get started, [URL="http://ambience639.com/home/"]come check out our new features today![/URL]
  8. Join today! New Crystal chest, shops, loads of NPCs to fight, great EXP rate and economy.
  9. Updated the thread, added some more media. Hopefully it looks a little more appealing now ;)
  10. [quote name='baycod9']nice! lots to do it seems like :p[/QUOTE] Yeah, we haven't had much time to focus on advertising so its been really slow, but hopefully we'll have more time on our hands shortly here.
  11. One of our players decided to make us a video :) - [video=youtube;vOUETQJDWF4]http://www.youtube.com/watch?v=vOUETQJDWF4&feature=youtu.be[/video] Finally got my internet back, going to be working on cleaning this thread up soon.
  12. [quote name='ratio']"We were unable to send an email out through our server. We have deleted your account. Please go back and try again, if the problem persists post here : [Forum link coming-soon]." I keep getting this while trying to sign up the forums.. Dafuq lmao[/QUOTE] Thanks for alerting me, I'm gonna see if I can do anything to fix that real quick. I'm not sure what my web dev did. Edit: Email verification has been deactivated until further notice, registration has been fixed.
  13. Sorry about the issues connecting lately, they've been fixed and the server's now back up.
  14. [quote name='StevenAbraham']Nice support banner, I wonder who made it?[/QUOTE] My bad, gotchu.
×