Added target lost event. Added all new NPC events to the old 1.7.10 script system.

This commit is contained in:
Luis C.M committed 2023-03-16 04:56:33 -05:00
1 parent 29935a1c6d
commit fe780d69ee
9 files changed
+39 -8

No files matched your search

+10
View File
@@ -204,6 +204,16 @@ public class EventHooks {
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onNPCTargetLost(EntityNPCInterface npc, EntityLivingBase prevtarget, EntityLivingBase newTarget) {
if(npc.script.isClient())
return false;
NpcEvent.TargetLostEvent event = new NpcEvent.TargetLostEvent(npc.wrappedNPC, prevtarget, newTarget);
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TARGET_LOST, event);
npc.script.callScript(EnumScriptType.TARGET_LOST, event);
return NpcAPI.EVENT_BUS.post(event);
}
public static void onNPCCollide(EntityNPCInterface npc, Entity entity){
if(npc == null || npc.wrappedNPC == null)
return;
@@ -63,6 +63,9 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
list.add("script.kills");
list.add("script.dialog_closed");
list.add("script.timer");
list.add("script.targetLost");
list.add("script.projectileTick");
list.add("script.projectileImpact");
if(showScript){
addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5));
@@ -29,6 +29,9 @@ public class GuiNPCEventScripts extends GuiScriptInterface {
hookList.add("kills");
hookList.add("dialogClose");
hookList.add("timer");
hookList.add("targetLost");
hookList.add("projectileTick");
hookList.add("projectileImpact");
this.script = new DataScript(npc);
this.handler = this.script;
@@ -26,6 +26,9 @@ public class GuiScriptAllNPCs extends GuiScriptInterface {
hookList.add("kills");
hookList.add("dialogClose");
hookList.add("timer");
hookList.add("targetLost");
hookList.add("projectileTick");
hookList.add("projectileImpact");
this.handler = this.script;
Client.sendData(EnumPacketServer.ScriptGlobalNPCGet);
@@ -13,10 +13,12 @@ public enum EnumScriptType {
KILLS("kills"),
DIALOG_CLOSE("dialogClose"),
TIMER("timer"),
TARGET_LOST("targetLost"),
PROJECTILE_TICK("projectileTick"),
PROJECTILE_IMPACT("projectileImpact"),
ATTACKED("attacked"),
ATTACK_MELEE("meleeAttack"),
TARGET_LOST("targetLost"),
ROLE("role"),
RANGED_CHARGE("rangedCharge"),
RANGED_LAUNCHED("rangedLaunched"),
@@ -41,8 +43,6 @@ public enum EnumScriptType {
TOSSED("tossed"),
PICKEDUP("pickedUp"),
PICKUP("pickUp"),
PROJECTILE_TICK("projectileTick"),
PROJECTILE_IMPACT("projectileImpact"),
LEVEL_UP("levelUp"),
KEY_PRESSED("keyPressed"),
QUEST_EVENT("questEvent"),
@@ -48,7 +48,7 @@ public class DataScript implements IScriptHandler {
public boolean hasInited = false;
public DataScript(EntityNPCInterface npc) {
for (int i = 0; i < 12; i++) {
for (int i = 0; i < 15; i++) {
scripts.add(new ScriptContainer(this));
}
@@ -551,6 +551,9 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
entity = null;
else
entity = event.getTarget().getMCEntity();
} else {
if(EventHooks.onNPCTargetLost(this, getAttackTarget(), entity))
return;
}
if (entity != null && entity != this && ai.onAttack != 3 && !isAttacking()) {
Line line = advanced.getAttackLine();
@@ -420,11 +420,13 @@ public class NpcEvent extends CustomNPCsEvent implements INpcEvent {
@Cancelable
public static class TargetLostEvent extends NpcEvent implements INpcEvent.TargetLostEvent {
public final IEntityLivingBase entity;
public final IEntityLivingBase oldTarget;
public final IEntityLivingBase newTarget;
public TargetLostEvent(ICustomNpc npc, EntityLivingBase entity) {
public TargetLostEvent(ICustomNpc npc, EntityLivingBase oldTarget, EntityLivingBase newTarget) {
super(npc);
this.entity = (IEntityLivingBase) NpcAPI.Instance().getIEntity(entity);
this.oldTarget = (IEntityLivingBase) NpcAPI.Instance().getIEntity(oldTarget);
this.newTarget = (IEntityLivingBase) NpcAPI.Instance().getIEntity(newTarget);
}
public String getHookName() {
@@ -432,7 +434,11 @@ public class NpcEvent extends CustomNPCsEvent implements INpcEvent {
}
public IEntityLivingBase getTarget() {
return entity;
return oldTarget;
}
public IEntityLivingBase getNewTarget() {
return newTarget;
}
}