Skip to content

Instantly share code, notes, and snippets.

@LucusAngel
Last active January 7, 2016 04:43
Show Gist options
  • Save LucusAngel/46d0b340e681c8971d70 to your computer and use it in GitHub Desktop.
Save LucusAngel/46d0b340e681c8971d70 to your computer and use it in GitHub Desktop.
u3example v2
/*
* 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 Examples;
import ai.npc.AbstractNpcAI;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.events.EventType;
import com.l2jserver.gameserver.model.events.ListenerRegisterType;
import com.l2jserver.gameserver.model.events.annotations.RegisterEvent;
import com.l2jserver.gameserver.model.events.annotations.RegisterType;
import com.l2jserver.gameserver.model.events.impl.character.OnCreatureKill;
import com.l2jserver.gameserver.network.clientpackets.Say2;
import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
/**
* Example for u3games
* @author FallenAngel
*/
public class u3gamesExample extends AbstractNpcAI
{
private static final int FAME_COUNT = 1000;
private static final int XP_REWARD = 2000;
private static final int SP_REWARD = 2000;
private u3gamesExample()
{
super(u3gamesExample.class.getSimpleName(), "Example");
}
@RegisterEvent(EventType.ON_CREATURE_KILL)
@RegisterType(ListenerRegisterType.GLOBAL)
public void OnCreatureKill(OnCreatureKill event)
{
if (event.getAttacker().isPlayable() && event.getTarget().isPlayable())
{
final L2PcInstance killer = event.getAttacker().getActingPlayer();
final L2PcInstance target = event.getTarget().getActingPlayer();
final String ip1 = killer.getClient().getConnection().getInetAddress().getHostAddress();
final String ip2 = target.getClient().getConnection().getInetAddress().getHostAddress();
if ((killer.getInstanceId() > 0) && !ip1.equals(ip2))
{
// Effects
killer.setFame(killer.getFame() + FAME_COUNT);
addExpAndSp(killer, XP_REWARD, SP_REWARD);
killer.broadcastUserInfo();
// Message
killer.broadcastPacket(new CreatureSay(killer.getObjectId(), Say2.TELL, killer.getName(), "I kill to " + target.getName() + "!"));
}
}
}
public static void main(String[] args)
{
new u3gamesExample();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment