From bc585cd9a5602164166811b9df86655c8c5924fc Mon Sep 17 00:00:00 2001 From: Atikur Rahaman Santo <55808925+ARSSANTO@users.noreply.github.com> Date: Sat, 17 Sep 2022 05:04:13 +0600 Subject: [PATCH 1/4] 2nd prop and lua54 support --- client/client.lua | 27 +++++++++++++++++++++------ fxmanifest.lua | 1 + shared/shared.lua | 6 +++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/client/client.lua b/client/client.lua index 54cb857..bc9dd82 100644 --- a/client/client.lua +++ b/client/client.lua @@ -8,11 +8,15 @@ local drugCount = 0 for k in pairs(Config.Emotes) do if Config.Emotes[k].AnimationOptions.Prop then Config.Emotes[k].AnimationOptions.Prop = GetHashKey(Config.Emotes[k].AnimationOptions.Prop) + if Config.Emotes[k].AnimationOptions.SecondProp then + Config.Emotes[k].AnimationOptions.SecondProp = GetHashKey(Config.Emotes[k].AnimationOptions.SecondProp) + end end end local consuming = false local cancelled = false +local attachProp, attachProp2 RegisterNetEvent('jim-consumables:Consume', function(itemName) if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Starting event, locking inventory and grabbing data^7..") end @@ -21,13 +25,19 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName) local emote = Config.Emotes[Config.Consumables[itemName].emote] local animDict = tostring(emote[1]) local anim = tostring(emote[2]) - local model, bone, drugeffect, stress + local model,model2, bone,bone2, drugeffect, stress local P1, P2, P3, P4, P5, P6 = table.unpack({0.0, 0.0, 0.0, 0.0, 0.0, 0.0}) + local P12, P22, P32, P42, P52, P62 = table.unpack({0.0, 0.0, 0.0, 0.0, 0.0, 0.0}) if emote.AnimationOptions.Prop then model = emote.AnimationOptions.Prop bone = GetPedBoneIndex(PlayerPedId(), emote.AnimationOptions.PropBone) P1, P2, P3, P4, P5, P6 = table.unpack(emote.AnimationOptions.PropPlacement) - end + if emote.AnimationOptions.SecondProp then + model2 = emote.AnimationOptions.SecondProp + bone2 = GetPedBoneIndex(PlayerPedId(), emote.AnimationOptions.SecondPropBone) + P12, P22, P32, P42, P52, P62 = table.unpack(emote.AnimationOptions.SecondPropPlacement) + end + end local time = Config.Consumables[itemName].time or math.random(5000, 6000) local type = Config.Consumables[itemName].type or "food" local stress = Config.Consumables[itemName].stress or 0 @@ -78,10 +88,15 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName) --Prop Spawning if model then if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Spawning consumable prop^7.") end - local attachProp = makeProp({ prop = model, coords = vector4(0.0,0.0,0.0,0.0)}, 1, 1) + attachProp = makeProp({ prop = model, coords = vector4(0.0,0.0,0.0,0.0)}, 1, 1) AttachEntityToEntity(attachProp, PlayerPedId(), bone, P1, P2, P3, P4, P5, P6, true, true, false, true, 1, true) + if model2 then + attachProp2 = makeProp({ prop = model2, coords = vector4(0.0,0.0,0.0,0.0)}, 1, 1) + AttachEntityToEntity(attachProp2, PlayerPedId(), bone2, P12, P22, P32, P42, P52, P62, true, true, false, true, 1, true) + end while consuming do Wait(100) end destroyProp(attachProp) + if model2 then destroyProp(attachProp2) end end end) while consuming do @@ -100,7 +115,7 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName) end end Wait(10) - time = time - 10 + time -= 10 end StopEntityAnim(PlayerPedId(), anim, animDict, 1.0) unloadAnimDict(animDict) @@ -194,13 +209,13 @@ CreateThread(function() Wait(10) if alcoholCount > 0 then Wait(1000 * 60 * 15) - alcoholCount = alcoholCount - 1 + alcoholCount -= 1 else Wait(1000) end if drugCount > 0 then Wait(1000 * 60 * 15) - drugCount = drugCount - 1 + drugCount -= 1 else Wait(1000) end diff --git a/fxmanifest.lua b/fxmanifest.lua index b0e6bf8..2d20e10 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,6 +4,7 @@ version "v1.3.1" description "Consumable Script By Jimathy" fx_version "cerulean" game "gta5" +lua54 'yes' shared_scripts { 'config.lua', 'shared/*.lua' } client_scripts { 'client/*.lua', } diff --git a/shared/shared.lua b/shared/shared.lua index d773818..27dbf5b 100644 --- a/shared/shared.lua +++ b/shared/shared.lua @@ -5,7 +5,7 @@ local time = 1000 function loadModel(model) if not HasModelLoaded(model) then if Config.Debug then print("^5Debug^7: ^2Loading Model^7: '^6"..model.."^7'") end while not HasModelLoaded(model) do - if time > 0 then time = time - 1 RequestModel(model) + if time > 0 then time -= 1 RequestModel(model) else time = 1000 print("^5Debug^7: ^3LoadModel^7: ^2Timed out loading model ^7'^6"..model.."^7'") break end Wait(10) @@ -198,7 +198,7 @@ function HealEffect(data) local count = (data[1] / 1000) while count > 0 do Wait(1000) - count = count - 1 + count -= 1 SetEntityHealth(PlayerPedId(), GetEntityHealth(PlayerPedId()) + data[2]) end healEffect = false @@ -215,7 +215,7 @@ function StaminaEffect(data) while startStamina > 0 do Wait(1000) if math.random(5, 100) < 10 then RestorePlayerStamina(PlayerId(), data[2]) end - startStamina = startStamina - 1 + startStamina -= 1 if math.random(5, 100) < 51 then end end startStamina = 0 From 5d084c304696bcf99279d46f269ff98e0d851a79 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Sat, 17 Sep 2022 16:48:42 +0100 Subject: [PATCH 2/4] Tidy + upgrade --- client/client.lua | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/client/client.lua b/client/client.lua index bc9dd82..88d6246 100644 --- a/client/client.lua +++ b/client/client.lua @@ -1,6 +1,5 @@ local QBCore = exports['qb-core']:GetCoreObject() -PlayerJob = {} local alcoholCount = 0 local drugCount = 0 @@ -16,7 +15,6 @@ end local consuming = false local cancelled = false -local attachProp, attachProp2 RegisterNetEvent('jim-consumables:Consume', function(itemName) if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Starting event, locking inventory and grabbing data^7..") end @@ -25,9 +23,8 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName) local emote = Config.Emotes[Config.Consumables[itemName].emote] local animDict = tostring(emote[1]) local anim = tostring(emote[2]) - local model,model2, bone,bone2, drugeffect, stress - local P1, P2, P3, P4, P5, P6 = table.unpack({0.0, 0.0, 0.0, 0.0, 0.0, 0.0}) - local P12, P22, P32, P42, P52, P62 = table.unpack({0.0, 0.0, 0.0, 0.0, 0.0, 0.0}) + local model, model2, bone, bone2, drugeffect, stress + local P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12 = table.unpack({0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}) -- Default placement coord cariable if emote.AnimationOptions.Prop then model = emote.AnimationOptions.Prop bone = GetPedBoneIndex(PlayerPedId(), emote.AnimationOptions.PropBone) @@ -35,9 +32,9 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName) if emote.AnimationOptions.SecondProp then model2 = emote.AnimationOptions.SecondProp bone2 = GetPedBoneIndex(PlayerPedId(), emote.AnimationOptions.SecondPropBone) - P12, P22, P32, P42, P52, P62 = table.unpack(emote.AnimationOptions.SecondPropPlacement) + P7, P8, P9, P10, P11, P12 = table.unpack(emote.AnimationOptions.SecondPropPlacement) end - end + end local time = Config.Consumables[itemName].time or math.random(5000, 6000) local type = Config.Consumables[itemName].type or "food" local stress = Config.Consumables[itemName].stress or 0 @@ -86,19 +83,19 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName) consuming = true CreateThread(function() --Prop Spawning - if model then - if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Spawning consumable prop^7.") end - attachProp = makeProp({ prop = model, coords = vector4(0.0,0.0,0.0,0.0)}, 1, 1) - AttachEntityToEntity(attachProp, PlayerPedId(), bone, P1, P2, P3, P4, P5, P6, true, true, false, true, 1, true) - if model2 then - attachProp2 = makeProp({ prop = model2, coords = vector4(0.0,0.0,0.0,0.0)}, 1, 1) - AttachEntityToEntity(attachProp2, PlayerPedId(), bone2, P12, P22, P32, P42, P52, P62, true, true, false, true, 1, true) - end - while consuming do Wait(100) end - destroyProp(attachProp) - if model2 then destroyProp(attachProp2) end - end - end) + if model and IsModelValid(model) == 1 then + if Config.Debug then print("^5Debug^7: ^3PropSpawn^7: ^2Spawning consumable prop^7.") end + attachProp = makeProp({ prop = model, coords = vector4(0.0,0.0,0.0,0.0)}, 1, 1) + AttachEntityToEntity(attachProp, PlayerPedId(), bone, P1, P2, P3, P4, P5, P6, true, true, false, true, 1, true) + if model2 and IsModelValid(model2) == 1 then + attachProp2 = makeProp({ prop = model2, coords = vector4(0.0,0.0,0.0,0.0)}, 1, 1) + AttachEntityToEntity(attachProp2, PlayerPedId(), bone2, P7, P8, P9, P10, P11, P12, true, true, false, true, 1, true) + else print("^5Debug^7: ^3Consume^7: ^2Second prop model isn't valid/found^7.") end + while consuming do Wait(50) end + if DoesEntityExist(attachProp) then destroyProp(attachProp) attachProp = nil end + if DoesEntityExist(attachProp2) then destroyProp(attachProp2) attackProp = nil end + else print("^5Debug^7: ^3PropSpawnstop^7: ^2Prop model isn't valid/found^7.") end + end) while consuming do if time <= 0 then consuming = false end if not Config.Consumables[itemName].canRun then @@ -168,7 +165,7 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName) end if stats.canOD then if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Current ^4drugCount^7: ^6"..(drugCount + 1)) end - drugCount = drugCount + 1 + drugCount += 1 if drugCount >= 4 then if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Current ^4drugCount^7: ^6"..drugCount.."^7 - ^2 removing health") end SetEntityHealth(PlayerPedId(), GetEntityHealth(PlayerPedId()) - math.random(10,15)) From 68b17642a6849cd81a60a58e24137678c7f7334d Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Sat, 17 Sep 2022 16:49:15 +0100 Subject: [PATCH 3/4] Version Bump --- fxmanifest.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fxmanifest.lua b/fxmanifest.lua index 2d20e10..46488a7 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,6 +1,6 @@ name "Jim-Consumables" author "Jimathy" -version "v1.3.1" +version "v1.3.2" description "Consumable Script By Jimathy" fx_version "cerulean" game "gta5" @@ -8,4 +8,4 @@ lua54 'yes' shared_scripts { 'config.lua', 'shared/*.lua' } client_scripts { 'client/*.lua', } -server_scripts { 'server/*.lua' } \ No newline at end of file +server_scripts { 'server/*.lua' } From 4bdcc11d51d8d6afadeecd35d085eca1c70025b3 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Sat, 17 Sep 2022 16:50:06 +0100 Subject: [PATCH 4/4] Update shared.lua --- shared/shared.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/shared.lua b/shared/shared.lua index 27dbf5b..e056dd7 100644 --- a/shared/shared.lua +++ b/shared/shared.lua @@ -51,7 +51,7 @@ function triggerNotify(title, message, type, src) end end -function countTable(table) local i = 0 for keys in pairs(table) do i = i + 1 end return i end +function countTable(table) local i = 0 for keys in pairs(table) do i += 1 end return i end function toggleItem(give, item, amount) TriggerServerEvent("jim-consumables:server:toggleItem", give, item, amount) end @@ -244,4 +244,4 @@ function StopEffects() -- Used to clear up any effects stuck on screen AnimpostfxStop('RaceTurbo') AnimpostfxStop('FocusIn') AnimpostfxStop('Rampage') -end \ No newline at end of file +end