|
Hi, not sure if this is already released but I came up with this to spawn NPC's in a random area!
I got the code from the existing NpcHandler#spawnNpc(...) method that comes with most PI bases.Code:public void spawnRandom(Client c, int id, int x, int x2, int y, int y2, int height, int walk, int hp, int maxHit, int attack, int defence, boolean attackPlayer, boolean headIcon) { NpcHandler.getNpcHandler().spawnNpc(c, id, ThreadLocalRandom.current().nextInt(x, x2 + 1), ThreadLocalRandom.current().nextInt(y, y2 + 1), height, walk, hp, maxHit, attack, defence, attackPlayer, headIcon); }
A cool thing you can do with this is spawn a ton of npc's in a region in random locations!
He's how the params work:Code://This loop spawns 100 NPC's randomly with a specified bound for (int i = 0; i < 100; i++) { NpcHandler.getNpcHandler().spawnNpc(c, npcId, ThreadLocalRandom.current().nextInt(3357, 3372 + 1), ThreadLocalRandom.current().nextInt(9629, 9649 + 1), 0, 1, 20, 5, 10, 10, true, false); }
x = bottomLeftX of the Area
x2 = bottomRigthX of the Area
y = topRightY of the Area
y2 = topLeftY of the Area
Enjoy
Last edited by Kiissmyswagb; 12-24-2015 at 12:36 AM. Reason: Added prevew image
Could be done much more nicely if you had some sort of "Location" class and you utilized consumers instead of tons of parameters
Code:public List<Npc> spawnRandom(int npcId, Location location, int amt, Consumer<Npc> action) { List<Npc> npcs = new ArrayList<>(amt); while(amt-- > 0) { Npc npc = new Npc(npcId, location.getRandomPosition()); World.getNpcs().add(npc); npcs.add(npc); action.apply(npc); } return npcs; } public List<Npc> spawnRandom(int npcId, Location location, int amt) { return spawnRandom(npcId, location, amt, it -> {}); }Code:Location location = new Location(x, y, x2, y2); spawnRandom(1, location, 100, it -> it.attack(player));
@I LOVE THOTS
Why are you using a List?
If I had a location class, I'd use it. If PI was designed for Java 8 I'd use j8 features too.
The power of lambda!!!
Well PI wasent desiged for a good stability in the long run lmao.. Why do you think he and Gabbe made a complete new system but having the same style as a PI in RUSE and released ? Well to make people stop using PI and getting over it.
where do i put this ? lol
I made something like this earlier with clipping and also added a last location recognition to create a better spaced out spawn rather then all possible cluster fuck.
Code:Position toSpawn; Position lastSpawn = null; for (int i = 0; i < 100; i++) { toSpawn = area.getRandomClippedPosition(); if (lastSpawn != null) { if (toSpawn.isWithinDistance(lastSpawn)) { toSpawn = area.getRandomClippedPosition(); } } NPC npc = new NPC(26, toSpawn); World.getAddNPCQueue().add(npc); lastSpawn = toSpawn; }
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |