local frzx = 0 local frzy = 0 local frzz = 0 local follow_num = 0 local result = 0 pressed = 0 local nearest_dist = 0 function camera_follow_object_init(e) CollisionOff(e) end function camera_follow_object_main(e) if follow_num == 0 then if g_KeyPressE == 1 and pressed == 0 then pressed = 1 nearest_dist = 3000 follow_num = 0 repeat result = 0 for a,_ in pairs (ai_bot_state) do if a ~= follow_num then if GetPlayerDistance(a) < nearest_dist then if PlayerLookingAtAI(a,nearest_dist,10) == 1 then nearest_dist = GetPlayerDistance(a) follow_num = a result = 1 end end end end until result == 0 frzx = g_PlayerPosX frzy = g_PlayerPosY frzz = g_PlayerPosZ end elseif follow_num > 0 then SetFreezePosition(frzx,frzy,frzz) SetFreezeAngle(0,PlayerAngleToPoint(GetEntityPositionX(follow_num),GetEntityPositionZ(follow_num)),0) TransportToFreezePosition() --SetPosition(e,GetEntityPositionX(follow_num),GetEntityPositionY(follow_num),GetEntityPositionZ(follow_num)) --Prompt("Tracking entity number: "..follow_num) if g_KeyPressE == 1 and pressed == 0 then pressed = 1 follow_num = 0 end end if g_KeyPressE == 0 then pressed = 0 end end function camera_follow_object_exit(e) end function PlayerAngleToPoint(x,z) local destx = x - g_PlayerPosX local destz = 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 --SetRotation(e,0,angle,0) return angle end function PlayerLookingAtAI(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 = GetEntityPositionX(e) - g_PlayerPosX local destz = GetEntityPositionZ(e) - 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