Jump to content

Question

Posted

Hello, i'm using phoenix engine which has CTF event inside.

The problem is that when event start and i go to get the enemy flag when i click on enemy team holder nothing happen..

i don't get the flag, no messages, no gs errors, nothing...

 

Here's the code: 

package net.phoenixengine.event;

import net.phoenixengine.AbstractEvent;
import net.phoenixengine.Config;
import net.phoenixengine.container.NpcContainer;
import net.phoenixengine.io.Out;
import net.phoenixengine.model.EventNpc;
import net.phoenixengine.model.EventPlayer;
import net.phoenixengine.model.TeamEventStatus;

public class CTF extends AbstractEvent
{
	public static boolean enabled = true;
	
	private class Core implements Runnable
	{
		
		@Override
		public void run()
		{
			try
			{
				switch (eventState)
				{
					case START:
						divideIntoTeams(2);
						teleportToTeamPos();
						preparePlayers();
						createPartyOfTeam(1);
						createPartyOfTeam(2);
						forceSitAll();
						spawnFlagsAndHolders();
						setStatus(EventState.FIGHT);
						schedule(10000);
						break;
					
					case FIGHT:
						forceStandAll();
						setStatus(EventState.END);
						
						clock.start();
						
						break;
					
					case END:
						clock.stop();
						if (winnerTeam == 0)
							winnerTeam = getWinnerTeam();
						unspawnFlagsAndHolders();
						if (playerWithRedFlag != null)
							unequipFlag(playerWithRedFlag);
						if (playerWithBlueFlag != null)
							unequipFlag(playerWithBlueFlag);
						giveReward(getPlayersOfTeam(winnerTeam));
						setStatus(EventState.INACTIVE);
						announce("Congratulation! The " + teams.get(winnerTeam).getName() + " team won the event with " + teams.get(winnerTeam).getScore() + " kills!");
						eventEnded();
						break;
				}
			}
			catch (final Throwable e)
			{
				e.printStackTrace();
				announce("Error! Event ended.");
				eventEnded();
			}
		}
	}
	
	private enum EventState
	{
		START, FIGHT, END, TELEPORT, INACTIVE
	}
	
	private EventState eventState;
	
	private final Core task;
	
	private EventNpc redFlagNpc;
	private EventNpc blueFlagNpc;
	private EventNpc redHolderNpc;
	private EventNpc blueHolderNpc;
	private int redFlagStatus;
	private int blueFlagStatus;
	private EventPlayer playerWithRedFlag;
	private EventPlayer playerWithBlueFlag;
	
	public CTF(final Integer containerId)
	{
		super(containerId);
		eventId = 10;
		createNewTeam(1, "Blue", Config.getInstance().getColor(getId(), "Blue"), Config.getInstance().getPosition(getId(), "Blue", 1));
		createNewTeam(2, "Red", Config.getInstance().getColor(getId(), "Red"), Config.getInstance().getPosition(getId(), "Red", 1));
		task = new Core();
		winnerTeam = 0;
		playerWithRedFlag = null;
		playerWithBlueFlag = null;
		blueFlagStatus = 0;
		redFlagStatus = 0;
		clock = new EventClock(Config.getInstance().getInt(getId(), "matchTime"));
		
	}
	
	@Override
	protected void endEvent()
	{
		winnerTeam = players.head().getNext().getValue().getMainTeam();
		
		setStatus(EventState.END);
		clock.stop();
		
	}
	
	private void equipFlag(final EventPlayer player, final int flag)
	{
		player.unequipWeapon();
		player.equipNewItem(6718);
		
		switch (flag)
		{
			case 1:
				playerWithBlueFlag = player;
				announce(getPlayerList(), player.getName() + " took the Blue flag!");
				blueFlagNpc.unspawn();
				break;
			case 2:
				playerWithRedFlag = player;
				announce(getPlayerList(), player.getName() + " took the Red flag!");
				redFlagNpc.unspawn();
				break;
			default:
				break;
		}
		player.broadcastUserInfo();
	}
	
	@Override
	protected String getScorebar()
	{
		return "" + teams.get(1).getName() + ": " + teams.get(1).getScore() + "  " + teams.get(2).getName() + ": " + teams.get(2).getScore() + "  Time: " + clock.getTimeInString();
	}
	
	/* (non-Javadoc)
	 * @see net.phoenixengine.AbstractEvent#onClockZero()
	 */
	@Override
	protected void onClockZero()
	{
		setStatus(EventState.END);
		schedule(1);
	}
	
	@Override
	public void onDie(final EventPlayer victim, final EventPlayer killer)
	{
		super.onDie(victim, killer);
		if (playerWithRedFlag != null && playerWithRedFlag.equals(victim))
		{
			announce(getPlayerList(), victim.getName() + " dropped the Red flag!");
			redFlagStatus = 2;
			unequipFlag(victim);
			redFlagNpc = NpcContainer.getInstance().createNpc(victim.getOwnerLoc().getX(), victim.getOwnerLoc().getY(), victim.getOwnerLoc().getZ(), Config.getInstance().getInt(getId(), "redFlagId"), instanceId);
		}
		if (playerWithBlueFlag != null && playerWithBlueFlag.equals(victim))
		{
			announce(getPlayerList(), victim.getName() + " dropped the Blue flag!");
			blueFlagStatus = 2;
			unequipFlag(victim);
			blueFlagNpc = NpcContainer.getInstance().createNpc(victim.getOwnerLoc().getX(), victim.getOwnerLoc().getY(), victim.getOwnerLoc().getZ(), Config.getInstance().getInt(getId(), "blueFlagId"), instanceId);
		}
		
		addToResurrector(victim);
	}
	
	@Override
	public void onKill(final EventPlayer victim, final EventPlayer killer)
	{
		super.onKill(victim, killer);
		
	}
	
	@Override
	public void onLogout(final EventPlayer player)
	{
		super.onLogout(player);
		
		if (playerWithRedFlag.equals(player))
		{
			announce(getPlayerList(), player.getName() + " dropped the Red flag!");
			redFlagStatus = 2;
			unequipFlag(player);
			redFlagNpc = NpcContainer.getInstance().createNpc(player.getOwnerLoc().getX(), player.getOwnerLoc().getY(), player.getOwnerLoc().getZ(), Config.getInstance().getInt(getId(), "redFlagId"), instanceId);
		}
		if (playerWithBlueFlag.equals(player))
		{
			announce(getPlayerList(), player.getName() + " dropped the Blue flag!");
			blueFlagStatus = 2;
			unequipFlag(player);
			blueFlagNpc = NpcContainer.getInstance().createNpc(player.getOwnerLoc().getX(), player.getOwnerLoc().getY(), player.getOwnerLoc().getZ(), Config.getInstance().getInt(getId(), "blueFlagId"), instanceId);
		}
		
	}
	
	@Override
	public boolean onTalkNpc(final Integer npcId, final EventPlayer player)
	{
		final EventNpc npc = NpcContainer.getInstance().getNpc(npcId);
		
		if (npc == null)
			return false;
		
		if (!(npc.equals(blueFlagNpc) || npc.equals(blueHolderNpc) || npc.equals(redFlagNpc) || npc.equals(redHolderNpc)))
			return false;
		// Blue holder
		if (npc.equals(blueHolderNpc))
			if (player.equals(playerWithRedFlag) && blueFlagStatus == 0)
			{
				announce(getPlayerList(), "The Blue team scored!");
				teams.get(player.getMainTeam()).increaseScore();
				player.increaseScore();
				returnFlag(2);
			}
		
		// Red holder
		if (npc.equals(redHolderNpc))
			if (player.equals(playerWithBlueFlag) && redFlagStatus == 0)
			{
				announce(getPlayerList(), "The Red team scored!");
				teams.get(player.getMainTeam()).increaseScore();
				player.increaseScore();
				returnFlag(1);
			}
		
		// Blue flag
		if (npc.equals(blueFlagNpc))
		{
			if (blueFlagStatus == 2)
			{
				// blue player
				if (player.getMainTeam() == 1)
					returnFlag(1);
				
				// red player
				if (player.getMainTeam() == 2)
					equipFlag(player, 1);
			}
			if (blueFlagStatus == 0)
				if (player.getMainTeam() == 2)
				{
					equipFlag(player, 1);
					blueFlagNpc.unspawn();
					blueFlagStatus = 1;
				}
			
		}
		
		// Red flag
		if (npc.equals(redFlagNpc))
		{
			if (redFlagStatus == 2)
			{
				// red player
				if (player.getMainTeam() == 2)
					returnFlag(2);
				
				// blue player
				if (player.getMainTeam() == 1)
					equipFlag(player, 2);
			}
			if (redFlagStatus == 0)
				if (player.getMainTeam() == 1)
				{
					equipFlag(player, 2);
					redFlagNpc.unspawn();
					redFlagStatus = 1;
				}
		}
		return true;
	}
	
	@Override
	public boolean onUseItem(final EventPlayer player, final Integer item)
	{
		if (playerWithRedFlag != null && playerWithRedFlag.equals(player) || playerWithBlueFlag != null && playerWithBlueFlag.equals(player))
			return false;
		
		return true;
	}
	
	private void returnFlag(final int flag)
	{
		int[] pos;
		switch (flag)
		{
			case 1:
				if (playerWithBlueFlag != null)
					unequipFlag(playerWithBlueFlag);
				if (blueFlagStatus == 2)
					blueFlagNpc.unspawn();
				
				pos = Config.getInstance().getPosition(getId(), "BlueFlag", 1);
				blueFlagNpc = NpcContainer.getInstance().createNpc(pos[0], pos[1], pos[2], Config.getInstance().getInt(getId(), "blueFlagId"), instanceId);
				blueFlagStatus = 0;
				announce(getPlayerList(), "The Blue flag returned!");
				break;
			
			case 2:
				if (playerWithRedFlag != null)
					unequipFlag(playerWithRedFlag);
				if (redFlagStatus == 2)
					redFlagNpc.unspawn();
				
				pos = Config.getInstance().getPosition(getId(), "RedFlag", 1);
				redFlagNpc = NpcContainer.getInstance().createNpc(pos[0], pos[1], pos[2], Config.getInstance().getInt(getId(), "redFlagId"), instanceId);
				redFlagStatus = 0;
				announce(getPlayerList(), "The Red flag returned!");
				break;
		}
	}
	
	@Override
	protected void schedule(final int time)
	{
		Out.tpmScheduleGeneral(task, time);
	}
	
	private void setStatus(final EventState s)
	{
		eventState = s;
	}
	
	private void spawnFlagsAndHolders()
	{
		int[] pos = Config.getInstance().getPosition(getId(), "BlueFlag", 1);
		blueFlagNpc = NpcContainer.getInstance().createNpc(pos[0], pos[1], pos[2], Config.getInstance().getInt(getId(), "blueFlagId"), instanceId);
		blueHolderNpc = NpcContainer.getInstance().createNpc(pos[0], pos[1], pos[2], Config.getInstance().getInt(getId(), "blueFlagHolderId"), instanceId);
		
		pos = Config.getInstance().getPosition(getId(), "RedFlag", 1);
		redFlagNpc = NpcContainer.getInstance().createNpc(pos[0], pos[1], pos[2], Config.getInstance().getInt(getId(), "redFlagId"), instanceId);
		redHolderNpc = NpcContainer.getInstance().createNpc(pos[0], pos[1], pos[2], Config.getInstance().getInt(getId(), "redFlagHolderId"), instanceId);
	}
	
	@Override
	public void start()
	{
		setStatus(EventState.START);
		schedule(1);
	}
	
	private void unequipFlag(final EventPlayer player)
	{
		player.unequipAndRemove(6718);
		
		if (player.equals(playerWithRedFlag))
			playerWithRedFlag = null;
		if (player.equals(playerWithBlueFlag))
			playerWithBlueFlag = null;
	}
	
	private void unspawnFlagsAndHolders()
	{
		blueFlagNpc.unspawn();
		blueHolderNpc.unspawn();
		redFlagNpc.unspawn();
		redHolderNpc.unspawn();
	}
	
	@Override
	public void createStatus()
	{
		status = new TeamEventStatus(containerId);
	}
}

And help i would appreciate.

2 answers to this question

Recommended Posts

Guest
This topic is now closed to further replies.


  • Posts

    • It's also the players' fault, because there have been decent servers implementing some of the things you said plus some other 'innovations', plus many QOL things for newbies (ingame bestiary, with drops searchers, etc). In the end, it's the players who decide to feed into that shit and play the most garbage servers simply because the owners of the servers gave their clan leaders 100 euros, or they insta quit the server because they didn't win the first QA, etc, etc, etc.   In the end, if a server is garbage or great it doesn't really matter if the players don't wanna stay in there.   Players are no better than the devs themselves, in the end it seems there are abusive devs who will milk the shit out of their willingly milkable players, or there are none, goes both ways.
    • In my opinion, L2 is dead because the people who make servers didn’t adapt to today’s reality. People are getting older, life moves faster, there are more responsibilities, and less free time. And I’m not even talking about newcomers—how can you expect someone new to this game to learn by Googling every drop location or quest requirement? These things should’ve been integrated into the game, made accessible with just a few clicks through the interface. Instead, so much time was wasted trying to recreate retail-like features that no one asked for. Everyone hates autofarm, but why? Because admins never found a smart way to implement it. You could have made it available only in specific zones, with reduced drops, working like Adrenaline, or auto-teleporting to farm for a limited time per day—just enough to help people with limited time stay relevant in-game. There should also be zones with better drops, where active farming actually matters. Other features feel pointless—like the Life Stone system. Spamming LS to get a skill? Instead, you could create a system where you level up the skill with low chances per level, something that feels progressive and fair. Crafting should be simpler too. Right-click a recipe, and the required materials should show up right there. As for sieges, why not create daily clan war events at peak hours—one for Europeans, one for Latinos? You could spawn crystals inside or outside castles that give points and trigger PvP. Add a boss during the event that gives even more points, and let the top clan in the ranking take the castle. I could go on forever, but what’s the point? The community died because the people who had the knowledge to improve the game just took the easy way out, copying the same server formula over and over until no one could enjoy playing it anymore.
    • It's not because I'm an admin that he treated me differently. I actually gave him several clients from my side without him even knowing they came from me, and most of them had no issues. I was also waiting 3–4 weeks at times for things I bought from AvE, even when I was in a rush. He still delivered in the end. That said, I'm not defending him blindly. I'm just saying it's unlikely he’d risk scamming someone over 60–100€, especially knowing how quickly word spreads here.
    • For exact same reason - there were accusation that I scammed. When was it? 2016? But in that time, admins actually didn't listen. I got banned, then unbaned (when I prooved I've refunded) but I was trash talking to mods. When few months later same shit happened, Grisom (?) old global mod, banned me anyway. You can read somewhere on forum how I was shitting on him for doing that (from other account because original account was banned) - which was banned too. He is not here anymore I think. Back in the days I was well know for not carring that much if I was talking to mod or admin, I didn't hold my tongue. Now You know. Just like You know - if I delay, I deliver or refund. I'm not a scammer, even if my old time haterz love to repeat themselfs like mantra. I don't care.
    • Okay I respect that but why is your other account banned?   I don't think this happened just because you delayed somebodys work even in 2012
  • Topics

×
×
  • Create New...