I want to do a script for my server where I change the door opening animation for some cars:
local veh = nil
local currentVeh = nil
local VehicleLists= {my cars}
function SupportedCars(v)
for _, model in ipairs(VehicleLists) do
if GetEntityModel(v) == GetHashKey(model) then
return true
end
end
return false
end
function OnTick()
local character = GetPlayerPed(-1)
currentVeh = GetVehiclePedIsTryingToEnter(character)
if currentVeh ~= 0 then
veh = currentVeh
end
if GetVehiclePedIsUsing(character) ~= 0 then
veh = GetVehiclePedIsUsing(character)
end
if SupportedCars(veh) then
local angle1 = GetVehicleDoorAngleRatio(veh, 1)
SetVehicleDoorControl(veh, 2, 1, angle1)
end
end
Citizen.CreateThread(function()
while true do
Wait(0)
OnTick()
end
end)
I want to change the door opening from some cars in my list. The problem is that I can’t manage to get server side synchronization to work.
What I want to achieve is, for example: player1 sees how player2 goes into his car with the new opening door animation. But no matter what I try, the door animation isn’t synced and also it looks like the default GTA door opening. Client side works without a problem.
I tried this for server.lua:
RegisterServerEvent(‘syncDoors’)
AddEventHandler(‘syncDoors’, function(vehNetId, angle)
TriggerClientEvent(‘syncDoors’, -1, vehNetId, angle)
end)
And added this to client.lua:
local vehNetId = NetworkGetNetworkIdFromEntity(veh)
TriggerServerEvent('syncDoors', vehNetId, angle1)
and this for registering the event:
RegisterNetEvent('syncDoors')
AddEventHandler('syncDoors', function(vehNetId, angle)
local vehicle = NetworkGetEntityFromNetworkId(vehNetId)
if DoesEntityExist(vehicle) and SupportedCars(vehicle) then
SetVehicleDoorControl(vehicle, 2, 1, angle)
end
But i can’t seem to make it work. Do you have any idea on how to do this? Thanks!