Jump to content
  • 0

Message On The Screen After Enchant


Question

Posted (edited)

Is there any way to do that using java to enchant an item leaves a message on the screen saying the chanse of success ?

 

like "you have X% chance to enchant your item"

 

im use l2jServer high five

 

Looking I found that should edit the "RequestExTryToPutEnchantTargetItem.java"

But exactly who should edit to make it work ?

package com.l2jserver.gameserver.network.clientpackets;

import java.util.logging.Level;

import com.l2jserver.gameserver.datatables.EnchantItemData;
import com.l2jserver.gameserver.model.EnchantScroll;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
import com.l2jserver.gameserver.network.SystemMessageId;
import com.l2jserver.gameserver.network.serverpackets.ExPutEnchantTargetItemResult;

/**
 * @author KenM
 */
public class RequestExTryToPutEnchantTargetItem extends L2GameClientPacket
{
	private static final String _C__D0_4C_REQUESTEXTRYTOPUTENCHANTTARGETITEM = "[C] D0:4C RequestExTryToPutEnchantTargetItem";
	
	private int _objectId = 0;
	
	@Override
	protected void readImpl()
	{
		_objectId = readD();
	}
	
	@Override
	protected void runImpl()
	{
		L2PcInstance activeChar = getClient().getActiveChar();
		
		if ((_objectId == 0) || (activeChar == null))
		{
			return;
		}
		
		if (activeChar.isEnchanting())
		{
			return;
		}
		
		L2ItemInstance item = activeChar.getInventory().getItemByObjectId(_objectId);
		L2ItemInstance scroll = activeChar.getActiveEnchantItem();
		
		if ((item == null) || (scroll == null))
		{
			return;
		}
		
		EnchantScroll scrollTemplate = EnchantItemData.getInstance().getEnchantScroll(scroll);
		if ((scrollTemplate == null) || !scrollTemplate.isValid(item))
		{
			activeChar.sendPacket(SystemMessageId.DOES_NOT_FIT_SCROLL_CONDITIONS);
			activeChar.setActiveEnchantItem(null);
			activeChar.sendPacket(new ExPutEnchantTargetItemResult(0));
			if (scrollTemplate == null)
			{
				_log.log(Level.WARNING, getClass().getSimpleName() + ": Undefined scroll have been used id: " + scroll.getItemId());
			}
			return;
		}
		activeChar.setIsEnchanting(true);
		activeChar.setActiveEnchantTimestamp(System.currentTimeMillis());
		activeChar.sendPacket(new ExPutEnchantTargetItemResult(_objectId));
	}
	
	@Override
	public String getType()
	{
		return _C__D0_4C_REQUESTEXTRYTOPUTENCHANTTARGETITEM;
	}
}

Edited by Hyo

11 answers to this question

Recommended Posts

  • 0
Posted (edited)

Problem solved

 

I edit my RequestExTryToPutEnchantTargetItem.java

package com.l2jserver.gameserver.network.clientpackets;

import java.util.logging.Level;

import com.l2jserver.gameserver.datatables.EnchantItemData;
import com.l2jserver.gameserver.model.EnchantScroll;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
import com.l2jserver.gameserver.network.SystemMessageId;
import com.l2jserver.gameserver.network.serverpackets.ExPutEnchantTargetItemResult;
++ import com.l2jserver.gameserver.network.serverpackets.ExShowScreenMessage;

/**
 * @author KenM
 */

public class RequestExTryToPutEnchantTargetItem extends L2GameClientPacket
{
	private static final String _C__D0_4C_REQUESTEXTRYTOPUTENCHANTTARGETITEM = "[C] D0:4C RequestExTryToPutEnchantTargetItem";

	private int _objectId = 0;

	@Override
	protected void readImpl()
	{
		_objectId = readD();
	}

	@Override
	protected void runImpl()
	{
		L2PcInstance activeChar = getClient().getActiveChar();

		if ((_objectId == 0) || (activeChar == null))
		{
			return;
		}

		if (activeChar.isEnchanting())
		{
			return;
		}

		L2ItemInstance item = activeChar.getInventory().getItemByObjectId(_objectId);
		L2ItemInstance scroll = activeChar.getActiveEnchantItem();

		if ((item == null) || (scroll == null))
		{
			return;
		}

		EnchantScroll scrollTemplate = EnchantItemData.getInstance().getEnchantScroll(scroll);
		if ((scrollTemplate == null) || !scrollTemplate.isValid(item))
		{
			activeChar.sendPacket(SystemMessageId.DOES_NOT_FIT_SCROLL_CONDITIONS);
			activeChar.setActiveEnchantItem(null);
			activeChar.sendPacket(new ExPutEnchantTargetItemResult(0));
			if (scrollTemplate == null)
			{
				_log.log(Level.WARNING, getClass().getSimpleName() + ": Undefined scroll have been used id: " + scroll.getItemId());
			}
			return;
		}
		activeChar.setIsEnchanting(true);
		++ double chance = scrollTemplate.getChance(item, null);
		++ activeChar.sendPacket(new ExShowScreenMessage("You have " + chance + "% chance of success!", 3000));
		activeChar.setActiveEnchantTimestamp(System.currentTimeMillis());
		activeChar.sendPacket(new ExPutEnchantTargetItemResult(_objectId));
	}

	@Override
	public String getType()
	{
		return _C__D0_4C_REQUESTEXTRYTOPUTENCHANTTARGETITEM;
	}
}

  :happyforever:

Edited by Hyo
  • 0
Posted

I was wrong about the RequestEnchantItem :lol:

You should send the ExShowScreenMessage with the EnchantScrolls handler which you can find in \data\scripts\handlers\itemhandlers

  • 0
Posted

ExShowScreenMessage.java

package com.l2jserver.gameserver.network.serverpackets;

import java.util.ArrayList;
import java.util.List;

import com.l2jserver.gameserver.network.NpcStringId;
import com.l2jserver.gameserver.network.SystemMessageId;

/**
 * @author Kerberos
 */
public class ExShowScreenMessage extends L2GameServerPacket
{
	private final int _type;
	private final int _sysMessageId;
	private final int _unk1;
	private final int _unk2;
	private final int _unk3;
	private final boolean _fade;
	private final int _size;
	private final int _position;
	private boolean _effect;
	private final String _text;
	private final int _time;
	private final int _npcString;
	private List<String> _parameters;
	
	public ExShowScreenMessage(String text, int time)
	{
		_type = 1;
		_sysMessageId = -1;
		_unk1 = 0;
		_unk2 = 0;
		_unk3 = 0;
		_fade = false;
		_position = 0x02;
		_text = text;
		_time = time;
		_size = 0;
		_effect = false;
		_npcString = -1;
	}
	
	public ExShowScreenMessage(NpcStringId npcString, int position, int time) // For npcstring
	{
		_type = 2;
		_sysMessageId = -1;
		_unk1 = 0;
		_unk2 = 0;
		_unk3 = 0;
		_fade = false;
		_position = position;
		_text = null;
		_time = time;
		_size = 0;
		_effect = false;
		_npcString = npcString.getId();
	}
	
	public ExShowScreenMessage(SystemMessageId systemMsg, int position, int time) // For SystemMessage
	{
		_type = 2;
		_sysMessageId = systemMsg.getId();
		_unk1 = 0;
		_unk2 = 0;
		_unk3 = 0;
		_fade = false;
		_position = position;
		_text = null;
		_time = time;
		_size = 0;
		_effect = false;
		_npcString = -1;
	}
	
	public ExShowScreenMessage(int type, int messageId, int position, int unk1, int size, int unk2, int unk3, boolean showEffect, int time, boolean fade, String text, NpcStringId npcString)
	{
		_type = type;
		_sysMessageId = messageId;
		_unk1 = unk1;
		_unk2 = unk2;
		_unk3 = unk3;
		_fade = fade;
		_position = position;
		_text = text;
		_time = time;
		_size = size;
		_effect = showEffect;
		_npcString = npcString.getId();
	}
	
	public ExShowScreenMessage(int type, int messageId, int position, int unk1, int size, int unk2, int unk3, boolean showEffect, int time, boolean fade, String text, NpcStringId npcString, String params)
	{
		_type = type;
		_sysMessageId = messageId;
		_unk1 = unk1;
		_unk2 = unk2;
		_unk3 = unk3;
		_fade = fade;
		_position = position;
		_text = text;
		_time = time;
		_size = size;
		_effect = showEffect;
		_npcString = npcString.getId();
	}
	
	/**
	 * String parameter for argument S1,S2,.. in npcstring-e.dat
	 * @param text
	 */
	public void addStringParameter(String text)
	{
		if (_parameters == null)
		{
			_parameters = new ArrayList<>();
		}
		_parameters.add(text);
	}
	
	@Override
	protected void writeImpl()
	{
		writeC(0xFE);
		writeH(0x39);
		writeD(_type); // 0 - system messages, 1 - your defined text, 2 - npcstring
		writeD(_sysMessageId); // system message id (_type must be 0 otherwise no effect)
		writeD(_position); // message position
		writeD(_unk1); // ?
		writeD(_size); // font size 0 - normal, 1 - small
		writeD(_unk2); // ?
		writeD(_unk3); // ?
		writeD(_effect ? 1 : 0); // upper effect (0 - disabled, 1 enabled) - _position must be 2 (center) otherwise no effect
		writeD(_time); // time
		writeD(_fade ? 1 : 0); // fade effect (0 - disabled, 1 enabled)
		writeD(_npcString); // npcString
		if (_npcString == -1)
		{
			writeS(_text); // your text (_type must be 1, otherwise no effect)
		}
		else
		{
			if (_parameters != null)
			{
				for (String s : _parameters)
				{
					writeS(s);
				}
			}
		}
	}
	
	public ExShowScreenMessage setUpperEffect(boolean value)
	{
		_effect = value;
		return this;
	}
}

Itemhandler

package handlers.itemhandlers;

import com.l2jserver.gameserver.handler.IItemHandler;
import com.l2jserver.gameserver.model.actor.L2Playable;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
import com.l2jserver.gameserver.network.SystemMessageId;
import com.l2jserver.gameserver.network.serverpackets.ChooseInventoryItem;

public class EnchantScrolls implements IItemHandler
{
	@Override
	public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
	{
		if (!playable.isPlayer())
		{
			playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
			return false;
		}
		
		final L2PcInstance activeChar = playable.getActingPlayer();
		if (activeChar.isCastingNow())
		{
			return false;
		}
		
		if (activeChar.isEnchanting())
		{
			activeChar.sendPacket(SystemMessageId.ENCHANTMENT_ALREADY_IN_PROGRESS);
			return false;
		}
		
		activeChar.setActiveEnchantItem(item);
		activeChar.sendPacket(new ChooseInventoryItem(item.getItemId()));
		return true;
	}
}

  • 0
Posted (edited)

What's the point of those files? Add your code after

activeChar.sendPacket(new ChooseInventoryItem(item.getItemId()));

@ EnchantItem, so you will see the msg after pressing the scroll. It's 0.8 cuz on aCis the value is double ;)

 

75d2zGA.png

Edited by SweeTs
  • 0
Posted

Something like this..

activeChar.sendPacket(new ExShowScreenMessage("You have " + Config.ENCHANT_CHANCE_WEAPON + "% chance of success!", 6000));

Also put a check for the enchant type.. note that if you have different chances for armor and jewels, you should send the chances of the two types, because it doesn't recognize what you want to enchant :)

  • 0
Posted (edited)

i edit my itemhandlers/enchantscroll.java

package handlers.itemhandlers;

import com.l2jserver.gameserver.handler.IItemHandler;
import com.l2jserver.gameserver.model.actor.L2Playable;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
+ import com.l2jserver.gameserver.network.serverpackets.ExShowScreenMessage;
import com.l2jserver.gameserver.network.SystemMessageId;
import com.l2jserver.gameserver.network.serverpackets.ChooseInventoryItem;

public class EnchantScrolls implements IItemHandler
{
	@Override
	public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
	{
		if (!playable.isPlayer())
		{
			playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
			return false;
		}
		
		final L2PcInstance activeChar = playable.getActingPlayer();
		if (activeChar.isCastingNow())
		{
			return false;
		}
		
		if (activeChar.isEnchanting())
		{
			activeChar.sendPacket(SystemMessageId.ENCHANTMENT_ALREADY_IN_PROGRESS);
			return false;
		}
		
		activeChar.setActiveEnchantItem(item);
		+ activeChar.sendPacket(new ExShowScreenMessage("You have " + Config.ENCHANT_CHANCE + "% chance of success!", 6000));
		activeChar.sendPacket(new ChooseInventoryItem(item.getItemId()));
		return true;
	}
}

Note: i use the same enchant chance for armors,weaps and jewels.

 

And i take this error in the gameserver console :(

post-133835-0-67961600-1421514814_thumb.jpg

Edited by Hyo
  • 0
Posted (edited)

Import also the Config class..

 

Ok, now are found... but the message leave when i use the scroll.. i want to message leave when i put the item

 

can understand me?

 

My custom enchant config

<enchant id="959" isBlessed="true" targetGrade="s">
		<!-- Custom Progressive enchant system uncomment the lines below to enable. -->
		<step level="1" successRate="100.00" />
		<step level="2" successRate="100.00" />
		<step level="3" successRate="100.00" />
		<step level="4" successRate="80.00" />
		<step level="5" successRate="75.00" />
		<step level="6" successRate="70.00" />
		<step level="7" successRate="65.00" />
		<step level="8" successRate="60.00" />
		<step level="9" successRate="55.00" />
		<step level="10" successRate="50.00" />
		<step level="11" successRate="45.00" />
		<step level="12" successRate="40.00" />
		<step level="13" successRate="35.00" />
		<step level="14" successRate="30.00" />
		<step level="15" successRate="25.00" />
		<step level="16" successRate="20.00" /> 
	</enchant>
Edited by Hyo
Guest
This topic is now closed to further replies.


  • Posts

    • i'll give it a shot in a few hours and post it here
    • 🛡 GoldRush — High Five x20   A fresh High Five server focused on active progression, fair competition, and a healthy player-driven economy.   GoldRush is built for players who want a fresh spin on our beloved game that is connected to today's world via Web3 marketplace.   🌍 Server Info   Chronicle: High Five Type: Mid Rate / PvP Craft Community: International Location: Europe Time Zone: GMT+3   ⚙️ Rates   EXP: x20 SP: x20 Adena: x10 Drop: x8 Spoil: x12 Raid Boss: x3 Quest Items: x5 Quest EXP / SP: x10 Quest Adena: x5   👑 Class Progression   1st Class: Free 2nd Class: Free 3rd Class: 5,000,000 Adena   1st and 2nd class transfers reward Shadow Weapons.   ✨ Main Features   No P2W as there is no donation currency in the game Web3 Marketplace Events with real rewards Rotating accessories shop Weekly Olympiad Clean and active mid-rate progression   🧩 Community Board Features   Buffer GM Shop Gatekeeper Drop Search Rankings   🔨 Enchant Info   Max Weapon Enchant: +16 Max Armor Enchant: +12 Olympiad Max Enchant: +6   Safe Enchant: Weapons / Armor: safe to +3 Full Body Armor: safe to +4   Enchant Chance: +4 to +6: 66% +7 to +9: 60% +10 to +12: 54% +13 to +14: 48% +15 to +16: 42%   🏪 GM Shop / Gear Progression   C-grade through Dynasty gear is available through the GM Shop.   Moirai+ progression is farm, craft and raid based.   There is no admin-created endgame gear selling.   🥇 Gold Rush Economy   GoldRush includes a server-wide Adena sink system.   Players contribute Adena to the Gold Rush Collector. When the server goal is reached, limited Gold Bar stock unlocks through the Gold Merchant.   Daily Gold Rush missions also allow active players to earn Gold Bars through gameplay.   🌐 Website Player-to-Player Marketplace   GoldRush includes a website-based Web3 marketplace where players can list and trade items with each other.   Items come from real players.   The marketplace is player-to-player only.   🏛 Olympiad   Weekly Olympiad cycle. Olympiad starts at 18:00 GMT+3. Olympiad max enchant: +6.   🏰 Sieges   Castle sieges take place on Sundays at 16:00 and 20:00 GMT+3.   The first siege will happen 2 weeks after launch.   🐉 Grand Boss Respawn   Queen Ant: 24h + 2h random Core: 30h + 2h random Orfen: 48h + 2h random Baium: 120h + 3h random Antharas: 120h + 24h random Valakas: 120h + 24h random Beleth: 120h + 24h random   🎉 Events   Manual GM events with real token or gold bar rewards.   ⚔️ Fair Play   Bots are strictly forbidden and will result in a ban without warning.   Dualbox is limited to 1 box.   GoldRush is built around a healthy player-to-player economy.   🚀 What to Expect   Active farming Meaningful PvP Meaningul Farming Player-driven economy No donation currency     🔗 Join Us   Website: www.goldrushpvp.xyz Discord: https://discord.gg/kg9WXxcAY   🏁 Expected Launch: July 18 2026     If you are looking for a fresh High Five x20 server with clean structure and strong long-term potential, GoldRush is almost ready.   See you in game.
    • Collisions is from client are no way to bypass from server. Can be done from client modification need to be moded a .dll I can do the work you can contact me by DM  P.D: I already have this job done on the past
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..