W dzisiejszym poradniku dowiemy się jak stworzyć własną
/komende . Wiele osób wie już pewnie jak zrobić
.komende , ale wg mnie ta pierwsza wygląda zdecydowanie lepiej , a więc dzisiaj nauczymy się taką przygotować .
Trzeba pamiętać jednak , że taka komenda wymaga modyfikacji systemu ! Co jest nie legalne ( Jednak z tego poradnika można dowiedzieć się jak edytować już gotowe komendy )
Czego potrzebujemy :- FileEdit
- Pliki L2J
Jak już pewnie wiadomo , na plikach L2J handlersy zostały przerzucone do DataPacku , a więc nie musimy ich kompilować (zostawiamy w postaci .java ) Ok , a więc zaczynamy .
1. Krok Pierwszy :Udajemy się do folderu :
data\scripts\handlers\usercommandhandlers
2. Krok Drugi :Tworzymy nowy plik
.java . W tym poradniku ja użyję
ServerInfo.java3. Krok Trzeci :Ok , mamy nasz plik
.java , a więc teraz go otwieramy i piszemy :
/*
* 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/>.
*/
- Wiadomo , to jest licencja GNU - nie zapominamy o niej na początku .
W tym przypadku robimy komendę , która wywoła okno html w grze , a więc importujemy odpowiednie klasy :
package handlers.usercommandhandlers;
import net.sf.l2j.gameserver.handler.IUserCommandHandler;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
Ok , zaimportowaliśmy odpowiednie classy z core , teraz przygotujemy naszą
classe :
public class ServerInfo implements IUserCommandHandler
{
private static final int[] COMMAND_IDS =
{
121
};
Naszą klase nazwałęm
ServerInfo- Teraz można zapytać . Ok , ale co oznacza to ID ? ( w tym przypadku my mamy 121 ) Odpowiedź jest prosta :Jest to ID z naszego clienta gry . Definiujemy to w pliku
commandname-e.dat . Otwórz ten plik za pomocą FileEdita . Powinieneś zobaczyć coś takiego :
- Pierwsza kolumna jest przeznaczona na numer komendy ( wiadomo , kolejno 1,2,3,4,5,6,7 itd ... ) Ostatnia była 121 czyli piszemy 122
- Druga kolumna jest przeznaczona na
ID , które omówiłem wyżej . Ostatnie było 120 , a więc ID piszmy
121 ( te samo ID wpisaliśmy do skryptu naszej komendy ! )
- W trzeciej kolumnie wpisujemy frazę na jaką będzie wywoływana dana komenda . My chcemy mieć komendę
/serverinfo , a więc wpisujemy :
[quote]a,[b]serverinfo[/b]\0[/quote]
Powinno wyglądać to tak :
- Zapisz i zamknij nasz plik .
Teraz piszemy dalej nasz skrypt do komendy . Dodajemy coś takiego :
/**
*
* @see net.sf.l2j.gameserver.handler.IUserCommandHandler#useUserCommand(int, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance)
*/
public boolean useUserCommand(int id, L2PcInstance activeChar)
{
if (id != COMMAND_IDS[0])
return false;
NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
npcHtmlMessage.setHtml("<html><head><title>Title</title></head><body>Tu wpisz Twój text jak będzie miał się pojawić w oknie po wywołaniu komendy !</body></html>");
activeChar.sendPacket(npcHtmlMessage);
return true;
}
/**
*
* @see net.sf.l2j.gameserver.handler.IUserCommandHandler#getUserCommandList()
*/
public int[] getUserCommandList()
{
return COMMAND_IDS;
}
}
Jest to funkcja , która wywoła nam naszą komendę . W tym przypadku wyświetli okno html . Teraz trochę objaśnienia :
if (id != COMMAND_IDS[0])
return false;
Jeśli ktoś używa komendy z Innym ID niż zdefiniowane wyżej , ma nic nie robić ( return false; )
NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
npcHtmlMessage.setHtml("<html><head><title>Title</title></head><body>Your Text Here</body></html>");
activeChar.sendPacket(npcHtmlMessage);
return true;
}
Tu podajemy co ma się stać gdy grasz wywoła komendę z ID zdefiniowanym u góry . Czyli wywołać okienko
Na koniec skryptu dodajemy :
/**
*
* @see net.sf.l2j.gameserver.handler.IUserCommandHandler#getUserCommandList()
*/
public int[] getUserCommandList()
{
return COMMAND_IDS;
}
}
Tak aby nasz końcowy , cały skrypt wyglądał tak :
/*
* 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 handlers.usercommandhandlers;
import net.sf.l2j.gameserver.handler.IUserCommandHandler;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
/**
* Support for /serverinfo command
* Added by Matim & Impos89 !
*/
public class ServerInfo implements IUserCommandHandler
{
private static final int[] COMMAND_IDS =
{
121
};
/**
*
* @see net.sf.l2j.gameserver.handler.IUserCommandHandler#useUserCommand(int, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance)
*/
public boolean useUserCommand(int id, L2PcInstance activeChar)
{
if (id != COMMAND_IDS[0])
return false;
NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
npcHtmlMessage.setHtml("<html><head><title>Title</title></head><body>Tutaj podajesz Twoj text..</body></html>");
activeChar.sendPacket(npcHtmlMessage);
return true;
}
/**
*
* @see net.sf.l2j.gameserver.handler.IUserCommandHandler#getUserCommandList()
*/
public int[] getUserCommandList()
{
return COMMAND_IDS;
}
}
Ok , nasza komenda jest gotowa . Ostatnim krokiem jest dodanie naszego skryptu do pliku
MasterHandler.java , który znajduje się w
\data\scripts\handlers
- Otwórz ten plik i w pierwszej kolumnie odszukaj tych linijek :
import handlers.usercommandhandlers.ChannelDelete;
import handlers.usercommandhandlers.ChannelLeave;
import handlers.usercommandhandlers.ChannelListUpdate;
import handlers.usercommandhandlers.ClanPenalty;
import handlers.usercommandhandlers.ClanWarsList;
import handlers.usercommandhandlers.DisMount;
import handlers.usercommandhandlers.Escape;
import handlers.usercommandhandlers.InstanceZone;
import handlers.usercommandhandlers.Loc;
import handlers.usercommandhandlers.Mount;
import handlers.usercommandhandlers.OlympiadStat;
import handlers.usercommandhandlers.PartyInfo;
import handlers.usercommandhandlers.Time;
W kolejności alfabetycznej dodajemy ( taki standard ) :
import handlers.usercommandhandlers.ServerInfo;
Teraz odszukaj takiej kolumny :
private static void loadUserHandlers()
{
UserCommandHandler.getInstance().registerUserCommandHandler(new ClanPenalty());
UserCommandHandler.getInstance().registerUserCommandHandler(new ClanWarsList());
UserCommandHandler.getInstance().registerUserCommandHandler(new DisMount());
UserCommandHandler.getInstance().registerUserCommandHandler(new Escape());
UserCommandHandler.getInstance().registerUserCommandHandler(new InstanceZone());
UserCommandHandler.getInstance().registerUserCommandHandler(new Loc());
UserCommandHandler.getInstance().registerUserCommandHandler(new Mount());
UserCommandHandler.getInstance().registerUserCommandHandler(new PartyInfo());
UserCommandHandler.getInstance().registerUserCommandHandler(new Time());
UserCommandHandler.getInstance().registerUserCommandHandler(new OlympiadStat());
UserCommandHandler.getInstance().registerUserCommandHandler(new ChannelLeave());
UserCommandHandler.getInstance().registerUserCommandHandler(new ChannelDelete());
UserCommandHandler.getInstance().registerUserCommandHandler(new ChannelListUpdate());
UserCommandHandler.getInstance().registerUserCommandHandler(new ServerInfo());
_log.config("Loaded " + UserCommandHandler.getInstance().size() + " UserHandlers");
}
I dodaj to :
UserCommandHandler.getInstance().registerUserCommandHandler(new ServerInfo());
(pod : UserCommandHandler.getInstance().registerUserCommandHandler(new ChannelListUpdate()); )
Zapisujemy i zamykamy , gotowe . Zrestartuj Swój server i w grze wpisz
/serverinfoPodziękowania dla :
Impos89
Jest to podstawowa komenda , która wywołuje jedynie okienko . W najbliższym czasie przedstawię bardziej rozbudowane komendy .