Jump to content

Question

Posted

Hello everyone!
can someone help me modify my code so that my pvp and pk ad show in which region the battle took place? Here an example:

 

0IV8ChX.png

 

 

/*
 * Copyright (C) 2004-2015 L2J DataPack
 * 
 * This file is part of L2J DataPack.
 * 
 * L2J DataPack 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.
 * 
 * L2J DataPack 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 handlers.custom;

import l2r.Config;
import l2r.gameserver.model.actor.instance.L2PcInstance;
import l2r.gameserver.model.events.Containers;
import l2r.gameserver.model.events.EventType;
import l2r.gameserver.model.events.impl.character.player.OnPlayerPvPKill;
import l2r.gameserver.model.events.listeners.ConsumerEventListener;
import l2r.gameserver.network.SystemMessageId;
import l2r.gameserver.network.serverpackets.SystemMessage;
import l2r.gameserver.util.Broadcast;

public class CustomAnnouncePkPvP
{
	public CustomAnnouncePkPvP()
	{
		if (Config.ANNOUNCE_PK_PVP)
		{
			Containers.Players().addListener(new ConsumerEventListener(Containers.Players(), EventType.ON_PLAYER_PVP_KILL, (OnPlayerPvPKill event) -> OnPlayerPvPKill(event), this));
		}
	}
	
	/**
	 * @param event
	 * @return
	 */
	private Object OnPlayerPvPKill(OnPlayerPvPKill event)
	{
		L2PcInstance pk = event.getActiveChar();
		if (pk.isGM())
		{
			return null;
		}
		L2PcInstance player = event.getTarget();
		
		String msg = Config.ANNOUNCE_PVP_MSG;
		if (player.getPvpFlag() == 0)
		{
			msg = Config.ANNOUNCE_PK_MSG;
		}
		msg = msg.replace("$killer", pk.getName()).replace("$target", player.getName());
		if (Config.ANNOUNCE_PK_PVP_NORMAL_MESSAGE)
		{
			SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1);
			sm.addString(msg);
			Broadcast.toAllOnlinePlayers(sm);
		}
		else
		{
			Broadcast.toAllOnlinePlayers(msg, false);
		}
		return null;
	}
}

 

Recommended Posts

  • 0
Posted
42 minutes ago, Rootware said:

 

You are definitely an affiliated person with some members. It look as advertise.

its bad? if its not allowed remove my post :(

you know anyone else? i always send my customers on him and had no complaints so far..

  • 0
Posted (edited)
/**
 * @author Kara
 */
public class YourClass
{
	public Object onPlayerPvPKill(OnPlayerPvPKill event)
	{
		final L2PcInstance activeChar = event.getActiveChar();
		
		if (!activeChar.isGM())
		{
			final String msg = MapRegionManager.getInstance().getMapRegion(activeChar).getName() + ": " + (activeChar.getKarma() > 0 ? Config.ANNOUNCE_PK_MSG : Config.ANNOUNCE_PVP_MSG).replace("$killer", activeChar.getName()).replace("$target", event.getTarget().getName());
			
			if (Config.ANNOUNCE_PK_PVP_NORMAL_MESSAGE)
			{
				Broadcast.toAllOnlinePlayers(SystemMessage.getSystemMessage(SystemMessageId.S1).addString(msg));
			}
			else
			{
				Broadcast.toAllOnlinePlayers(msg, false);
			}
		}
		
		return null;
	}
}

 

Edited by V-Ray
  • 0
Posted
1 minute ago, HARDECORE said:

Excuse me, sorry to disturb your chat, but can someone help me? :thinking:

 

Search for something called MapRegionManager, you should have normally methods to retrieve zone name. It depends about the pack.

  • 0
Posted
5 minutes ago, HARDECORE said:

Excuse me, sorry to disturb your chat, but can someone help me? :thinking:

 

4 hours ago, V-Ray said:

/**
 * @author Kara
 */
public class YourClass
{
	public Object onPlayerPvPKill(OnPlayerPvPKill event)
	{
		final L2PcInstance activeChar = event.getActiveChar();
		
		if (!activeChar.isGM())
		{
			final String msg = MapRegionManager.getInstance().getMapRegion(activeChar).getName() + ": " + (activeChar.getKarma() > 0 ? Config.ANNOUNCE_PK_MSG : Config.ANNOUNCE_PVP_MSG).replace("$killer", activeChar.getName()).replace("$target", event.getTarget().getName());
			
			if (Config.ANNOUNCE_PK_PVP_NORMAL_MESSAGE)
			{
				Broadcast.toAllOnlinePlayers(SystemMessage.getSystemMessage(SystemMessageId.S1).addString(msg));
			}
			else
			{
				Broadcast.toAllOnlinePlayers(msg, false);
			}
		}
		
		return null;
	}
}

 

are you blind or something?

  • 0
Posted
2 minutes ago, HARDECORE said:

 

What's wrong?

 

1dsHFwj.png

 

listen he made you an example of the function you dont replace everything :D how experienced are you on this field?

  • 0
Posted
1 minute ago, Nightw0lf said:

ouça, ele fez de você um exemplo da função em que você não substitui tudo: D qual é a sua experiência nesse campo?

very little. I am not a programmer. starting to study in the area

  • 0
Posted

in this case

this is the full example

/*
 * Copyright (C) 2004-2015 L2J DataPack
 * 
 * This file is part of L2J DataPack.
 * 
 * L2J DataPack 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.
 * 
 * L2J DataPack 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 handlers.custom;

import l2r.Config;
import l2r.gameserver.model.actor.instance.L2PcInstance;
import l2r.gameserver.model.events.Containers;
import l2r.gameserver.model.events.EventType;
import l2r.gameserver.model.events.impl.character.player.OnPlayerPvPKill;
import l2r.gameserver.model.events.listeners.ConsumerEventListener;
import l2r.gameserver.network.SystemMessageId;
import l2r.gameserver.network.serverpackets.SystemMessage;
import l2r.gameserver.util.Broadcast;

public class CustomAnnouncePkPvP
{
	public CustomAnnouncePkPvP()
	{
		if (Config.ANNOUNCE_PK_PVP)
		{
			Containers.Players().addListener(new ConsumerEventListener(Containers.Players(), EventType.ON_PLAYER_PVP_KILL, (OnPlayerPvPKill event) -> OnPlayerPvPKill(event), this));
		}
	}
	
	/**
	 * @param event
	 * @return
	 */
	public Object onPlayerPvPKill(OnPlayerPvPKill event)
	{
		final L2PcInstance activeChar = event.getActiveChar();
		
		if (!activeChar.isGM())
		{
			final String msg = MapRegionManager.getInstance().getMapRegion(activeChar).getName() + ": " + (activeChar.getKarma() > 0 ? Config.ANNOUNCE_PK_MSG : Config.ANNOUNCE_PVP_MSG).replace("$killer", activeChar.getName()).replace("$target", event.getTarget().getName());
			
			if (Config.ANNOUNCE_PK_PVP_NORMAL_MESSAGE)
			{
				Broadcast.toAllOnlinePlayers(SystemMessage.getSystemMessage(SystemMessageId.S1).addString(msg));
			}
			else
			{
				Broadcast.toAllOnlinePlayers(msg, false);
			}
		}
		
		return null;
	}
}

checkout the imports and see if the classes exist try to compile then see for compilation errors

  • 0
Posted
6 minutes ago, Nightw0lf said:

in this case

this is the full example


/*
 * Copyright (C) 2004-2015 L2J DataPack
 * 
 * This file is part of L2J DataPack.
 * 
 * L2J DataPack 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.
 * 
 * L2J DataPack 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 handlers.custom;

import l2r.Config;
import l2r.gameserver.model.actor.instance.L2PcInstance;
import l2r.gameserver.model.events.Containers;
import l2r.gameserver.model.events.EventType;
import l2r.gameserver.model.events.impl.character.player.OnPlayerPvPKill;
import l2r.gameserver.model.events.listeners.ConsumerEventListener;
import l2r.gameserver.network.SystemMessageId;
import l2r.gameserver.network.serverpackets.SystemMessage;
import l2r.gameserver.util.Broadcast;

public class CustomAnnouncePkPvP
{
	public CustomAnnouncePkPvP()
	{
		if (Config.ANNOUNCE_PK_PVP)
		{
			Containers.Players().addListener(new ConsumerEventListener(Containers.Players(), EventType.ON_PLAYER_PVP_KILL, (OnPlayerPvPKill event) -> OnPlayerPvPKill(event), this));
		}
	}
	
	/**
	 * @param event
	 * @return
	 */
	public Object onPlayerPvPKill(OnPlayerPvPKill event)
	{
		final L2PcInstance activeChar = event.getActiveChar();
		
		if (!activeChar.isGM())
		{
			final String msg = MapRegionManager.getInstance().getMapRegion(activeChar).getName() + ": " + (activeChar.getKarma() > 0 ? Config.ANNOUNCE_PK_MSG : Config.ANNOUNCE_PVP_MSG).replace("$killer", activeChar.getName()).replace("$target", event.getTarget().getName());
			
			if (Config.ANNOUNCE_PK_PVP_NORMAL_MESSAGE)
			{
				Broadcast.toAllOnlinePlayers(SystemMessage.getSystemMessage(SystemMessageId.S1).addString(msg));
			}
			else
			{
				Broadcast.toAllOnlinePlayers(msg, false);
			}
		}
		
		return null;
	}
}

checkout the imports and see if the classes exist try to compile then see for compilation errors

  

I added and compiled it. no mistake! but when I test in game the ad does not appear and this error occurs in gameserver

 

zSPbow7.png

 

  • 0
Posted
5 minutes ago, HARDECORE said:

  

I added and compiled it. no mistake! but when I test in game the ad does not appear and this error occurs in gameserver

 

zSPbow7.png

 

 

Either the MapRegionManager return null cause it cannot find the region which is weird, unless you're in a custom map (Which is not included i guess) OR the target of the event is null (which most unlikely).

 

Do a null check in target like 

if (event.getTarget() == null)
{
   //Print message here to confirm is null
   return null;
}

 

If the MapRegionManager return null region and you're not on a custom region then throw your pack in the garbage as i already see is downloaded L2ro.

Guest
This topic is now closed to further replies.


×
×
  • Create New...