--how close player can get before angels become active (start moving) local active_range = 500 --effects how far away player is looking from angel before he's considered "not looking" at them local player_view_angle = 50 --how fast the angels move forward (they only move forward when they can see the player) local move_speed = 175 --how fast the angel will rotate to face the player if he's not looking at them local rotate_speed = 8 --how much damage per hit local damage = 10 --delay until sound is played (also delay between sound replay) --sound is slot 1 local sound_delay = 1000 --how close player needs to be to get attacked (also not visible) local attack_range = 100 --how long between attacks local attack_delay = 500 local attack_delay_init = attack_delay local sound_delay_init = sound_delay function angels_init(e) end function angels_main(e) CollisionOff(e) StopAnimation(e) if GetPlayerDistance(e) <= active_range then player_view_angle = 70 if PlayerLooking(e,active_range,player_view_angle) ~= 1 then LookAtPlayer(e) if GetPlayerDistance(e) >= active_range / 2 then RotateToPlayerSlowly(e,rotate_speed) else RotateToPlayer(e) end if GetPlayerDistance(e) <= attack_range then if GetTimer(e) > attack_delay and PlayerLooking(e,active_range,player_view_angle) ~= 1 then HurtPlayer(e,damage) attack_delay = GetTimer(e) + attack_delay_init end if GetTimer(e) > sound_delay then PlaySound(e,1) sound_delay = GetTimer(e) + sound_delay_init end else MoveForward(e,move_speed) sound_delay = GetTimer(e) + (sound_delay_init / 2) attack_delay = GetTimer(e) + attack_delay_init end end end CollisionOn(e) end function angels_exit(e) end function PlayerLooking(e,dis,v) if g_Entity[e] ~= nil then if dis == nil then dis = 3000 end if v == nil then v = 0.5 end if GetPlayerDistance(e) <= dis then local destx = g_Entity[e]['x'] - g_PlayerPosX local destz = g_Entity[e]['z'] - g_PlayerPosZ local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle <= 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end while g_PlayerAngY < 0 or g_PlayerAngY > 360 do if g_PlayerAngY <= 0 then g_PlayerAngY = 360 + g_PlayerAngY elseif g_PlayerAngY > 360 then g_PlayerAngY = g_PlayerAngY - 360 end end local L = angle - v local R = angle + v if L <= 0 then L = 360 + L elseif L > 360 then L = L - 360 end if R <= 0 then R = 360 + R elseif R > 360 then R = R - 360 end if (L < R and math.abs(g_PlayerAngY) > L and math.abs(g_PlayerAngY) < R) then return 1 elseif (L > R and (math.abs(g_PlayerAngY) > L or math.abs(g_PlayerAngY) < R)) then return 1 else return -1000 end else return 1 end end end