[Help] Thread management + DM Event

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
User avatar
rychoo84
Posts: 58
Joined: Fri Jan 01, 2010 11:26 am
Location: Breslau

[Help] Thread management + DM Event

Post by rychoo84 »

L2J Revision n/a
L2JDP Revision n/a

Hi,
First of all I'd like to aplogize if this topic doesn't fit the section (don't want to spam useless posts in order to become able to write in Custom section. If it's possible please move this topic into the right section, thank you

I'm writing my own DM (Last man standing type) event based on already existing TvT files. The main part is working fine, except when one participant is left, the event is running until the time is over (and it should end after there's only one player left).

after every call of OnKill method killed participant is being removed (that part works fine) from the event.
Ofc REWARDING state is set only when there's one guy left (that works fine too)

Code: Select all

 if(_players[0].getParticipatedPlayerCount() == 1){	setState(EventState.REWARDING);	rewardDmWinner(_players[0]);} 
I also have made a method, which checks if there's only on guy left:

Code: Select all

 public static boolean CheckDmPlayerCountEqualToOne(){	if(_players[0].getParticipatedPlayers().size() == 1)		return true; 	return false;} 
Now I'm checking for these conditions inside the DmManager class (equivalent of TvTManager)

Code: Select all

 public void run(){	int delay = (int) Math.round((_startTime - System.currentTimeMillis()) / 1000.0); 	if (delay > 0)	{	      this.announce(delay);	} 	int nextMsg = 0;	if (delay > 3600)	{		nextMsg = delay - 3600;	}	else if (delay > 1800)	//..... 	else	{	   // start	   if (DmEvent.isInactive())	   {		DmManager.this.startReg();	   }	   else if (DmEvent.isParticipating())	   {		DmManager.this.startEvent();	   }	  else	   {		DmManager.this.endEvent();	    }       } 	if (delay > 0)	{	       //here it is		[color=#00BF40]if(DmEvent.isStarted() && DmEvent.CheckDmPlayerCountEqualToOne())		{			DmManager.this.endEvent();		}[/color] 		nextRun = ThreadPoolManager.getInstance().scheduleGeneral(this, nextMsg * 1000);	}} 
I must have forgot something, probably need to stop the thread somehow. Could you give me some hints how make it work?
Thx in advance
Tom
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: [Help] Thread management + DM Event

Post by jurchiks »

where's the endEvent method itself?
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
User avatar
rychoo84
Posts: 58
Joined: Fri Jan 01, 2010 11:26 am
Location: Breslau

Re: [Help] Thread management + DM Event

Post by rychoo84 »

it's totally unchanged (if speaking about TvT eqiuvalent it's in TvT Manager class)

Code: Select all

 public void endEvent()	{		Announcements.getInstance().announceToAll(DmEvent.calculateRewards()); 		DmEvent.sysMsgToAllParticipants("DM Event: Teleporting back to the registration npc in "				+ Config.DM_EVENT_START_LEAVE_TELEPORT_DELAY + " second(s).");		DmEvent.stopFight(); 		this.scheduleEventStart();	} 

Stop Fight (also unchanged, equivalent in TvTEvent class)

Code: Select all

 public static void stopFight()	{			// Set state INACTIVATING		setState(EventState.INACTIVATING); 		//Unspawn event npc		unSpawnNpc(); 		// Opens all doors specified in configs for dm		openDoors(Config.DM_DOORS_IDS_TO_CLOSE); 		// Closes all doors specified in Configs for dm		closeDoors(Config.DM_DOORS_IDS_TO_OPEN); 		// Iterate over all teams		for (DmEventTeam team : _players)		{			for (L2PcInstance playerInstance : team.getParticipatedPlayers().values())			{				// Check for nullpointer				if (playerInstance != null)				{					new DmEventTeleporter(playerInstance, Config.DM_EVENT_PARTICIPATION_NPC_COORDINATES, false, false);				}			}		} 		// Cleanup of teams		_players[0].cleanMe(); 		// Set state INACTIVE		setState(EventState.INACTIVE);	} 
Last edited by rychoo84 on Thu Jul 15, 2010 12:34 pm, edited 1 time in total.
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: [Help] Thread management + DM Event

Post by jurchiks »

and stopFight()?
i'm not searching this in epilogue code since i'm not working with it atm.
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
User avatar
Raikkon35
Posts: 178
Joined: Sat Mar 08, 2008 2:54 pm

Re: [Help] Thread management + DM Event

Post by Raikkon35 »

Under my limited knowledge of Java, I think you should add the check in onkill.
And then, start the endEvent.
User avatar
rychoo84
Posts: 58
Joined: Fri Jan 01, 2010 11:26 am
Location: Breslau

Re: [Help] Thread management + DM Event

Post by rychoo84 »

Raikkon35 wrote:Under my limited knowledge of Java, I think you should add the check in onkill.
And then, start the endEvent.
your modesty is unlimited...
Exactly this is what I was looking for :)
put this into onKill method:

Code: Select all

 if(CheckDmPlayerCountEqualToOne())      DmManager.getInstance().endEvent(); 
Thx for your tip Raikkon35
Post Reply