local hidden = {} local hide_delay = 0.4 --how long until the character is fully invisible (effects flash) local reappear_delay = 2 --how long you need to not be looking at the character for it to reappear local view_angle = 50 -- if not within this angle of the player's vision then we can reappear? local view_range = 1500 --maximum view of the player local move_speed = 1 --how fast the character will chase the player local minimum_chase_range = 750 --how close the character can get to the player hide_delay = hide_delay * 1000 reappear_delay = reappear_delay * 1000 function shadow_people_init(e) hidden[e] = 1 Hide(e) CollisionOff(e) end function shadow_people_main(e) SetEntityHealth(e,100000) CharacterControlUnarmed(e) RotateToPoint(e,g_PlayerPosX,g_PlayerPosZ) if GetPlayerDistance(e) > minimum_chase_range and GetEntityVisibility(e) == 0 then ModulateSpeed(e,move_speed) AIEntityGoToPosition(g_Entity[e]['obj'],g_PlayerPosX,g_PlayerPosZ) elseif GetPlayerDistance(e) < minimum_chase_range * 0.9 and GetEntityVisibility(e) == 0 then ModulateSpeed(e,move_speed*100) AIEntityGoToPosition(g_Entity[e]['obj'],g_Entity[e]['x'] + (math.sin(AngleToPoint(e,g_PlayerPosX,g_PlayerPosZ)+180) * minimum_chase_range),g_Entity[e]['z'] + (math.cos(AngleToPoint(e,g_PlayerPosX,g_PlayerPosZ)+180) * minimum_chase_range)) else AIEntityStop(g_Entity[e]['obj']) StopAnimation(e) end if hidden[e] == 1 then if PlayerLooking(e,view_range,view_angle) == 1 then StartTimer(e) else if GetTimer(e) > reappear_delay then hidden[e] = 0 Show(e) end end elseif hidden[e] == 0 then StartTimer(e) if PlayerLooking(e,view_range,view_angle) == 1 then hidden[e] = 2 end elseif hidden[e] > 1 then if hide_delay > 0 and hidden[e] < 10 then if GetTimer(e) > hide_delay * 0.1 then StartTimer(e) if GetEntityVisibility(e) == 0 then Show(e) else Hide(e) end hidden[e] = hidden[e] + 1 end else StartTimer(e) Hide(e) hidden[e] = 1 end end --hidden --Prompt("visible = "..GetEntityVisibility(e).." time til reappearance = "..(reappear_delay-GetTimer(e))) if GetPlayerDistance(e) > 1400 then Hide(e) hidden[e] = 1 end end --main(e) function shadow_people_exit(e) end function AngleToPoint(e,x,z) if g_Entity[e] ~= nil and x > 0 and z > 0 then local destx = x - g_Entity[e]['x'] local destz = z - g_Entity[e]['z'] 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 --SetRotation(e,0,angle,0) return angle end end function RotateToPoint(e,x,z) if g_Entity[e] ~= nil and x > 0 and z > 0 then local destx = x - g_Entity[e]['x'] local destz = z - g_Entity[e]['z'] 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 SetRotation(e,0,angle,0) return angle end 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 0 end else return 0 end end end