From 83b8ddec5e4d7efef82aff4085fc2558816cc337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20N=27gadi?= Date: Thu, 17 Aug 2017 17:41:42 +0200 Subject: [PATCH] Use new instance code --- __resource.lua | 4 ++++ client/main.lua | 55 ++++++++++++++++++++++++++++++++----------------- locales/en.lua | 1 + locales/fr.lua | 1 + 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/__resource.lua b/__resource.lua index 473a6ccf..948dceff 100644 --- a/__resource.lua +++ b/__resource.lua @@ -18,3 +18,7 @@ client_scripts { 'config.lua', 'client/main.lua' } + +dependencies { + 'instance' +} \ No newline at end of file diff --git a/client/main.lua b/client/main.lua index 36f260bd..7867679a 100644 --- a/client/main.lua +++ b/client/main.lua @@ -24,6 +24,7 @@ local CurrentActionMsg = '' local CurrentActionData = {} local FirstSpawn = true local PlayerLoaded = false +local Instance = {} function DrawSub(text, time) ClearPrints() @@ -112,12 +113,6 @@ function EnterProperty(name) TriggerServerEvent('esx_property:saveLastProperty', name) - TriggerEvent('instance:get', function(instance) - if instance.host == nil then - TriggerEvent('instance:create') - end - end) - Citizen.CreateThread(function() DoScreenFadeOut(800) @@ -170,12 +165,6 @@ function ExitProperty(name) SetEntityCoords(playerPed, outside.x, outside.y, outside.z) - TriggerEvent('instance:get', function(instance) - if instance.host ~= nil then - TriggerEvent('instance:leave') - end - end) - for i=1, #property.ipls, 1 do RemoveIpl(property.ipls[i]) end @@ -299,7 +288,7 @@ function OpenPropertyMenu(property) menu.close() if data2.current.value == 'enter' then - EnterProperty(property.name) + TriggerEvent('instance:create', 'property', {property = property.name}) end if data2.current.value == 'leave' then @@ -315,7 +304,7 @@ function OpenPropertyMenu(property) end if data2.current.value == 'visit' then - EnterProperty(property.name) + TriggerEvent('instance:create', 'property', {property = property.name}) end end, @@ -420,7 +409,7 @@ function OpenGatewayOwnedPropertiesMenu(property) menu.close() if data2.current.value == 'enter' then - EnterProperty(data.current.value) + TriggerEvent('instance:create', 'property', {property = data.current.value}) end if data2.current.value == 'leave' then @@ -492,7 +481,7 @@ function OpenGatewayAvailablePropertiesMenu(property) end if data2.current.value == 'visit' then - EnterProperty(data.current.value) + TriggerEvent('instance:create', 'property', {property = data.current.value}) end end, @@ -553,7 +542,8 @@ function OpenRoomMenu(property) elements = elements, }, function(data, menu) - TriggerEvent('instance:invite', GetPlayerServerId(data.current.value), property.inside) + TriggerEvent('instance:invite', 'property', GetPlayerServerId(data.current.value), {property = property.name}) + ESX.ShowNotification(_U('you_invited', GetPlayerName(data.current.value))) end, function(data, menu) menu.close() @@ -793,6 +783,15 @@ function OpenPlayerInventoryMenu(property) end +TriggerEvent('instance:registerType', 'property', + function(instance) + EnterProperty(instance.data.property) + end, + function(instance) + ExitProperty(instance.data.property) + end +) + AddEventHandler('playerSpawned', function() if FirstSpawn then @@ -805,7 +804,7 @@ AddEventHandler('playerSpawned', function() ESX.TriggerServerCallback('esx_property:getLastProperty', function(propertyName) if propertyName ~= nil then - EnterProperty(propertyName) + TriggerEvent('instance:create', 'property', {property = propertyName}) end end) @@ -849,6 +848,22 @@ AddEventHandler('esx:playerLoaded', function(xPlayer) end) +RegisterNetEvent('instance:onCreate') +AddEventHandler('instance:onCreate', function(instance) + + if instance.type == 'property' then + TriggerEvent('instance:enter', instance) + end + +end) + +RegisterNetEvent('instance:onPlayerLeft') +AddEventHandler('instance:onPlayerLeft', function(instance, player) + if player == instance.host then + ExitProperty(instance.data.property) + end +end) + AddEventHandler('esx_property:hasEnteredMarker', function(name, part) local property = GetProperty(name) @@ -1029,7 +1044,9 @@ Citizen.CreateThread(function() end if CurrentAction == 'room_exit' then - ExitProperty(CurrentActionData.propertyName) + TriggerEvent('instance:get', function(instance) + TriggerEvent('instance:leave') + end) end CurrentAction = nil diff --git a/locales/en.lua b/locales/en.lua index ce700925..133b42d1 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -11,6 +11,7 @@ Locales['en'] = { ['owned_properties'] = 'acquired properties', ['available_properties'] = 'available properties', ['invite_player'] = 'invite a player', + ['you_invited'] = 'you invited %s', ['player_clothes'] = 'clothes', ['remove_object'] = 'remove object', ['deposit_object'] = 'deposit object', diff --git a/locales/fr.lua b/locales/fr.lua index 2123dcb1..3b7a3567 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -11,6 +11,7 @@ Locales['fr'] = { ['owned_properties'] = 'propriétés acquises', ['available_properties'] = 'propriétés disponibles', ['invite_player'] = 'inviter un joueur', + ['you_invited'] = 'vous avez invité %s', ['player_clothes'] = 'vêtements', ['remove_object'] = 'retirer objet', ['deposit_object'] = 'déposer objet',