Jump to content
  • 0

[HELP] How to add line to remove weapons in Code Java ?


Question

Posted

how do I add a command line when to remove the member VIP also remove a weapon that the inventory?

 

see the code...

 

package com.l2j.gameserver.handler.admincommandhandlers;

import java.sql.Connection;
import java.sql.PreparedStatement;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.l2j.L2DatabaseFactory;
import com.l2j.gameserver.Announcements;
import com.l2j.gameserver.datatables.GmListTable;
import com.l2j.gameserver.handler.IAdminCommandHandler;
import com.l2j.gameserver.model.L2Object;
import com.l2j.gameserver.model.actor.instance.L2PcInstance;
import com.l2j.gameserver.network.serverpackets.SocialAction;

public class AdminVip implements IAdminCommandHandler
{
private static String[]		ADMIN_COMMANDS	=
											{ "admin_setvip" };
private final static Log	_log			= LogFactory.getLog(AdminVip.class.getName());

public boolean useAdminCommand(String command, L2PcInstance activeChar)
{
	if (activeChar == null)
		return false;

	if (command.startsWith("admin_setvip"))
	{
		L2Object target = activeChar.getTarget();

		if (target instanceof L2PcInstance)
		{
			L2PcInstance targetPlayer = (L2PcInstance) target;
			boolean newVip = !targetPlayer.isCharViP();

			if (newVip)
			{
				targetPlayer.setCharViP(true);
				targetPlayer.updateNameTitleColor();
				updateDatabase(activeChar, true);
				sendMessages(true, targetPlayer, activeChar, true, true);
				targetPlayer.broadcastPacket(new SocialAction(targetPlayer.getObjectId(), 16)); 
				targetPlayer.broadcastUserInfo();
			}
			else
			{
					targetPlayer.setCharViP(false);
				targetPlayer.updateNameTitleColor();
				updateDatabase(activeChar, false);
				sendMessages(false, targetPlayer, activeChar, true, true);
				targetPlayer.broadcastUserInfo();
			}
		}
		else
		{
			activeChar.sendMessage("Impossible to set a non Player Target as VIP.");
			_log.info("GM: " + activeChar.getName() + " is trying to set a non Player Target as VIP.");
			return false;
		}
	}
	return true;
}

private void sendMessages(boolean fornewVip, L2PcInstance player, L2PcInstance gm, boolean announce, boolean notifyGmList)
{
	if (fornewVip)
	{
		player.sendMessage(gm.getName() + " has granted VIP Status for you!");
		gm.sendMessage("You've granted VIP Status for " + player.getName());

		if (announce)
			Announcements.getInstance().announceToAll(player.getName() + " has received VIP Status!");

		if (notifyGmList)
			GmListTable.broadcastMessageToGMs("Warn: " + gm.getName() + " has Set " + player.getName() + " as VIP !");
	}
	else
	{
		player.sendMessage(gm.getName() + " has revoked VIP Status from you!");
		gm.sendMessage("You've revoked VIP Status from " + player.getName());

		if (announce)
			Announcements.getInstance().announceToAll(player.getName() + " has lost VIP Status!");

		if (notifyGmList)
			GmListTable.broadcastMessageToGMs("Warn: " + gm.getName() + " has removed VIP Status of player" + player.getName());
	}
}

/**
 *
 * @param activeChar
 * @param newDonator
 */
private void updateDatabase(L2PcInstance player, boolean newVIP)
{
	Connection con = null;
	try
	{
		// prevents any NPE.
		// ----------------
		if (player == null)
			return;

		// Database Connection
		//--------------------------------
		con = L2DatabaseFactory.getInstance().getConnection();
		PreparedStatement stmt = con.prepareStatement(newVIP ? INSERT_DATA : DEL_DATA);

		// if it is a new donator insert proper data
		// --------------------------------------------
		if (newVIP)
		{
			stmt.setInt(1, player.getObjectId());
			stmt.setString(2, player.getName());
			stmt.setInt(3, player.isHero() ? 1 : 0);
			stmt.setInt(4, player.isNoble() ? 1 : 0);
			stmt.setInt(5, player.isDonator() ? 1 : 0);
			stmt.setInt(6, 1);
			stmt.execute();
			stmt.close();
		}
		else
		// deletes from database
		{
			stmt.setInt(1, player.getObjectId());
			stmt.execute();
			stmt.close();
		}
	}
	catch (Exception e)
	{
		_log.error("Error: could not update database: ", e);
	}
	finally
	{
		try
		{
			con.close();
		}
		catch (Exception e)
		{
			_log.error("Error: could not update database: ", e);
		}
	}
}

// Updates That Will be Executed by MySQL
// ----------------------------------------
String	INSERT_DATA	= "REPLACE INTO characters_custom_data (obj_Id, char_name, hero, noble, donator, vip) VALUES (?,?,?,?,?,?)";
String	DEL_DATA	= "UPDATE characters_custom_data SET vip = 0 WHERE obj_Id=?";

/**
 * @return
 */
public String[] getAdminCommandList()
{
	return ADMIN_COMMANDS;
}
}

 

thxx

4 answers to this question

Recommended Posts

  • 0
Posted

Sorry you have to speak better english.

 

[Offtopic]

Se quiseres escreve em brazileiro que eu leio,o teu inglês é ilegivel

  • 0
Posted

Sorry i use translator!

 

Vamos la, estou querendo adicionar um linha de comando para quando eu remover o membro VIP remova também um certo item que esta no inventario dele, uma Weapon por exemplo.

 

Postei o código do AdminCommand //setvip no post antigo.

  • 0
Posted

Sorry i use translator!

 

Vamos la, estou querendo adicionar um linha de comando para quando eu remover o membro VIP remova também um certo item que esta no inventario dele, uma Weapon por exemplo.

 

Postei o código do AdminCommand //setvip no post antigo.

Just use L2PcInstance player = null; player.getInventory().deleteItem(itemId);

I don't have eclipse on this PC so the method names might be wrong,but thats basically it.

  • 0
Posted

In setvip, something like (example of my aio systtem):

 

_player.getInventory().addItem("", Config.AIO_ITEMID, 1, _player, null);

 

and to remove

 

_player.getInventory().destroyItemByItemId("", Config.AIO_ITEMID, 1, _player, null);
_player.getWarehouse().destroyItemByItemId("", Config.AIO_ITEMID, 1, _player, null);

 

WH check in case, he put the item into wh.

Guest
This topic is now closed to further replies.


  • Posts

    • ElmoreLab Harbor - Eternal C1 x1: ✅ https://harbor.elmorelab.com ElmoreLab Harbor - Eternal C1 x1 - is an exclusive server of the Eternal C1 chronicles from the top project ElmoreLab Harbor.   A unique server of its kind, on which everyone will have maximum pleasure, such as oldschool players who dream of nostalgia and to feel the warmest and classic C1 chronicles, as well as experienced players who are tired of thousands unbalanced servers of late chronicles. Due to the professional corrections of the balance system and the HONEST gameplay system - on this server, EVERY player will feel like in their own, warm and cozy Harbor C1. Let's return to the origins of L2 - back to 2004 in C1! ❤️   ⭐ Server characteristics:   STRICTLY 1 window, NO BOXES Bans for RMT and bots/cheats No donations with benefits Unique and high-quality PTS-build from Master Toma Professional corrections and full class-balance Reworked economy and closed all abuses Improved animations and all aspects of the game Exclusive HD-client with high-quality textures Experienced administration and management Fixed all bugs, geodata, exploits and holes Maximum sociality due to the 1-box system Discovering, exploring and researching Big online International server Nostalgia and oldschool-feelings   Rates: x1 Server start: 14.02.2025   The server is at the final stages of development and preparation for release. Information on the server will be updated, soon the patchnotes and changes/edits will be posted. Don't miss the legendary and epic experience on the best server in the last 20 years! ❤️ Join our C1-forum with a lot of information about server and active discussions.   ⭐ Website: https://harbor.elmorelab.com   ✅ Forum: https://forum-harbor.elmorelab.com   💥 Telegram: https://t.me/l2harbor https://t.me/l2harbor_chat   ⚡ Discord: https://discord.gg/harborelmorelab
    • yeah ok, if you say what is fuctional 100% i can't say something different 😛  but if someone find hard to compile it or get vs and all that things i have here one more simple way here to put overlay in your own server or to change your window name with few money.
    • I've been using this for 2 years now with no issues from Discord. I don't use ogg.dll either. This one works with any l2.exe too; I don’t see any difference between them.
    • hmm.. ok i just see that, is different code first of all. My sources is totally different based in other way, with else libraries.  I have access to modify everything even to make the clock to stop show how many time users play in server. 1) so maybe keep some personal info more hide. 2) i dont use ogg.dll 3) i create it and give it ready + support to install it. Plus what is mine can working with what ever .exe you want not just l2 with same simple method. And i am sure if you try this source to compile it, after 3 hours discord will like shadowban your API too thats my source
  • Topics

×
×
  • Create New...