--registers creatures to allow them to communicate later gha_register_table = {} --gha_register creature in the table function gha_register(LuaAI) local zoneid = LuaAI:GetCreature():GetZoneId() if gha_register_table[zoneid] == nil then gha_register_table[zoneid] = {} end gha_register_table[zoneid][LuaAI:GetCreature():GetGUIDLow()] = LuaAI:GetCreature():GetGUID() end -- gha_unregister function gha_unregister(LuaAI) local zoneid = LuaAI:GetCreature():GetZoneId() if gha_register_table[zoneid] ~= nil then gha_register_table[zoneid][LuaAI:GetCreature():GetGUIDLow()] = nil end end gha_send_help_request_sender = nil gha_send_help_helpers_count = 0 gha_send_help_max_needed_helpers = 5 function gha_send_help_request(index,respval) if gha_send_help_request_sender == nil then return false end if DispatchMsg( 0,gha_send_help_request_sender,respval,GHA_NEED_HELP, nil ) == GHA_YES then gha_send_help_helpers_count = gha_send_help_helpers_count + 1 end if gha_send_help_helpers_count >= gha_send_help_max_needed_helpers then return true end return nil end -- gha_checkforhelp function gha_checkforhelp(LuaAI,unit) gha_unregister(LuaAI) local zoneid = LuaAI:GetCreature():GetZoneId() if gha_register_table[zoneid] == nil then gha_register(LuaAI) return false end gha_send_help_helpers_count = 0 gha_send_help_request_sender = LuaAI:GetCreature():GetGUID() gha_send_help_max_needed_helpers = 5 table.foreach (gha_register_table[zoneid], gha_send_help_request) if gha_send_help_helpers_count > 0 then LuaAI:GetCreature():DoYell( "Anybody wana help me ?!" , 0,nil ) gha_register(LuaAI) return true end gha_register(LuaAI) return false end -- TEST FUNC function gha_test(LuaAI) log("test") rx,ry,rz = i_creature:GetRespawnCoord() log("%f %f %f",rx,ry,rz) length = i_creature:GetDistanceSq(rx,ry,rz) log("lenght = " .. length) end function gha_victim_is_within_combat_range(LuaAI) if ( not i_creature:isAlive() ) or ( i_creature:getVictim() == nil ) then return false end rx,ry,rz = i_creature:GetRespawnCoord() length = i_creature:getVictim():GetDistanceSq(rx,ry,rz) return ( length < GHA_THREAT_RADIUS ) end