how to set player fleeing

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

how to set player fleeing

Post by jurchiks »

Got one quest that in l2off sends the player running away from npc while the npc itself despawns in 2 seconds.
Does anyone know how to make it happen (make the player flee)?
l2off method is AddFleeDesire(player, 1000000) so I'm guessing it either has some globally used npc skill (perhaps 5259?) or no visible skill at all.
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
MELERIX
L2j Veteran
L2j Veteran
Posts: 6667
Joined: Sat Sep 23, 2006 11:31 pm
Location: Chile
Contact:

Re: how to set player fleeing

Post by MELERIX »

flee = fear effect
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: how to set player fleeing

Post by jurchiks »

that doesn't help me, I already know that...
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.
drizzlx
Posts: 13
Joined: Mon Jul 16, 2012 6:53 pm

Re: how to set player fleeing

Post by drizzlx »

You could just bestow the fear effect on the player... I don't know if there is an actual method to make them flee but that's how I would do it.
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: how to set player fleeing

Post by jurchiks »

Yeah but I need the specific effect. I can't just use any skill, there's probably one specifically designed for this, because this one isn't supposed to be resisted (and AFAIK you can resist fear normally).
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.
RogerSmith
Posts: 69
Joined: Fri Oct 01, 2010 11:57 am

Re: how to set player fleeing

Post by RogerSmith »

jurchiks wrote:Yeah but I need the specific effect. I can't just use any skill, there's probably one specifically designed for this, because this one isn't supposed to be resisted (and AFAIK you can resist fear normally).
why can't you force it in the NPC AI or something


like the stun on antharas skills isn't/wasn't done in XML, it was hardcoded into the JUMP skilltype/flytype
Can't remember, but basically one of antharas skills used to lift people up and throw them in an arc and had a stun in core.


edit: the skilltype was THROW_UP

Can't find the stuff anymore
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: how to set player fleeing

Post by jurchiks »

I believe there is a debuff icon in debuff bar when this happens.
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.
RogerSmith
Posts: 69
Joined: Fri Oct 01, 2010 11:57 am

Re: how to set player fleeing

Post by RogerSmith »

jurchiks wrote:I believe there is a debuff icon in debuff bar when this happens.
you find it necessary?

Know any other NPCs that bestow buffs, debuff? Perhaps check newbie helper?

Then there is the Fear.java in effecthandlers.

It has methods like startFear or something
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: how to set player fleeing

Post by jurchiks »

Well, for the first thing, I don't even know how long that stuff should last, so if it's a skill I wouldn't have to worry about that part.

And Fear effecthandler has no methods for calling the effect directly (I suppose you could construct the effect, but I have no idea what the Env parameter should contain).

In short, I'm asking for code to make an L2PcInstance run away from L2Npc (two known parameters, dunno about anything else).

Edit: ok, since nobody could say for sure what it does, got the answer in some other forum. AddFleeDesire makes the NPC run away from the player, and the other parameter is apparently for how long to run away.
So now I just gotta find out how to do that, but it should be easy because no skills involved, just AI.
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
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: how to set player fleeing

Post by jurchiks »

Can anyone at least tell me how to calculate the distance an npc can run in a given time interval?
Should be npc.getRunSpeed() * timeInSecondsOrMs * something that I don't know. Unless the walk/run speed means exactly how many units the npc can run in a second, but then I need confirmation.

P.S. I'm using "npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location(x, y, z));" to move the npc, since there seem to be no methods to achieve this directly in the L2Npc class (which is really weird tbh).
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.
RogerSmith
Posts: 69
Joined: Fri Oct 01, 2010 11:57 am

Re: how to set player fleeing

Post by RogerSmith »

A hunch, not real numbers, is that the run speed in stat window is the distance in ingame units you can run in a second.
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: how to set player fleeing

Post by jurchiks »

Yeah, I'm guessing that too, but I'd really like to know if that's actually true. It's like nobody knows...
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.
HorridoJoho
L2j Senior Developer
L2j Senior Developer
Posts: 795
Joined: Sun Aug 14, 2005 11:27 am

Re: how to set player fleeing

Post by HorridoJoho »

Actually you can take a look into L2Character#updatePosition() which is called by GameTimeControler.MoveObjects task.

This code tells ya

Code: Select all

 MOVE_SPEED * (CUR_GTC_TICKS - LAST_POS_UPD_GTC_TICKS) / GTC_TICKS_PER_SECOND 
which means how much in a second. GTC stands for GameTimeControler.

However, when you want a NPC to flee by AI from the player, you don't need to worry about that.
You simply duplicate what is written in the FEAR effect handler. It would be the simplest to do it with a simple npc
since with hardcoded moving and skillsusing objects you would have to intercept this.

An example for an npc which just stands around and is fleeing on onTalk would be:

Code: Select all

 /* * 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 ai.individual; import java.util.concurrent.ConcurrentHashMap; import com.l2jserver.Config;import com.l2jserver.gameserver.GameTimeController;import com.l2jserver.gameserver.GeoData;import com.l2jserver.gameserver.ai.CtrlIntention;import com.l2jserver.gameserver.model.L2CharPosition;import com.l2jserver.gameserver.model.Location;import com.l2jserver.gameserver.model.actor.L2Character;import com.l2jserver.gameserver.model.actor.L2Npc;import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;import com.l2jserver.gameserver.model.quest.jython.QuestJython;import com.l2jserver.util.Rnd; import java.util.Iterator;import java.util.Map.Entry; /** * @author FBIagent */public class MyThief extends QuestJython{    private static class FleeInfo    {        public final L2Character fleeTarget;        // flee duration in game ticks        public final int fleeDuration;        public final int fleeStart;         /**         * @param fleeTarget target to flee from         * @param fleeDuration flee duration in seconds         */        protected FleeInfo(final L2Character fleeTarget, final int fleeDuration)        {            this.fleeTarget = fleeTarget;            this.fleeDuration = fleeDuration * GameTimeController.TICKS_PER_SECOND;            this.fleeStart = GameTimeController.getGameTicks();        }    }     private static final int[] _THIEF_IDS = new int[] {0};    private static final String _FLEE_TIMER_NAME = "flee_move_updater";    private static final ConcurrentHashMap<L2Npc, FleeInfo> _FLEEING_THIEFS = new ConcurrentHashMap<>();     public static void main(String[] args)    {        new MyThief(-1, "MyThief", "ai");    }     private static void startFlee(L2Npc npc, L2Character fleeTarget)    {        _FLEEING_THIEFS.put(npc, new FleeInfo(fleeTarget, 10));    }        private static L2CharPosition calculateFleeDestination(L2Npc npc, L2Character fleeTarget)    {        int fleeDistance = Rnd.get((int)(npc.getStat().getMoveSpeed() * 5), (int)(npc.getStat().getMoveSpeed() * 10));         int dstX = 0;        int dstY = 0;        int dstZ = 0;         // TODO: make a proper calculation to actually turn the BACK of the npc towards the flee target an move into this direction         if (Config.GEODATA > 0)        {            Location destiny = GeoData.getInstance().moveCheck(npc.getX(), npc.getY(), npc.getZ(), dstX, dstX, dstZ, npc.getInstanceId());            dstX = destiny.getX();            dstY = destiny.getY();        }         return new L2CharPosition(dstX, dstY, dstZ, 0);    }     public MyThief(int questId, String name, String descr)    {        super(questId, name, descr);        addTalkId(_THIEF_IDS);        startQuestTimer(_FLEE_TIMER_NAME, 100, null, null, true);    }     @Override    public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)    {        if (!_FLEE_TIMER_NAME.equals(event))            return null;         Iterator<Entry<L2Npc, FleeInfo>> iter = _FLEEING_THIEFS.entrySet().iterator();        while (iter.hasNext())        {            Entry<L2Npc, FleeInfo> entry = iter.next();            npc = entry.getKey();            FleeInfo info = entry.getValue();            if (info.fleeStart + info.fleeDuration < GameTimeController.getGameTicks())                iter.remove();                            npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, calculateFleeDestination(npc, info.fleeTarget));        }            return null;    }     @Override    public String onTalk(L2Npc npc, L2PcInstance player)    {        startFlee(npc, player);        return null;    }} 
(Watch out for the TODO)
Post Reply