Skip to content

Instantly share code, notes, and snippets.

@ChaosPaladin
Forked from St3eT/admin_dice.diff
Created February 25, 2016 15:22
Show Gist options
  • Save ChaosPaladin/98cdc09d957a96d07b73 to your computer and use it in GitHub Desktop.
Save ChaosPaladin/98cdc09d957a96d07b73 to your computer and use it in GitHub Desktop.
Dice admin command
### Eclipse Workspace Patch 1.0
#P L2J_DataPack_BETA
Index: dist/game/data/scripts/handlers/admincommandhandlers/AdminDice.java
===================================================================
--- dist/game/data/scripts/handlers/admincommandhandlers/AdminDice.java (revision 0)
+++ dist/game/data/scripts/handlers/admincommandhandlers/AdminDice.java (working copy)
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2004-2014 L2J DataPack
+ *
+ * This file is part of L2J DataPack.
+ *
+ * L2J DataPack 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.
+ *
+ * L2J DataPack 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.admincommandhandlers;
+
+import java.util.StringTokenizer;
+
+import com.l2jserver.gameserver.handler.IAdminCommandHandler;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jserver.gameserver.network.serverpackets.Dice;
+import com.l2jserver.gameserver.util.Broadcast;
+import com.l2jserver.util.Rnd;
+
+/**
+ * Something smart.
+ */
+public class AdminDice implements IAdminCommandHandler
+{
+ private static final String[] ADMIN_COMMANDS =
+ {
+ "admin_dice",
+ "admin_setdice",
+ };
+
+ @Override
+ public boolean useAdminCommand(String command, L2PcInstance activeChar)
+ {
+ final StringTokenizer st = new StringTokenizer(command, " ");
+ final String actualCommand = st.nextToken();
+ switch (actualCommand.toLowerCase())
+ {
+ case "admin_dice":
+ {
+ final int number;
+ if (st.hasMoreTokens())
+ {
+ number = Integer.parseInt(st.nextToken());
+ }
+ else
+ {
+ number = Rnd.get(1, 6);
+ }
+ Broadcast.toSelfAndKnownPlayers(activeChar, new Dice(activeChar.getObjectId(), 4628, number, activeChar.getX() - 30, activeChar.getY() - 30, activeChar.getZ()));
+ break;
+ }
+ case "admin_setdice":
+ {
+ if (st.hasMoreTokens())
+ {
+ if (activeChar.getTarget() != null)
+ {
+ if (activeChar.getTarget().isPlayer())
+ {
+ final int number = Integer.parseInt(st.nextToken());
+
+ if ((number >= 1) && (number <= 6))
+ {
+ ((L2PcInstance) activeChar.getTarget()).getVariables().set("DICE_NUMBER", String.valueOf(number));
+ }
+ else
+ {
+ activeChar.sendMessage("Bad usage! usage: //setdice <1-6>");
+ }
+ }
+ else
+ {
+ activeChar.sendMessage("Your target must be player.");
+ }
+ }
+ else
+ {
+ activeChar.sendMessage("You need target for that.");
+ }
+ }
+ else
+ {
+ activeChar.sendMessage("Bad usage! usage: //setdice <1-6>");
+ }
+ break;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public String[] getAdminCommandList()
+ {
+ return ADMIN_COMMANDS;
+ }
+}
\ No newline at end of file
Index: dist/game/data/scripts/handlers/MasterHandler.java
===================================================================
--- dist/game/data/scripts/handlers/MasterHandler.java (revision 10322)
+++ dist/game/data/scripts/handlers/MasterHandler.java (working copy)
@@ -63,6 +63,7 @@
import handlers.admincommandhandlers.AdminCursedWeapons;
import handlers.admincommandhandlers.AdminDebug;
import handlers.admincommandhandlers.AdminDelete;
+import handlers.admincommandhandlers.AdminDice;
import handlers.admincommandhandlers.AdminDisconnect;
import handlers.admincommandhandlers.AdminDoorControl;
import handlers.admincommandhandlers.AdminEditChar;
@@ -328,6 +329,7 @@
AdminCursedWeapons.class,
AdminDebug.class,
AdminDelete.class,
+ AdminDice.class,
AdminDisconnect.class,
AdminDoorControl.class,
AdminEditChar.class,
Index: dist/game/data/scripts/handlers/itemhandlers/RollingDice.java
===================================================================
--- dist/game/data/scripts/handlers/itemhandlers/RollingDice.java (revision 10322)
+++ dist/game/data/scripts/handlers/itemhandlers/RollingDice.java (working copy)
@@ -56,6 +56,12 @@
return false;
}
+ if (activeChar.getVariables().getInt("DICE_NUMBER", -1) != -1)
+ {
+ number = activeChar.getVariables().getInt("DICE_NUMBER");
+ activeChar.getVariables().remove("DICE_NUMBER");
+ }
+
Broadcast.toSelfAndKnownPlayers(activeChar, new Dice(activeChar.getObjectId(), itemId, number, activeChar.getX() - 30, activeChar.getY() - 30, activeChar.getZ()));
SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_ROLLED_S2);
Index: dist/game/config/adminCommands.xml
===================================================================
--- dist/game/config/adminCommands.xml (revision 10322)
+++ dist/game/config/adminCommands.xml (working copy)
@@ -607,6 +607,10 @@
<!-- ADMIN SCAN -->
<admin command="admin_scan" accessLevel="7" />
<admin command="admin_deleteNpcByObjectId" accessLevel="7" confirmDlg="true" />
+
+ <!-- ADMIN DICE -->
+ <admin command="admin_dice" accessLevel="7" />
+ <admin command="admin_setdice" accessLevel="7" />
<!-- VOICE COMMANDS -->
<admin command="banchat" accessLevel="7" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment