Jump to content
  • 0

Exp Item


milosvamp

Question

What's the code for adding exp ? for sp it's GIVE_SP, but for exp idk i tried many things nothing worked, i want to make a custom item that gives exp to player when he clicks it... just like i did for SP....pls help, thanks.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

player.addExpAndSp(long exp, long sp);

 

try this:

/*
 * 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 l2f.gameserver.handler.items.impl;

import l2f.gameserver.handler.items.IItemHandler;
import l2f.gameserver.model.Playable;
import l2f.gameserver.model.Player;
import l2f.gameserver.model.items.ItemInstance;
import l2f.gameserver.utils.Location;
import l2f.gameserver.utils.Log;

/**
 * @author Alex
 *
 */
public class ExpItem implements IItemHandler
{

	private static final int[] _itemIds =
	{
		111, 1111
	};
	
	private static long _xp1 = 500;
	private static long _xp2 = 2000;
	private static long _sp1 = 500;
	private static long _sp2 = 2000;
	
	@Override
	public boolean useItem(Playable playable, ItemInstance item, boolean ctrl)
	{
		if ((playable == null) || !playable.isPlayer())
			return false;
		
		final Player player = (Player) playable;
		final int itemId = item.getItemId();
		switch (itemId)
		{
			case 111:
				player.addExpAndSp(_xp1, _sp1);
				player.sendMessage("The gods gave you " + _xp1 + " xp and " + _sp1 + " sp.");
				break;
			case 1111:
				player.addExpAndSp(_xp2, _sp2);
				player.sendMessage("The gods gave you " + _xp2 + " xp and " + _sp2 + " sp.");
				break;
			default:
				return false;
		}
		return true;
	}
	
	@Override
	public final int[] getItemIds()
	{
		return _itemIds;
	}
	
	@Override
	public boolean pickupItem(Playable playable, ItemInstance item)
	{
		return true;
	}

	@Override
	public void dropItem(Player player, ItemInstance item, long count, Location loc)
	{
		if (item.isEquipped())
		{
			player.getInventory().unEquipItem(item);
			player.sendUserInfo(true);
		}
		
		item = player.getInventory().removeItemByObjectId(item.getObjectId(), count);
		if (item == null)
		{
			player.sendActionFailed();
			return;
		}
		
		Log.LogItem(player, Log.Drop, item);
		
		item.dropToTheGround(player, loc);
		player.disableDrop(1000);
		
		player.sendChanges();
	}
	
}

the pack that i used ot write it is stormdc

Edited by ganjaradio
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...