Jump to content
  • 0

[Q]Spawn Mob with your name


Question

Posted

can some one write a voice command .spawn and this command should do this:

 

Update monster(for Example Sin Eater),rename it to characters's name who uses this command and spawn it(if it is possible it should not respawn)

 

can you?

3 answers to this question

Recommended Posts

  • 0
Posted

I think this section shouldn't be used to request for complete codes.

Anyway I did something, you can try it or get a clue and did it by yourself.

Not tested.

 

[index: dist/game/data/scripts/handlers/voicedcommandhandlers/Spawn.java
===================================================================
--- dist/game/data/scripts/handlers/voicedcommandhandlers/Spawn.java	(revision 0)
+++ dist/game/data/scripts/handlers/voicedcommandhandlers/Spawn.java	(revision 0)
@@ -0,0 +1,100 @@
+/*
+ * 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 handlers.voicedcommandhandlers;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import com.l2jhidden.main.L2DatabaseFactory;
+import com.l2jserver.gameserver.datatables.NpcTable;
+import com.l2jserver.gameserver.datatables.SpawnTable;
+import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
+import com.l2jserver.gameserver.model.L2Spawn;
+import com.l2jserver.gameserver.model.actor.L2Npc;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
+import com.l2jserver.util.Rnd;
+
+/**
+ * 
+ * @author Wyatt
+ * 
+ */
+public class Spawn implements IVoicedCommandHandler
+{
+	private static final String[] VOICED_COMMANDS =
+	{
+		"spawn"
+	};
+	
+	private static L2Spawn _npcSpawn = null;
+	private static L2Npc _lastNpcSpawn = null;
+	private static int npcid = 12564;
+	
+	@Override
+	public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params)
+	{
+		if (command.equals("spawn"))
+		{
+			Connection con = null;
+			try
+			{
+				con = L2DatabaseFactory.getInstance().getConnection();
+				PreparedStatement statement = con.prepareStatement("UPDATE `npc` SET name='"+activeChar.getName()+"' WHERE id="+npcid);
+				statement.executeQuery();
+				statement.close();			
+			}
+			catch (Exception e)
+			{
+			}
+			finally
+			{
+				L2DatabaseFactory.close(con);
+			}
+			
+			L2NpcTemplate tmpl = NpcTable.getInstance().getTemplate(npcid);	
+			try
+			{
+				_npcSpawn = new L2Spawn(tmpl);
+				
+				_npcSpawn.setLocx(Rnd.get(activeChar.getX()-100, activeChar.getX()+100));
+				_npcSpawn.setLocy(Rnd.get(activeChar.getY()-100, activeChar.getY()+100));
+				_npcSpawn.setLocz(activeChar.getZ());
+				_npcSpawn.setAmo.unt(1);//remove the "."
+				_npcSpawn.setHeading(activeChar.getHeading());
+				_npcSpawn.setRespawnDelay(1);
+				
+				SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
+				
+				_npcSpawn.init();
+				_lastNpcSpawn = _npcSpawn.getLastSpawn();
+				_lastNpcSpawn.isAggressive();
+				_lastNpcSpawn.decayMe();
+				_lastNpcSpawn.spawnMe(_npcSpawn.getLastSpawn().getX(), _npcSpawn.getLastSpawn().getY(), _npcSpawn.getLastSpawn().getZ());
+			
+			}
+			catch (Exception e)
+			{
+			}
+		}
+		
+		return true;
+	}
+	
+	@Override
+	public String[] getVoicedCommandList()
+	{
+		return VOICED_COMMANDS;
+	}
+}
/code]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...