Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Flags for mobs:
- # .isMob = All hostile mobs should get this one
- # .isMonster = All basic hostiles that need basic targeting and pathing
- # .isBoss = For bosses that do stuff during update.
- # .basicIgnoreTargeting = Hostiles with this flag will be ignored by basic hostiles
- #
- # Runs repeatedly as the mobAI logic loop
- mobAI_task_logic:
- type: task
- debug: false
- script:
- #get all our custom mob npc's
- - event "mobai logic"
- - foreach <server.get_npcs_flagged[mobAI.doLogic]> {
- #logic loop for default mob AI tagged as .isMonster
- - if <def[value].is_spawned> && !<def[value].flag[mobAI.isMonster]> {
- #Tell it to attack/check its target
- - run mobAI_task_attack as:<def[value]> instantly
- #if it still doesn't have a target, resume pathing
- - if <def[value].flag[mobAI.target]||null> == null {
- - resume waypoints npc:%value%
- }
- - queue clear
- }
- #Check for another monstertype - boss
- - run mobAI_task_logic delay:10t
- # Chooses a nearby target
- mobAI_task_picktarget:
- type: task
- debug: false
- script:
- - ^flag npc mobAI.target:null
- - ^define entities <npc.location.find.npcs.within[<npc.flag[mobAI.trackingRange]>]>
- - ^define entity null
- - ^foreach %entities% {
- - if !<%value%.flag[mobAI.basicIgnoreTargeting]> {
- - define entities <def[entities].exclude[%value%]>
- }
- elseif <%value%.distance[<npc.flag[mobAI.spawnLocation]>]> > <npc.flag[mobAI.maxTrackingRange]> {
- - define entities <def[entities].exclude[%value%]>
- }
- elseif <%value%.is_player> {
- if <%value%.gamemode.id> != 0 {
- - define entities <def[entities].exclude[%value%]>
- }
- }
- }
- - ^foreach %entities% {
- - if <npc.can_see[%value%]> {
- - define entity %value%
- - foreach stop
- }
- }
- - ^flag npc mobAI.target:%entity%
- - event "mobai found_target" context:npc|<npc>|target|%entity%
- # Makes a sentry NPC attack the target
- mobAI_task_attack:
- type: task
- debug: true
- script:
- #increment attack cooldown
- - ^flag npc mobAI.attackCooldown:<npc.flag[mobAI.attackCooldown].add[10].asint>
- #check if it's time to reset its attack cooldown and start attack
- - ^if <npc.flag[mobAI.attackCooldown]> >= <npc.flag[mobAI.attackRate]> {
- - flag npc mobAI.attackCooldown:0
- }
- else {
- - queue clear
- }
- #pick new target if it doesnt have one
- - ^if <npc.flag[mobAI.target]> == null {
- - ^inject mobAI_task_picktarget
- }
- #otherwise check if its current target is not valid anymore and get a new one
- else {
- - if !<util.entity_is_spawned[<npc.flag[mobAI.target]>]> || !<npc.can_see[<npc.flag[mobAI.target]>]||false> {
- - inject mobAI_task_picktarget
- - if <npc.flag[mobAI.target]> == null {
- - flag npc mobAI.lostTarget:true
- }
- }
- }
- #if still no target, end attack
- - ^if <npc.flag[mobAI.target]> == null {
- - if <npc.flag[mobAI.lostTarget]> == true {
- - event "mobai lost_target" context:npc|<npc>
- }
- - inject mobAI_task_pathfind
- - queue clear
- }
- #get location of target and calculate if it's in attack range
- - ^define loc <npc.flag[mobAI.target].as_entity.location.add[0,0.33,0]>
- - if <npc.location.distance[%loc%]> < <npc.flag[mobAI.attackRange]> {
- - ^look %loc%
- - ^pause waypoints
- - event "mobai attack" context:npc|<npc>|target|<npc.flag[mobAI.target].as_entity>
- mobAI_task_pathfind:
- type: task
- debug: false
- script:
- - if <npc.location.distance[<npc.flag[mobAI.spawnLocation]>]> > <npc.flag[mobAI.wanderDistance]> {
- - walk <npc.flag[mobAI.spawnLocation]> speed:<npc.flag[mobAI.speed]> lookat:<npc.flag[mobAI.spawnLocation]>
- - queue clear
- }
- - if <npc.flag[lastPathfind]> > 0 {
- - flag npc mobAI.lastPathfind:<npc.flag[mobAI.lastPathfind].sub[10]>
- - queue clear
- }
- - walk <npc.flag[mobAI.spawnLocation]> speed:<npc.flag[mobAI.speed]> lookat:<npc.flag[mobAI.spawnLocation]> radius:lookat:<npc.flag[mobAI.wanderDistance]>
- mobAI_attack:
- type: task
- debug: false
- script:
- #get fail chance
- - if <npc.has_flag[attackFailChance]> == true {
- - if <util.random.int[1].to[100]> <= <npc.flag[attackFailChance]> {
- - queue clear
- }
- #get base damage
- - if <npc.has_flag[mobAI.damage]> == true {
- - flag npc mobAI.currentDmg:<npc.flag[mobAI.damage]>
- }
- else {
- - flag npc mobAI.currentDmg:<yaml[mobAI_mobs].read[default.damage]>
- }
- #critical
- - if <npc.has_flag[criticalChance]> == true {
- - if <util.random.int[1].to[100]> <= <npc.flag[criticalChance]> {
- - flag npc mobAI.critBonus:<npc.flag[mobAI.currentDmg].mul[<npc.flag[mobAI.criticalPercent].div[100]>]>
- }
- }
- #condition effects
- #armor calculations for players
- - if <npc.flag[mobAI.target].is_player> == true {
- #base values
- #slashing
- #crushing
- #shattering
- #piercing
- }
- mobAI_task_removearrow:
- type: task
- debug: false
- script:
- - if %hit_entities% == li@ remove %shot_entities%
Advertisement
Add Comment
Please, Sign In to add comment