Chakl22 Posted May 8, 2011 Posted May 8, 2011 I need a Script for do the next: Spawn a NPC, (with announce x NPC has spawned in x location) and will disapear in x hours (configurable time and coords, for spawn), Despawn NPC after the pre-config time (With announce x NPC has disapear, and will be spwned again in x time), PD: No reward, no drop, only spawn a NPC. Hope somone can help.
0 vampir Posted May 8, 2011 Posted May 8, 2011 there was already script about spawning npc after clicking on item, so copy code that spawn npc, make runnable class with something like public void run() while(true){ spawnNpc(); Thread.sleep(xtime); unspawnNpc(); Thread.sleep(xtime); } and in spawnNpc make announce, also make announce in unspawnNpc easy to do :) hf
0 Chakl22 Posted May 9, 2011 Author Posted May 9, 2011 Finally someone help me: Here the script: Index: data/scripts/custom/SpawnNPC/SpawnNPC.java =================================================================== --- data/scripts/custom/SpawnNPC/SpawnNPC.java (revision 0) +++ data/scripts/custom/SpawnNPC/SpawnNPC.java (revision 0) @@ -0,0 +1,97 @@ +/* + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see <http://www.gnu.org/licenses/>. + */ +package custom.SpawnNPC; + +import com.l2jserver.gameserver.model.actor.L2Npc; +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; +import com.l2jserver.gameserver.model.quest.Quest; +import com.l2jserver.gameserver.util.Broadcast; +import com.l2jserver.util.Rnd; + +/** + * This script automatically spawns, despawns and respawns an NPC of your choice at your desired location + * as well as announces the spawn location and despawn/respawn time. + * FIXME the current coordinates are from all the Newbie Guides in starting villages. Change them to your desired locations. + * @author jurchiks + */ +public class SpawnNPC extends Quest +{ + private static final int NPC = 32349; // the ID of the NPC to spawn + private static final int INITIAL_TIME = 60; // spawn 1 hour after server has started + private static final int DESPAWN_TIME = 120; // despawn 2 hours after spawned + private static final int RESPAWN_TIME = 120; // respawn 2 hours after despawned + private static final boolean RANDOM_SPAWN = false; // if true, NPC will spawn in random places, otherwise only the FIRST coordinates will be used + + //@formatter:off + private static final int[][] COORDS = + { + { -84081, 243227, -3728, 0 }, // Talking Island + { 45475, 48359, -3056, 0 }, // Elven Village + { 17024, 13296, -3736, 0 }, // Dark Elf Village + { 115632, -177996, -896, 0 }, // Dwarven Village + { -45032, -113598, -192, 0 }, // Orc Village + { -119692, 44504, 360, 0 } // Kamael Village + }; // X, Y, Z, heading + //@formatter:on + + public SpawnNPC(int id, String name, String descr) + { + super(id, name, descr); + startQuestTimer("spawn", 60000 * INITIAL_TIME, null, null); + } + + @Override + public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) + { + if (event.equalsIgnoreCase("spawn")) + { + int loc = RANDOM_SPAWN ? Rnd.get(COORDS.length) : 0; + npc = addSpawn(NPC, COORDS[loc][0], COORDS[loc][1], COORDS[loc][2], COORDS[loc][3], false, 0); + startQuestTimer("despawn", 60000 * DESPAWN_TIME, npc, null); + Broadcast.announceToOnlinePlayers("Your NPC has spawned at " + COORDS[loc][0] + " " + COORDS[loc][1] + " " + COORDS[loc][2]); + Broadcast.announceToOnlinePlayers("It will disappear in " + calcAnnounce(DESPAWN_TIME)); + } + else if (event.equalsIgnoreCase("despawn")) + { + npc.deleteMe(); + startQuestTimer("spawn", 60000 * RESPAWN_TIME, npc, null); + Broadcast.announceToOnlinePlayers("Your NPC has disappeared."); + Broadcast.announceToOnlinePlayers("It will respawn in " + calcAnnounce(RESPAWN_TIME)); + } + return null; + } + + String calcAnnounce(int time) + { + String announce = ""; + int minutes = time % 60; + if (time / 60 > 0) // if at least 1 hour + { + announce += time / 60 + " hour(s)"; + if (minutes > 0) // not exact hours, add minutes to announcement + announce += " and " + minutes + " minute(s)"; + } + else if (minutes > 0) // less than 1 hour, add minutes to announcement + announce += minutes + " minute(s)"; + if (announce.isEmpty()) // time <= 0? + announce = "!wrong time set, check your settings!"; + return announce; + } + + public static void main(String[] args) + { + new SpawnNPC(-1, "SpawnNPC", "custom"); + } +} \ No newline at end of file Tested & Working. Credits To: jurchiks from L2J Forum.
Question
Chakl22
I need a Script for do the next:
Spawn a NPC, (with announce x NPC has spawned in x location) and will disapear in x hours (configurable time and coords, for spawn),
Despawn NPC after the pre-config time (With announce x NPC has disapear, and will be spwned again in x time),
PD: No reward, no drop, only spawn a NPC. Hope somone can help.
3 answers to this question
Recommended Posts