-- DESCRIPTION: When the target is within [RANGE=500] distance, the character will attack the target using melee combat, either using fists, or with a melee weapon if equipped. They will use and when attacking, and and when hurt. They can optionally [RunAway!=0] and be [InstantlyKillable!=1]. master_interpreter_core = require "scriptbank\\masterinterpreter" g_melee_attack = {} g_melee_attack_behavior = {} g_melee_attack_behavior_count = 0 function melee_attack_init(e) g_melee_attack[e] = {} g_melee_attack[e]["bycfilename"] = "scriptbank\\people\\melee_attack.byc" g_melee_attack_behavior_count = master_interpreter_core.masterinterpreter_load (g_melee_attack[e], g_melee_attack_behavior ) melee_attack_properties(e,500,0,1) end function melee_attack_properties(e, range, runaway, instantlykillable) g_melee_attack[e]['range'] = range g_melee_attack[e]['runaway'] = runaway g_melee_attack[e]['instantlykillable'] = instantlykillable master_interpreter_core.masterinterpreter_restart (g_melee_attack[e], g_Entity[e]) end function melee_attack_main(e) if g_Entity[e]['health'] < 20 then local obj = g_Entity[3].obj -- my entity ID is 3 - replace by yours to fit your needs. local oX = g_Entity[e]['x'] local oY = g_Entity[3]['y'] local oZ = g_Entity[e]['z'] PositionObject(obj,oX+20,oY,oZ+10) Spawn(3) end if g_melee_attack[e] ~= nil and g_melee_attack_behavior_count > 0 then g_melee_attack_behavior_count = master_interpreter_core.masterinterpreter (g_melee_attack_behavior, g_melee_attack_behavior_count, e, g_melee_attack[e], g_Entity[e]) end end