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.


  • Posts

    • Lol good joke.   If I'd be the one contacting yo then I'd say at least 50% in advance because you can basically just fuck off when things doesn't go your way, and then you as a developer just wasted days or even weeks of time with development.
    • "Just make your own game!" sounds simple until you’ve tried it. I did, with Epic Dragon World and learned the hard way that "open source" often means "free labor for resellers." The MIT license became a buffet for people to grab code, rebrand it and ghost the project. Even basic collaboration collapsed because everyone wanted their vision, not *a* vision. NCSoft’s lawyers aren’t theoretical. They’re a sword of Damocles. Even if you rebuild a client from scratch, if it feels like Lineage 2, they’ll come knocking. Ask the Chrono Trigger fangame corpses how that goes. MMOs are hospice care. The genre’s on life support, kept alive by whales and nostalgia. Look at Throne and Liberty, NCSoft’s own "successor" to L2, flopping harder than a 2004 PKer in ToI. Classic reboots (WoW, L2) are bandaids, not resurrections. This is the hobby. Optimizing old systems, reverse-engineering spaghetti code and preserving janky mechanics is the fun part. Monetizing it turns it into customer service hell. No thanks. Community? What community? The L2 scene is 90% resellers, 10% players who’ll quit the second they don’t get +16 on day one. Both asking how to install Java and why running the uncompiled server does not work.
    • Dear players, Open beta test for C3 begins today at 19:00 server time (GMT +2). 💰 All participants who find bugs during OBT will be rewarded with Coin of Luck (CoL): - 1 CoL for each staticmesh issue found — e.g., walking through textures, etc., - 2 CoL or more for server-side issues, depending on their severity., We strongly recommend reviewing the quest list - when switching to Chronicle 3, the total number of quests should match the number shown in the upper right corner of the window and correspond to the quest count from Chronicle 2. To log into the game, use the same data you use to access the Airin server. 📌 Download client: Google Drive
    • 🔥 Sale Alert! 🔥 Twitter Accounts with 50 Followers — now on SALE! Looking to launch a project or warm up your account base fast? We’ve got starter Twitter accounts with ~50 followers at a sweet price. 💰 Limited-time offer – while stock lasts! ✅ Organic-Looking ✅ Clean & Safe ✅ Perfect for boosting credibility 📦 Instant delivery
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock