Page 1 of 2
Custom NPC with condition
Posted: Sat Jan 11, 2014 6:36 pm
by Lyan
Hi
I am currently working on some custom NPC's which you can use only with different conditions, in example: reach level 85, have some random item, finish a quest and etc.
I tried to copy a text from another quests and change some details so it will be appropriate to mine. These were java quest so it didn't work ( I can't change my java files).
Example:
Code: Select all
class Quest (JQuest) : def __init__(self,id,name,descr): JQuest.__init__(self,id,name,descr) def onEvent(self,event,st): htmltext = event count=st.getQuestItemsCount(ADENA_ID) if count < 0 or st.getPlayer().getLevel() < 86 : htmltext = "<html><head><body>Come back later.<br></body></html>" else: st.takeItems(ADENA_ID,0) st.getPlayer().setTarget(st.getPlayer()) QUEST = Quest(QuestId,str(QuestId) + "_" + QuestName,QuestDesc) for npcId in NPCS: QUEST.addStartNpc(npcId) QUEST.addTalkId(npcId)
Anyone can help me to make a Py file so it will work?
Re: Custom NPC with condition
Posted: Sat Jan 11, 2014 6:46 pm
by jurchiks
Don't write jython scripts, support for jython will be removed in future.
Re: Custom NPC with condition
Posted: Sat Jan 11, 2014 6:57 pm
by Lyan
If there is any way to write it with Java but not change it on l2jserver.jar, it will be great.. I don't have the source code
Re: Custom NPC with condition
Posted: Sat Jan 11, 2014 7:45 pm
by NosBit
Look in data/scripts folder for java files for examples we are converting old python scripts to java once its done jython will be removed.
Re: Custom NPC with condition
Posted: Sat Jan 11, 2014 7:49 pm
by Lyan
I already did that but it doesn't work..
Code: Select all
import custom.Four; import com.l2jserver.gameserver.model.actor.L2Npc;import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; public class Four{ // Item private static final int FourLeaf Golden Clover Coin = 7569; // NPCs private static final int[] NPCs = { 36600 }; @Override public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) { if ("teleportWithToken".equals(event)) { if (hasQuestItems(player, FourLeaf Golden Clover Coin)) { npc.showChatWindow(player, 3); } else { return "no-pass.htm"; } } return super.onAdvEvent(event, npc, player); } @Override public String onTalk(L2Npc npc, L2PcInstance player) { return player.isNoble() ? "no-pass.htm" : "no-pass.htm"; } private Four(String name, String descr) { super(name, descr); addStartNpc(NPCs); addTalkId(NPCs); } public static void main(String[] args) { new FourLeaf(FourLeaf.class.getSimpleName(), custom\Four"); }}
Re: Custom NPC with condition
Posted: Sat Jan 11, 2014 7:53 pm
by jurchiks
WTF is that? That is not a valid variable name, of course it won't work.
Re: Custom NPC with condition
Posted: Sun Jan 12, 2014 6:09 pm
by Lyan
Changed, still doesn't work. It doesn't compile.
Re: Custom NPC with condition
Posted: Sun Jan 12, 2014 9:11 pm
by jurchiks
http://docs.oracle.com/javase/tutorial/ ... ables.html
You probably didn't change all 3 places where the variable name is used.
Re: Custom NPC with condition
Posted: Thu Jan 16, 2014 3:12 pm
by Lyan
Code: Select all
import custom.FourLeaf; import com.l2jserver.gameserver.model.actor.L2Npc;import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; public class FourLeaf { // Item private static final int FOURLEAF = 7569; // NPCs private static final int[] NPCs = { 36600 }; @Override public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) { if ("teleportWithToken".equals(event)) { if (hasQuestItems(player, FOURLEAF)) { npc.showChatWindow(player, 3); } else { return "no-pass.htm"; } } return super.onAdvEvent(event, npc, player); } @Override public String onTalk(L2Npc npc, L2PcInstance player) { return player.isNoble() ? "no-pass.htm" : "no-pass.htm"; } private FourLeaf(String name, String descr) { super(name, descr); addStartNpc(NPCs); addTalkId(NPCs); } public static void main(String[] args) { new FourLeaf(FourLeaf.class.getSimpleName() custom\FourLeaf"); }}
What could be wrong now?
Re: Custom NPC with condition
Posted: Thu Jan 16, 2014 3:57 pm
by Sdw
Code: Select all
new FourLeaf(FourLeaf.class.getSimpleName() custom\FourLeaf");
Re: Custom NPC with condition
Posted: Fri Jan 17, 2014 9:59 am
by jurchiks
How about you do this:
http://www.l2jserver.com/wiki/Setup_Eclipse_and_SVN
and then you'll see for yourself.
Re: Custom NPC with condition
Posted: Fri Jan 17, 2014 1:59 pm
by Hyrelius
It also does not extend "L2Script".. if it does not extend it - there's nothing to @override. That's why the code is failing.
You should definitely setup a working development environment in order to not have to ask for help because of such obvious compile-time issues.
Re: Custom NPC with condition
Posted: Fri Jan 17, 2014 2:19 pm
by jurchiks
onTalk/onAdvEvent is defined in Quest, not L2Script. FourLeaf extends AbstractNpcAI is what you're looking for in this case, among other things.
Re: Custom NPC with condition
Posted: Sat Jan 18, 2014 2:39 am
by Hyrelius
Oh I thought he wanted a separate script, which would handle that conditional NPC... could use some AI instead .. so yeah.. my bad.
Re: Custom NPC with condition
Posted: Sat Jan 18, 2014 7:49 pm
by Lyan
Hyrelius wrote:Oh I thought he wanted a separate script, which would handle that conditional NPC... could use some AI instead .. so yeah.. my bad.
What I have to replace?