Thanks to DnR's implementation of the latest L2j Geoengine i finally was able to finish my FleeingNpc AI.
Before the Geodata "canMove" check i was using the Fear skill effect on attack.
But that wasnt retail like at all.
It works like a charm now.
They will avoid walls ,and dont get stuck anymore.
Enjoy.
FleeingNpc.java
Before the Geodata "canMove" check i was using the Fear skill effect on attack.
But that wasnt retail like at all.
It works like a charm now.
They will avoid walls ,and dont get stuck anymore.
Enjoy.
- Code:
Index: scripts.cfg
===================================================================
--- scripts.cfg (revision 614)
+++ scripts.cfg (working copy)
@@ -12,6 +12,7 @@
ai/group_template/devils_isle.py
ai/group_template/fairy_trees.py
ai/group_template/feedable_beasts.py
+ai/group_template/FleeingNpc.java
ai/group_template/FrenzyOnAttack.java
FleeingNpc.java
- Code:
/*
* 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.group_template;
import net.sf.l2j.Config;
import net.sf.l2j.gameserver.ai.CtrlIntention;
import net.sf.l2j.gameserver.geoengine.GeoData;
import net.sf.l2j.gameserver.model.L2CharPosition;
import net.sf.l2j.gameserver.model.L2Object;
import net.sf.l2j.gameserver.model.L2Skill;
import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.model.quest.Quest;
import net.sf.l2j.util.Rnd;
/*
* Elpies and Four Sepulcher victims AI.<br>
* By Karakan for L2JLisvus
*/
public class FleeingNpc extends Quest
{
private static final int ELPY = 432;
private static final int VICTIM = 12985;
private static final int VICTIM2 = 12986;
private static final int VICTIM3 = 12987;
private static final int VICTIM4 = 12988;
private static final int VICTIM5 = 12989;
private static final int VICTIM6 = 12990;
private static final int VICTIM7 = 12991;
private static final int VICTIM8 = 12992;
public FleeingNpc (int questId, String name, String descr)
{
super(questId, name, descr);
int[] mobs =
{
ELPY,
VICTIM,
VICTIM2,
VICTIM3,
VICTIM4,
VICTIM5,
VICTIM6,
VICTIM7,
VICTIM8
};
registerMobs(mobs);
}
@Override
public String onAttack(L2NpcInstance npc, L2PcInstance attacker, int damage, boolean isPet)
{
final int rndX = npc.getX() + Rnd.get(-Config.MAX_DRIFT_RANGE, Config.MAX_DRIFT_RANGE); //Could be increased (+-500 for Dungeons, +-1000 for Hunting Grounds)
final int rndY = npc.getY() + Rnd.get(-Config.MAX_DRIFT_RANGE, Config.MAX_DRIFT_RANGE);
npc.disableCoreAI(true);
if (!npc.isMoving() && GeoData.getInstance().canMove(npc.getX(), npc.getY(), npc.getZ(), rndX, rndY, npc.getZ()))
{
npc.setRunning();
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(rndX, rndY, npc.getZ(), 0));
}
return super.onAttack(npc, attacker, damage, isPet);
}
@Override
public String onSkillSee(L2NpcInstance npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
{
final int rndX = npc.getX() + Rnd.get(-Config.MAX_DRIFT_RANGE, Config.MAX_DRIFT_RANGE); /
final int rndY = npc.getY() + Rnd.get(-Config.MAX_DRIFT_RANGE, Config.MAX_DRIFT_RANGE);
npc.disableCoreAI(true);
if (skill.isOffensive() && targets[0] == npc)
{
if (!npc.isMoving() && GeoData.getInstance().canMove(npc.getX(), npc.getY(), npc.getZ(), rndX, rndY, npc.getZ()))
{
npc.setRunning();
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(rndX, rndY, npc.getZ(), 0));
}
}
return super.onSkillSee(npc, caster, skill, targets, isPet);
}
// Register the new Script at the Script System
public static void main(String[] args)
{
new FleeingNpc(-1, "fleeingnpc", "ai/group_template");
}
}
Last edited by Karakan on 12th July 2019, 15:28; edited 1 time in total