Custom NPC with condition

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
Lyan
Posts: 66
Joined: Sat Nov 05, 2011 9:55 am

Custom NPC with condition

Post 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?
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Custom NPC with condition

Post by jurchiks »

Don't write jython scripts, support for jython will be removed in future.
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.
Lyan
Posts: 66
Joined: Sat Nov 05, 2011 9:55 am

Re: Custom NPC with condition

Post 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
NosBit
L2j Veteran
L2j Veteran
Posts: 314
Joined: Mon Mar 11, 2013 4:19 pm

Re: Custom NPC with condition

Post 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.
Image
Lyan
Posts: 66
Joined: Sat Nov 05, 2011 9:55 am

Re: Custom NPC with condition

Post 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");    }}
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Custom NPC with condition

Post by jurchiks »

Code: Select all

FourLeaf Golden Clover Coin
WTF is that? That is not a valid variable name, of course it won't work.
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.
Lyan
Posts: 66
Joined: Sat Nov 05, 2011 9:55 am

Re: Custom NPC with condition

Post by Lyan »

Changed, still doesn't work. It doesn't compile.
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Custom NPC with condition

Post by jurchiks »

http://docs.oracle.com/javase/tutorial/ ... ables.html
You probably didn't change all 3 places where the variable name is used.
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.
Lyan
Posts: 66
Joined: Sat Nov 05, 2011 9:55 am

Re: Custom NPC with condition

Post by Lyan »

jurchiks wrote:http://docs.oracle.com/javase/tutorial/ ... ables.html
You probably didn't change all 3 places where the variable name is used.

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?
Sdw
L2j Veteran
L2j Veteran
Posts: 855
Joined: Mon May 03, 2010 8:38 am
Location: France

Re: Custom NPC with condition

Post by Sdw »

Code: Select all

new FourLeaf(FourLeaf.class.getSimpleName() custom\FourLeaf");
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Custom NPC with condition

Post by jurchiks »

How about you do this: http://www.l2jserver.com/wiki/Setup_Eclipse_and_SVN
and then you'll see for yourself.
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.
Hyrelius
Posts: 257
Joined: Thu Dec 16, 2010 5:16 am

Re: Custom NPC with condition

Post 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.
Image
I don't mind helping - however: I only do so if I want to.
No support for other server packs than L2J.
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Custom NPC with condition

Post 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.
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.
Hyrelius
Posts: 257
Joined: Thu Dec 16, 2010 5:16 am

Re: Custom NPC with condition

Post 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.
Image
I don't mind helping - however: I only do so if I want to.
No support for other server packs than L2J.
Lyan
Posts: 66
Joined: Sat Nov 05, 2011 9:55 am

Re: Custom NPC with condition

Post 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?
Post Reply