Jump to content
  • 0

[Request]Need Script for Spawn & Despawn NPC.


Question

Posted

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

  • 0
Posted

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
Posted

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.

Guest
This topic is now closed to further replies.


  • Posts

    • Patch - Link https://www.mediafire.com/file/537zxllgc0hz1k4/L2Water_FILES.rar/file
    • GitHub - zikdoz/L2DiscordPresence: Simple library to enable customized Discord's rich presence (e.g. playing on some server with custom text and icons) for Lineage 2 (may be used for other games, I think)
    • Dear players!   06.12.2024 at 20:00 MSC will be the opening of the server Interlude Remastered Fulgrim, with raits x4. Fulgrim will allow you to look at the game from a new angle, and a lot of balance edits will allow you to play on your favorite classes. Development on the server will take place in stages (3 stages). After the completion of all stages, (tentatively 3-4 months) server x4 Fulgrim will be merged with our server x2 Median, with an increase in the raits of the latter to x3. See you 06.12.2024 at 20:00 at the opening!       General information. EXP/SP: x4 Adena (dynamic): x4-x1.25 Drop chance (dynamic): x4 (x3 for S-grade) Spoil chance: x4 (x3 for S grade) Raid drop chance: x2 Quest adena: x4 Quest EXP/SP: x4 Quest drop chance: x1 Epic chance: x1 Seal stones: x2 Maximum number of windows for one player: 1+1   Details can be found on our forum: https://forum.elmorelab.com/index.ph...B8%D0%B5.7128/ Our Discord - https://discord.gg/medianel
    • Hello looking for person who can make , Discord Presence in discord server. 😇        
    • Hallo Cheaters. first of all I am using Acis pack i wanna ask if someone know how to make command on Requestbypassserver.java that will show augment  wand (window) I want to bypass this one. bypass -h npc_%objectId%_Augment 1 If u want to know more info let me know  Thanks 🙏
  • Topics

×
×
  • Create New...