From 36d48ae16abd7396aef82ae342ee19061206f7d6 Mon Sep 17 00:00:00 2001 From: theskirata Date: Thu, 16 Jun 2022 20:09:29 +0100 Subject: [PATCH] refactor/feat: button config now separately in config.lua --- client/client.lua | 6 +++--- config.lua | 9 ++++++--- server/server.lua | 7 +++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/client/client.lua b/client/client.lua index d88a27b..ffb70d1 100644 --- a/client/client.lua +++ b/client/client.lua @@ -43,12 +43,12 @@ Citizen.CreateThread(function() else DrawText3Ds(coordsObject.x, coordsObject.y, coordsObject.z, Config.Text.LieOnBed .. ' ~g~' .. Anim .. '~w~ | ' .. Config.Text.SwitchBetween) end - if IsControlJustPressed(0, Config.objects.ButtonToLayOnBed) then + if IsControlJustPressed(0, Config.ButtonLayBed) then TriggerServerEvent('ChairBedSystem:Server:Enter', current, coordsObject) end else DrawText3Ds(coordsObject.x, coordsObject.y, coordsObject.z, Config.Text.SitOnChair) - if IsControlJustPressed(0, Config.objects.ButtonToSitOnChair) then + if IsControlJustPressed(0, Config.ButtonSitChair) then TriggerServerEvent('ChairBedSystem:Server:Enter', current, coordsObject) end end @@ -56,7 +56,7 @@ Citizen.CreateThread(function() if (InUse) then DrawText3Ds(coordsObject.x, coordsObject.y, coordsObject.z, Config.Text.Standup) - if IsControlJustPressed(0, Config.objects.ButtonToStandUp) then + if IsControlJustPressed(0, Config.ButtonStandUp) then InUse = false TriggerServerEvent('ChairBedSystem:Server:Leave', coordsObject) ClearPedTasksImmediately(PlayerPed) diff --git a/config.lua b/config.lua index fe0e3b6..31f667d 100644 --- a/config.lua +++ b/config.lua @@ -7,10 +7,13 @@ Config = {} +-- Default Keys (Refer to https://docs.fivem.net/game-references/controls/ for IDs) +Config.ButtonSitChair = 58 +Config.ButtonLayBed = 38 +Config.ButtonStandUp = 23 + +-- Objects for this script to work with Config.objects = { - ButtonToSitOnChair = 58, -- // Default: G -- // https://docs.fivem.net/game-references/controls/ - ButtonToLayOnBed = 38, -- // Default: E -- // https://docs.fivem.net/game-references/controls/ - ButtonToStandUp = 23, -- // Default: F -- // https://docs.fivem.net/game-references/controls/ SitAnimation = {anim='PROP_HUMAN_SEAT_CHAIR_MP_PLAYER'}, BedBackAnimation = {dict='anim@gangops@morgue@table@', anim='ko_front'}, BedStomachAnimation = {anim='WORLD_HUMAN_SUNBATHE'}, diff --git a/server/server.lua b/server/server.lua index f75b76e..d6026d6 100644 --- a/server/server.lua +++ b/server/server.lua @@ -17,7 +17,7 @@ AddEventHandler('playerDropped', function() end end) - +-- Player lies down/sits on Object RegisterServerEvent('ChairBedSystem:Server:Enter') AddEventHandler('ChairBedSystem:Server:Enter', function(object, objectcoords) local oSource = source @@ -28,12 +28,11 @@ AddEventHandler('ChairBedSystem:Server:Enter', function(object, objectcoords) end end) - +-- Player leaves Object RegisterServerEvent('ChairBedSystem:Server:Leave') AddEventHandler('ChairBedSystem:Server:Leave', function(objectcoords) local oSource = source oPlayerUse[oSource] = nil oArray[objectcoords] = nil -end) - +end) \ No newline at end of file