This script is designed for GTA 5 FiveM servers to simulate human vision by making NPCs within the player’s field of view semi-transparent. This feature helps players in roleplay scenarios by visually indicating which NPCs and players they haven’t seen, enhancing immersion and realism.
Features
Field of View Simulation: NPCs and Players within the character’s field of view are rendered semi-transparent, indicating they haven’t been seen by the player.
Immersive Roleplay: Enhances roleplay by providing visual cues about what the character can or cannot see.
Efficient Performance: The script is optimized with a low resmon value of 0.01, ensuring minimal impact on server performance.
this is a cool idea, the only problem i noticed was when driving a car it thinks you can’t see the car you are inside. other than that this is great work.
With this code, when you press C, the character will see what is happening behind and your car will no longer become invisible.
This is all that is necessary for the script to work, the rest can be removed
local viewAngle = 180.0
local alpha = 100
function ChangeEntityAlpha(entity, alpha)
local entityAlpha = GetEntityAlpha(entity)
if entityAlpha == 0 then return end
if entityAlpha == alpha then return end
SetEntityAlpha(entity, alpha)
end
function CanSeeEntity(direction, playerForwardVector)
return (direction.x * playerForwardVector.x + direction.y * playerForwardVector.y) > math.cos(math.rad(viewAngle))
end
Citizen.CreateThread(function()
while true do
local playerPed = PlayerPedId()
local playerPos = GetEntityCoords(playerPed)
local playerForwardVector = GetEntityForwardVector(playerPed)
if IsControlPressed(0, 26) then
playerForwardVector = -playerForwardVector
end
local peds = GetGamePool('CPed')
for _, ped in ipairs(peds) do
if ped ~= playerPed then
local pedPos = GetEntityCoords(ped)
local direction = pedPos - playerPos
local canSee = CanSeeEntity(direction, playerForwardVector)
ChangeEntityAlpha(ped, canSee and 255 or alpha)
end
end
local vehicles = GetGamePool('CVehicle')
local playerVehicle = GetVehiclePedIsIn(playerPed, false)
for _, vehicle in ipairs(vehicles) do
if not DoesEntityExist(playerVehicle) and not vehicle == playerVehicle then
local vehiclePos = GetEntityCoords(vehicle)
local direction = vehiclePos - playerPos
local canSee = CanSeeEntity(direction, playerForwardVector)
ChangeEntityAlpha(vehicle, canSee and 255 or alpha)
end
end
Wait(500)
end
end)