From bf697d319350665f73e84ea1453c076aabcbc5a4 Mon Sep 17 00:00:00 2001 From: Pickle <111543470+PickleModifications@users.noreply.github.com> Date: Sun, 30 Oct 2022 17:12:04 -0400 Subject: [PATCH] Update v1.1.1 --- ptelevision/client/main.lua | 70 +++++++++++++++++++++++++------------ ptelevision/client/tv.lua | 4 +-- ptelevision/server/main.lua | 28 ++++----------- ptelevision/shared/main.lua | 6 +++- 4 files changed, 62 insertions(+), 46 deletions(-) diff --git a/ptelevision/client/main.lua b/ptelevision/client/main.lua index 8ce9267..7a6c809 100644 --- a/ptelevision/client/main.lua +++ b/ptelevision/client/main.lua @@ -70,33 +70,14 @@ function ShowScreen(data) PopScaleformMovieFunctionVoid() Citizen.CreateThread(function() + TriggerServerEvent("ptelevision:requestSync", data.coords) local tvObj = data.entity - - local _, status = GetTelevision(data.coords) - local _, lstatus = GetTelevisionLocal(data.coords) local screenModel = Config.Models[data.model] - if status and status["ptv_status"] then - local status = status["ptv_status"] - Citizen.Wait(1000) - if status.type == "play" and lstatus then - if (status.channel and Channels[status.channel]) then - PlayVideo({url = Channels[status.channel].url, channel = status.channel}) - elseif (status.url) then - local time - if (lstatus.start_time) then - time = math.floor((GetGameTimer() - lstatus.start_time) / 1000) - end - PlayVideo({url = status.url, time = time}) - end - elseif (status.type == "browser") then - PlayBrowser({ url = status.url }) - end - end while duiObj do if (tvObj and sfHandle ~= nil and HasScaleformMovieLoaded(sfHandle)) then local pos = GetEntityCoords(tvObj) local scale = screenModel.Scale - local offset = GetOffsetFromEntityInWorldCoords(tvObj, -1.02, -0.055, 1.04) + local offset = GetOffsetFromEntityInWorldCoords(tvObj, screenModel.Offset.x, screenModel.Offset.y, screenModel.Offset.z) local hz = GetEntityHeading(tvObj) DrawScaleformMovie_3dNonAdditive(sfHandle, offset.x, offset.y, offset.z, 0.0, -hz, 0.0, 2.0, 2.0, 2.0, scale * 1, scale * (9/16), 1, 2) end @@ -162,18 +143,63 @@ Citizen.CreateThread(function() local data = GetClosestScreen() if (data and not duiObj) then ShowScreen(data) - elseif ((not data or #(vec3(CURRENT_SCREEN.coords) - vec3(data.coords)) > 0.01 ) and duiObj) then + elseif ((not data or #(v3(CURRENT_SCREEN.coords) - v3(data.coords)) > 0.01 ) and duiObj) then HideScreen() end Citizen.Wait(wait) end end) +Citizen.CreateThread(function() + while true do + local wait = 2500 + local locations = Config.Locations + for i=1, #locations do + local data = locations[i] + local dist = #(GetEntityCoords(PlayerPedId()) - v3(data.Position)) + if not locations[i].obj and dist < 20.0 then + LoadModel(data.Model) + locations[i].obj = CreateObject(data.Model, data.Position.x, data.Position.y, data.Position.z) + SetEntityHeading(locations[i].obj, data.Position.w) + FreezeEntityPosition(locations[i].obj, true) + elseif locations[i].obj and dist > 20.0 then + DeleteEntity(locations[i].obj) + locations[i].obj = nil + end + end + Citizen.Wait(wait) + end +end) + RegisterNetEvent("ptelevision:requestUpdate", function(data) Televisions = data.Televisions Channels = data.Channels end) +RegisterNetEvent("ptelevision:requestSync", function(coords, data) + local tvObj = data.entity + + local _, status = GetTelevision(coords) + local screenModel = Config.Models[data.model] + if status and status["ptv_status"] then + local update_time = status.update_time + local status = status["ptv_status"] + Citizen.Wait(1000) + if status.type == "play" then + if (status.channel and Channels[status.channel]) then + PlayVideo({url = Channels[status.channel].url, channel = status.channel}) + elseif (status.url) then + local time = math.floor((data.current_time - update_time) / 1000) + PlayVideo({url = status.url, time = time}) + end + elseif (status.type == "browser") then + PlayBrowser({ url = status.url }) + end + end +end) + + + RegisterNUICallback("pageLoaded", function() waitForLoad = false end) diff --git a/ptelevision/client/tv.lua b/ptelevision/client/tv.lua index 054c283..b599e26 100644 --- a/ptelevision/client/tv.lua +++ b/ptelevision/client/tv.lua @@ -148,7 +148,7 @@ end function GetTelevisionLocal(coords) for k,v in pairs(TelevisionsLocal) do - if #(vec3(v.coords) - vec3(coords)) < 0.01 then + if #(v3(v.coords) - v3(coords)) < 0.01 then return k, v end end @@ -180,7 +180,7 @@ RegisterNetEvent("ptelevision:event", function(data, index, key, value) Televisions = data local data = Televisions[index] local screen = CURRENT_SCREEN - if (screen and #(vec3(screen.coords) - vec3(data.coords)) < 0.001) then + if (screen and #(v3(screen.coords) - v3(data.coords)) < 0.001) then local index, data = GetTelevision(screen.coords) if (index) then local event = value diff --git a/ptelevision/server/main.lua b/ptelevision/server/main.lua index 26ed1ef..ee7f27b 100644 --- a/ptelevision/server/main.lua +++ b/ptelevision/server/main.lua @@ -19,6 +19,7 @@ function SetTelevision(coords, key, value, update) Televisions[index][key] = value end Televisions[index].coords = coords + Televisions[index].update_time = os.time() if (update) then TriggerClientEvent("ptelevision:event", -1, Televisions, index, key, value) end @@ -52,6 +53,12 @@ function SetChannel(source, data) end end +RegisterNetEvent("ptelevision:requestSync", function(coords) + local _source = source + local index, data = GetTelevision(coords) + TriggerClientEvent("ptelevision:requestSync", _source, coords, {current_time = os.time()}) +end) + RegisterNetEvent("ptelevision:event", function(data, key, value) local _source = source Config.Events.ScreenInteract(_source, data, key, value, function() @@ -74,29 +81,8 @@ RegisterNetEvent("ptelevision:requestUpdate", function() }) end) -AddEventHandler('onResourceStop', function(name) - if name == GetCurrentResourceName() then - for i=1, #Locations do - local data = Locations[i] - if (DoesEntityExist(Locations[i].obj)) then - DeleteEntity(Locations[i].obj) - end - end - end -end) - AddEventHandler('playerDropped', function(reason) local _source = source SetChannel(_source, nil) end) -Citizen.CreateThread(function() - Citizen.Wait(1000) - local locations = Config.Locations - for i=1, #locations do - local data = locations[i] - local obj = CreateObject(data.Model, data.Position.x, data.Position.y, data.Position.z, true) - SetEntityHeading(obj, data.Position.w) - table.insert(Locations, {data = data, obj = obj}) - end -end) \ No newline at end of file diff --git a/ptelevision/shared/main.lua b/ptelevision/shared/main.lua index bb66b55..c5b855b 100644 --- a/ptelevision/shared/main.lua +++ b/ptelevision/shared/main.lua @@ -1,5 +1,9 @@ Televisions = {} +function v3(coord) + return vector3(coord.x, coord.y, coord.z), coord.w +end + function DumpArray(obj, seen) if type(obj) ~= 'table' then return obj end if seen and seen[obj] then return seen[obj] end @@ -12,7 +16,7 @@ end function GetTelevision(coords) for k,v in pairs(Televisions) do - if #(vec3(v.coords) - vec3(coords)) < 0.01 then + if #(v3(v.coords) - v3(coords)) < 0.01 then return k, v end end