Coward (fleeing script)


Author: Mastaba
Created: 2013-05-26T02:10:42-0400
Edited: 2013-05-27T03:53:13-0400
Denizen Version: 0.8.8
Views: 47
Downloads: 886
Likes: 1


WGET
Description: I'll write up a more thorough explanation later, but this is a script that you can trigger for an npc to flee when it is low on health.

Edit:5/27/13 removed some duplicate code.

# Make sure you set a larger pathfinding range with /npc pathfinding range #
# script by Mastaba 5/26/13
# for Denizen 0.8.8 by aufdemrand
"Coward":
    type: assignment

    default constants:
# This distance will determine how far the npc runs away.
# From the minimum distance to just under twice that number.
        minFleeDis: 10

    actions:
        on assignment:
        - trigger name:click toggle:false
        - trigger name:chat toggle:true
        - trigger name:damage toggle:true
        - trigger name:proximity toggle:true cooldown:5 radius:10

    interact scripts:
    - 10 Aggressive

"Aggressive":
    type: interact

    steps:
            1:
                proximity trigger:
                    entry:
                        script:
                        - chat "I'm an agressive mob!"
                        - ^flag npc fleeing:false
                        - attack

                damage trigger:
                    script:
                    - ^chat "Ouch! Don't hit me... I'm outta here!"
                    - ^if "<flag.n:fleeing || false>" == "true" determine cancelled
                    - ^flag npc fleeing:true
                    - ^flag npc flee_attacker:<player>
                    - ^runtask "script:Flee_calc_start"
                    - ^zap 2

            2:
                proximity trigger:
                    exit:
                        script:
                        - ^flag npc fleeing:false
                        - ^attack stop
                        - ^zap 1

"Flee_calc_start":
    type: task

    script:
    - ^flag npc flee_counter:0
 
    - ^flag npc flee_Mx:<npc.location.x>
    - ^flag npc flee_Mz:<npc.location.z>
    - ^flag npc flee_Px:<player.location.x>
    - ^flag npc flee_Pz:<player.location.z>
    - ^runtask "script:Flee_calc_meat"

"Flee_calc_cont":
    type: task

    script:
    - ^flag npc flee_counter:++
 
    - ^flag npc flee_Mx:<flag.n:flee_Mfleex>
    - ^flag npc flee_Mz:<flag.n:flee_Mfleez>
    - ^flag npc flee_Px:<<flag.n:flee_attacker>.location.x>
    - ^flag npc flee_Pz:<<flag.n:flee_attacker>.location.z>
    - ^runtask "script:Flee_calc_meat"

"Flee_calc_meat":
    type: task

    script:
    - ^flag npc flee_xD:<flag.n:flee_Mx>
    - ^flag npc flee_xD:-:<flag.n:flee_Px>

    - ^flag npc flee_zD:<flag.n:flee_Mz>
    - ^flag npc flee_zD:-:<flag.n:flee_Pz>

    - ^flag npc flee_Mfleex:<flag.n:flee_Mx>
    - ^flag npc flee_Mfleex:+:<flag.n:flee_xD>

    - ^flag npc flee_Mfleez:<flag.n:flee_Mz>
    - ^flag npc flee_Mfleez:+:<flag.n:flee_zD>

    - ^if "<flag.n:flee_xD.abs>" < "<cons:minFleeDis>" && "<flag.n:flee_zD.abs>" < "<cons:minFleeDis>" runtask "script:Flee_calc_cont"
      else if "<flag.n:flee_xD.abs>" >= "<cons:minFleeDis>" || "<flag.n:flee_zD.abs>" >= "<cons:minFleeDis>" runtask "script:Flee_walk"

"Flee_walk":
    type: task

    script:
    - ^attack stop
    - ^walkto "location:<flag.n:flee_Mfleex>,<npc.location.y>,<flag.n:flee_Mfleez>,<npc.location.world>" speed:3




Comments
No one has posted a comment! Post one below: