Page 1 of 1

Little help over here :P

Posted: Mon Jul 01, 2013 10:39 pm
by HyperByter
If you want to receive support we need this info to help you properly.
» Find Revision
L2J Revision 6040M:
L2JDP Revision 9776:

Ok guys i tried to fix this problem for hours but unsuccessfully, so now its time to get help from better devs than me lol :P i m trying to make some custom castle battle event ( i will contribute it to L2J as soon as its finished )

Code: Select all

 /* * Copyright (C) 2004-2013 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 *fork*.CastleBattle; import java.util.Calendar;import java.util.logging.Logger; import com.l2jserver.gameserver.Announcements;import com.l2jserver.gameserver.ThreadPoolManager;import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage; /** * @author HyperByter * @version Beta * @build 2.7.2013 */ public class CastleBattle{    private static Logger _log = Logger.getLogger("CastleBattle");        private static String htm_path = "data/scripts/*fork*/CastleBattle/";    private static int CB_State = 1; // 0 - Disabled, 1 - Not in progress, 2 - Participation, 3 - Running, 4 - Event ended        // Initialize Engine    private static void CB_Init()    {        if (CB_State != 0)        {            SetStartTime();        }    }        // Event Loop    public static void SetStartTime()    {        Calendar _nextTime = Calendar.getInstance();        int _m = _nextTime.get(Calendar.MINUTE);        int x = 1;        while (_m > 5)        {            _m -= 5;            x++;        }        _nextTime.set(Calendar.MINUTE, x * 5);        ThreadPoolManager.getInstance().scheduleGeneral(new CastleBattleLoop(), _nextTime.getTimeInMillis() - System.currentTimeMillis());    }        // Allow players to participate in the event    public static void StartParticipation()    {        CB_State = 2;        Announcements.getInstance().announceToAll("Castle Battle participation has started.");        _log.info("Castle Battle participation has started.");    }        // Player requests to join event via NPC    public static void CB_bypass(String _cmd, L2PcInstance _player)    {        if (_cmd.startsWith("InitHtmlRequest"))        {            if (CB_State == 0)            {                NpcHtmlMessage _html = new NpcHtmlMessage(0);                _html.setFile("", htm_path + "CB_Disabled.htm");                _player.sendPacket(_html);            }            if (CB_State == 1)            {                NpcHtmlMessage _html = new NpcHtmlMessage(0);                _html.setFile("", htm_path + "CB_NotInProgress.htm");                _player.sendPacket(_html);            }            if (CB_State == 2)            {                NpcHtmlMessage _html = new NpcHtmlMessage(0);                _html.setFile("", htm_path + "CB_Participate.htm");                _player.sendPacket(_html);            }        }    }        public static void main(String[] args)    {        _log.info("# Castle Battle Engine #");        _log.info("Author : HyperByter");        _log.info("Version : Beta");        _log.info("Version : 2.7.2013");        CastleBattle.CB_Init();    }    } class CastleBattleLoop implements Runnable{    @Override    public void run()    {        CastleBattle.StartParticipation();    }} 
everything works fine without errors, but the problem is that variable CB_State doesnt change after starting participation, it still says its 1 ( not in progress ). i rly got no idea what more to change to get it working...

thx for your help ;)

[EDIT] : i see that l2()dc string was replaced with *fork* but it isnt from fork, its shortened name of my server.

Re: Little help over here :P

Posted: Tue Jul 02, 2013 9:52 am
by BiggBoss
replace

Code: Select all

 class CastleBattleLoop implements Runnable{    @Override    public void run()    {        CastleBattle.StartParticipation();    }} 
for

Code: Select all

 static class CastleBattleLoop implements Runnable{    @Override    public void run()    {        CastleBattle.StartParticipation();    }} 
EDIT: And make it inner class

Re: Little help over here :P

Posted: Tue Jul 02, 2013 9:56 am
by HyperByter
ok i did, but now i m getting error :

Illegal modifier for the class CastleBattleLoop; only public, abstract & final are permitted

Re: Little help over here :P

Posted: Tue Jul 02, 2013 9:57 am
by BiggBoss
HyperByter wrote:ok i did, but now i m getting error :

Illegal modifier for the class CastleBattleLoop; only public, abstract & final are permitted
yeah, i edited the post while you was changing :mrgreen:
Make it inner class

Re: Little help over here :P

Posted: Tue Jul 02, 2013 10:07 am
by HyperByter
mhm i m not sure if i understood correctly, so i should put CastleBattleLoop class inside CastleBattle class ?
If yes i did but now how to call this class with scheduled function ? new CastleBattleLoop() doesnt work :P

Anyway i dont think its cuz of this loop class, i tried to call StartParcitipation method directly from SetStartTime and same shit happened :D CB_State value didnt change. looks like i need to declare it in other way, but i m not that pro in java lol

Re: Little help over here :P

Posted: Tue Jul 02, 2013 10:10 am
by BiggBoss
dunno what are you doing wrong or what is going wrong, but the code does not seems to have any problem

Re: Little help over here :P

Posted: Tue Jul 02, 2013 10:13 am
by HyperByter
yep its pretty obvious cuz i didnt find any problem with it aswell except of this never changing int value. maybe there is some other detail which i missed and thats why it isnt working properly, well lets see what other devs will suggest, anyway thx for your help dude ;)

Re: Little help over here :P

Posted: Sun Jul 07, 2013 8:24 pm
by Zoey76

Re: Little help over here :P

Posted: Mon Jul 08, 2013 12:24 am
by HyperByter
thx for answer Zoey :P

so the result of your enhancement is following :

When I tried to talk to npc which holds this script before event started, it wrote "Castle Battle is not currently running"... which is OK, but then event didnt start at all, so I restarted server and didnt talk to npc before event started ( then it did ) but then when I spoke to to it, it still said "Castle Battle is not currently running"

I bypassed CB_bypass function thru getInstance method but you see what it did.. anyway I managed to learn something about those Singletons methods before you responded, and got it partially working with the following code ( it got expanded a little in meanwhile ) :

http://pastebin.com/vjxCtBEv

The only one problem is that it starts only when I talk to npc at least once, then participation starts properly at time which is defined at SetStartTime.

So I tried to put CastleBattle.getInstance.CB_bypass("",null) to main method so the instance get automatically initialized, but then the result was that participation started twice ( once automatically, 2nd time when I spoke to NPC )
Well I guess I shouldn't put anything inside class constructor, but then the result will be that participation starts automatically if I call CB_Init from main method thru getInstance, but after that, NPC will say that Castle Battle engine is disabled ( int CB_State = 0 );

[EDIT] : NPC bypass script : http://pastebin.com/6asNEEK8