Jump to content

Recommended Posts

Posted

Hello! Today, I made my second code!

 

It's an item, which gives you Donator's Status.

 

The id of the item is 6673, if you want change it.

 

### Eclipse Workspace Patch 1.0
#P L2jFrozen_Gs
Index: head-src/com/l2jfrozen/gameserver/handler/ItemHandler.java
===================================================================
--- head-src/com/l2jfrozen/gameserver/handler/ItemHandler.java	(revision 946)
+++ head-src/com/l2jfrozen/gameserver/handler/ItemHandler.java	(working copy)
@@ -65,6 +66,7 @@
import com.l2jfrozen.gameserver.handler.itemhandlers.SpecialXMas;
import com.l2jfrozen.gameserver.handler.itemhandlers.SpiritShot;
import com.l2jfrozen.gameserver.handler.itemhandlers.SummonItems;
+import com.l2jfrozen.gameserver.handler.itemhandlers.VipItem;

/**
  * This class manages handlers of items
@@ -144,6 +147,7 @@
		registerItemHandler(new ExtractableItems());
		registerItemHandler(new SpecialXMas());
		registerItemHandler(new SummonItems());
+		registerItemHandler(new VipItem());
		registerItemHandler(new BeastSpice());
		registerItemHandler(new JackpotSeed());
		registerItemHandler(new NobleCustomItem());

### Eclipse Workspace Patch 1.0
#P L2jFrozen_Gs
Index: head-src/com/l2jfrozen/gameserver/handler/itemhandlers/VipItem.java
===================================================================
--- head-src/com/l2jfrozen/gameserver/handler/itemhandlers/VipItem.java	(revision 0)
+++ head-src/com/l2jfrozen/gameserver/handler/itemhandlers/VipItem.java	(working copy)
@@ -0,0 +1,145 @@
+/*
+ * 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 com.l2jfrozen.gameserver.handler.itemhandlers;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import com.l2jfrozen.Config;
+import com.l2jfrozen.gameserver.handler.IItemHandler;
+import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance;
+import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jfrozen.gameserver.model.actor.instance.L2PlayableInstance;
+import com.l2jfrozen.util.CloseUtil;
+import com.l2jfrozen.util.database.L2DatabaseFactory;
+
+/**
+ * @author Crystalia
+ *
+ */
+public class VipItem implements IItemHandler
+{
+
+	private static final int ITEM_IDS[] = {
+        6673
+    };
+
+	@Override
+	public int[] getItemIds()
+    {
+        return ITEM_IDS;
+    }
+
+	private void updateDatabase(L2PcInstance player, boolean newDonator)
+	{
+		Connection con = null;
+		try
+		{
+			// prevents any NPE.
+			// ----------------
+			if(player == null)
+				return;
+
+			// Database Connection
+			//--------------------------------
+			con = L2DatabaseFactory.getInstance().getConnection(false);
+			PreparedStatement stmt = con.prepareStatement(newDonator ? INSERT_DATA : DEL_DATA);
+
+			// if it is a new donator insert proper data
+			// --------------------------------------------
+			if(newDonator)
+			{
+				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, 1);
+				stmt.execute();
+				stmt.close();
+				stmt = null;
+			}
+			else
+			// deletes from database
+			{
+				stmt.setInt(1, player.getObjectId());
+				stmt.execute();
+				stmt.close();
+				stmt = null;
+			}
+		}
+		catch(Exception e)
+		{
+			if(Config.ENABLE_ALL_EXCEPTIONS)
+				e.printStackTrace();
+			
+			
+		}
+		finally
+		{
+			CloseUtil.close(con);
+		}
+	}
+
+	// Updates That Will be Executed by MySQL
+	// ----------------------------------------
+	String INSERT_DATA = "REPLACE INTO characters_custom_data (obj_Id, char_name, hero, noble, donator) VALUES (?,?,?,?,?)";
+	String DEL_DATA = "UPDATE characters_custom_data SET donator = 0 WHERE obj_Id=?";
+	
+	@Override
+	public void useItem(L2PlayableInstance playable, L2ItemInstance item)
+	{
+		if(!(playable instanceof L2PcInstance))
+            return;
+        L2PcInstance activeChar = (L2PcInstance)playable;
+        
+        	if(activeChar.isDonator())
+        	{
+        	activeChar.sendMessage("You are already a donator.You cannot use that item.");
+        	return;
+        	playable.destroyItem("Consume", item.getObjectId(), 1, null, false);
+        	activeChar.setDonator(true);
+        	updateDatabase(activeChar, true);
+        	activeChar.sendMessage("Thanks for using our item in order to be server's donator.");
+            activeChar.broadcastUserInfo();
+        
+		
+	}
+	
+}
\ No newline at end of file

 


 

PS; It's not tested, if someone can give feedback I would be greatful.

 


 

Thanks Elfocrash, for his help in this code!

 


Posted

meh, try to do something more interesting, setting hero and noble while clicking on item isnt anything special..

Posted

meh, try to do something more interesting, setting hero and noble while clicking on item isnt anything special..

Dude, it's my first try in java. I don't know to make 'super' things, but with the time I will learn more and more.

 

I will try, to make something new. Thanks!

Posted

Yeah! I Have it at my server. :)

Are you sure? Show me the config or the code.

 

I searched l2jfrozen's source and there isn't any code about this item.

 

Waiting proofs.

Posted

I had it at my server.

C:\server\gameserver\config\functions\l2jfrozen.properties

# -----------------------------------------------------
# Donator Custom Item Configuration -
# -----------------------------------------------------
# When ActiveChar will use this item will be Donator.
EnableDonatorCustomItem = True
# Id Item Need's 
DonatorCustomItemId = 6673

Posted

YOU passed it. In retail l2jfrozen this code isn't exist.

 


 

http://subversion.assembla.com/svn/L2jFrozenInterlude/trunk/gameserver/config/functions/l2jfrozen.properties -> Current Revision (l2jfrozen.properties)

 


I don't have source. I don't use eclipse because I don't understand how to do it.

  • 1 month later...
Posted

My Code 100times easier

//Donator Custom item by Leki

package com.l2jfrozen.gameserver.handler.itemhandlers;

import com.l2jfrozen.gameserver.handler.IItemHandler;
import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance;
import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
import com.l2jfrozen.gameserver.model.actor.instance.L2PlayableInstance;
import com.l2jfrozen.gameserver.network.serverpackets.SocialAction;

public class DonateCustomItem implements IItemHandler
{

public DonateCustomItem()
{
//null
}

@Override
public void useItem(L2PlayableInstance playable, L2ItemInstance item)
{
		if(!(playable instanceof L2PcInstance))
			return;

		L2PcInstance activeChar = (L2PcInstance) playable;

		if(activeChar.isInOlympiadMode())
		{
			activeChar.sendMessage("This item can not be used on olympiad");
		}

		if(activeChar.isDonator())
		{
			activeChar.sendMessage("You are already the donator member");
		}
		else
		{
			activeChar.broadcastPacket(new SocialAction(activeChar.getObjectId(), 16));
			activeChar.setDonator(true);;
			activeChar.sendMessage("You are donator member now!");
			activeChar.broadcastUserInfo();
			playable.destroyItem("Consume", item.getObjectId(), 1, null, false);
		}
		activeChar = null;
}

@Override
public int[] getItemIds()
{
	return ITEM_IDS;
}

private static final int ITEM_IDS[] =
{
	6673
};

}

Posted

My Code 100times easier

//Donator Custom item by Leki

package com.l2jfrozen.gameserver.handler.itemhandlers;

import com.l2jfrozen.gameserver.handler.IItemHandler;
import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance;
import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
import com.l2jfrozen.gameserver.model.actor.instance.L2PlayableInstance;
import com.l2jfrozen.gameserver.network.serverpackets.SocialAction;

public class DonateCustomItem implements IItemHandler
{

public DonateCustomItem()
{
//null
}

@Override
public void useItem(L2PlayableInstance playable, L2ItemInstance item)
{
		if(!(playable instanceof L2PcInstance))
			return;

		L2PcInstance activeChar = (L2PcInstance) playable;

		if(activeChar.isInOlympiadMode())
		{
			activeChar.sendMessage("This item can not be used on olympiad");
		}

		if(activeChar.isDonator())
		{
			activeChar.sendMessage("You are already the donator member");
		}
		else
		{
			activeChar.broadcastPacket(new SocialAction(activeChar.getObjectId(), 16));
			activeChar.setDonator(true);;
			activeChar.sendMessage("You are donator member now!");
			activeChar.broadcastUserInfo();
			playable.destroyItem("Consume", item.getObjectId(), 1, null, false);
		}
		activeChar = null;
}

@Override
public int[] getItemIds()
{
	return ITEM_IDS;
}

private static final int ITEM_IDS[] =
{
	6673
};

}

You don't even use database part.

 

Also, where is registering?

Guest
This topic is now closed to further replies.
×
×
  • Create New...