From e6b4c1d13c6e0a4861fe5abd1820719826c80624 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Wed, 9 Jul 2025 15:10:53 +0100 Subject: [PATCH] Add fade in animations for entity spawning --- shared/make/loaders.lua | 22 +++++++++++++++++++++- shared/make/makePed.lua | 7 ++++++- shared/make/makeProp.lua | 4 ++++ shared/make/makeVeh.lua | 8 ++++++-- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/shared/make/loaders.lua b/shared/make/loaders.lua index 8a7436b..402efd2 100644 --- a/shared/make/loaders.lua +++ b/shared/make/loaders.lua @@ -187,7 +187,7 @@ end --- ``` function playAnim(animDict, animName, duration, flag, ped, speed) loadAnimDict(animDict) - debugPrint("^6Bridge^7: ^3playAnim^7() ^2Triggered^7: ", animDict, animName) + debugPrint("^6Bridge^7: ^3playAnim^7() ^2Triggered^7: ", animDict, animName, flag) TaskPlayAnim(ped and ped or PlayerPedId(), animDict, animName, speed or 8.0, speed or -8.0, duration or 30000, flag or 50, 1, false, false, false) end @@ -238,4 +238,24 @@ function playGameSound(audioBank, soundSet, soundRef, coords, synced, range) PlaySoundFromEntity(soundId, soundRef, coords, soundSet, synced, 1.0) end ReleaseScriptAudioBank(audioBank) +end + +-- Experimental, add fade in for spawned entities +function fadeInEnt(ent, duration) + duration = duration or 500 -- in ms + local fadeSteps = 20 + local stepTime = duration / fadeSteps + + SetEntityAlpha(ent, 0, false) + SetEntityVisible(ent, true, false) + SetEntityLocallyInvisible(ent) -- sometimes helps prevent "pop-in" in early frames + + for i = 1, fadeSteps do + Wait(stepTime) + local newAlpha = math.floor((i / fadeSteps) * 255) + SetEntityAlpha(ent, newAlpha, false) + end + + -- Restore full visibility + ResetEntityAlpha(ent) end \ No newline at end of file diff --git a/shared/make/makePed.lua b/shared/make/makePed.lua index 5910d6e..3aa4515 100644 --- a/shared/make/makePed.lua +++ b/shared/make/makePed.lua @@ -62,7 +62,7 @@ function makePed(data, coords, freeze, collision, scenario, anim, synced) model = data.model loadModel(data.model) ped = CreatePed(0, model, coords.x, coords.y, coords.z - 1.03, coords.w, synced and synced or false, false) - + SetEntityAplha(ped, 0, false) -- Inheritance SetPedHeadBlendData(ped, data.custom.faceFather, data.custom.faceMother, data.custom.raceShape, data.custom.skinFather, data.custom.skinMother, data.custom.raceSkin, data.custom.faceMix or 0, data.custom.skinMix or 0, data.custom.raceMix or 0, false) @@ -116,6 +116,7 @@ function makePed(data, coords, freeze, collision, scenario, anim, synced) loadModel(model) if gameName == "rdr3" then ped = CreatePed(model, coords.x, coords.y, coords.z - 1.03, coords.w, synced or false, false) + SetEntityAplha(ped, 0, false) SetEntityVisible(ped, 1) -- SetEntityVisible SetEntityAlpha(ped, 255, false) -- SetEntityAlpha SetRandomOutfitVariation(ped, true) -- Invisible without @@ -141,6 +142,10 @@ function makePed(data, coords, freeze, collision, scenario, anim, synced) end unloadModel(model) Peds[keyGen()..keyGen()] = ped + + CreateThread(function() + fadeInEnt(ped) + end) return ped end diff --git a/shared/make/makeProp.lua b/shared/make/makeProp.lua index 6fe6b4f..ecaa38c 100644 --- a/shared/make/makeProp.lua +++ b/shared/make/makeProp.lua @@ -23,12 +23,16 @@ local Props = {} function makeProp(data, freeze, synced) loadModel(data.prop) local prop = CreateObject(data.prop, data.coords.x, data.coords.y, data.coords.z-1.03, synced and synced or false, synced and synced or false, false) + SetEntityAlpha(veh, 0, false) SetEntityHeading(prop, (data.coords.w or 0) + 180.0) FreezeEntityPosition(prop, freeze or false) debugPrint("^6Bridge^7: ^1Prop ^2Created^7: '^6"..prop.."^7' | ^2Hash^7: ^7'^6"..data.prop.."^7' | ^2Coord^7: "..formatCoord(data.coords)) SetModelAsNoLongerNeeded(data.prop) Props[keyGen()..keyGen()] = prop + CreateThread(function() + fadeInEnt(prop) + end) return prop end diff --git a/shared/make/makeVeh.lua b/shared/make/makeVeh.lua index d32ac57..008e355 100644 --- a/shared/make/makeVeh.lua +++ b/shared/make/makeVeh.lua @@ -18,18 +18,22 @@ function makeVeh(model, coords) local veh = CreateVehicle(model, coords.x, coords.y, coords.z, coords.w, true, false) SetVehicleHasBeenOwnedByPlayer(veh, true) if gameName ~= "rdr3" then - SetNetworkIdCanMigrate(NetworkGetNetworkIdFromEntity(veh), true) + SetEntityAlpha(veh, 0, false) + SetNetworkIdCanMigrate(NetworkGetNetworkIdFromEntity(veh), true) Wait(100) SetVehicleNeedsToBeHotwired(veh, false) SetVehRadioStation(veh, 'OFF') SetVehicleFuelLevel(veh, 100.0) SetVehicleModKit(veh, 0) + end SetVehicleOnGroundProperly(veh) - debugPrint("^6Bridge^7: ^1Veh ^2Created^7: '^6"..veh.."^7' | ^2Hash^7: ^7'^6"..model.."^7' | ^2Coord^7: "..formatCoord(coords)) unloadModel(model) Vehicles[#Vehicles + 1] = veh + CreateThread(function() + fadeInEnt(veh) + end) return veh end