diff --git a/client/main.lua b/client/main.lua index 5ddfdfa..d3211df 100644 --- a/client/main.lua +++ b/client/main.lua @@ -4,28 +4,65 @@ RegisterCommand("stealshoes", function() TriggerEvent('tnj-stealshoes:client:TheftShoe') end) +local function IsTargetDead(playerId) + local retval = false + local hasReturned = false + QBCore.Functions.TriggerCallback('shoes:server:isPlayerDead', function(result) + retval = result + hasReturned = true + end, playerId) + while not hasReturned do + Wait(10) + end + return retval +end + RegisterNetEvent('tnj-stealshoes:client:TheftShoe', function() -- This could be used in the radialmenu ;) local ped = PlayerPedId() if not IsPedRagdoll(ped) then local player, distance = QBCore.Functions.GetClosestPlayer() if player ~= -1 and distance < 1.5 then local playerId = GetPlayerServerId(player) - if not IsPedInAnyVehicle(GetPlayerPed(player)) and not IsPedInAnyVehicle(ped) then - local oped = GetPlayerPed(player) - local hasShoes = GetPedDrawableVariation(oped, 6) - if hasShoes ~= 34 then - while not HasAnimDictLoaded("random@domestic") do - RequestAnimDict("random@domestic") - Wait(1) + if Config.Down then + if IsTargetDead(playerId) then + if not IsPedInAnyVehicle(GetPlayerPed(player)) and not IsPedInAnyVehicle(ped) then + local oped = GetPlayerPed(player) + local hasShoes = GetPedDrawableVariation(oped, 6) + if hasShoes ~= 34 then + while not HasAnimDictLoaded("random@domestic") do + RequestAnimDict("random@domestic") + Wait(1) + end + TaskPlayAnim(ped, "random@domestic", "pickup_low", 8.00, -8.00, 500, 0, 0.00, 0, 0, 0) + TriggerServerEvent("tnj-stealshoes:server:TheftShoe", playerId) + SetPedComponentVariation(oped, 6, 34, 0, 2) + else + QBCore.Functions.Notify("No shoes to been stolen!", "error") + end + else + QBCore.Functions.Notify('You can\'t steal shoes in vehicle', "error") end - TaskPlayAnim(ped, "random@domestic", "pickup_low", 8.00, -8.00, 500, 0, 0.00, 0, 0, 0) - TriggerServerEvent("tnj-stealshoes:server:TheftShoe", playerId) - SetPedComponentVariation(oped, 6, 34, 0, 2) else - QBCore.Functions.Notify("No shoes to been stolen!", "error") + QBCore.Functions.Notify('They are not down!', "error") end else - QBCore.Functions.Notify('You can\'t steal shoes in vehicle', "error") + if not IsPedInAnyVehicle(GetPlayerPed(player)) and not IsPedInAnyVehicle(ped) then + local oped = GetPlayerPed(player) + local hasShoes = GetPedDrawableVariation(oped, 6) + if hasShoes ~= 34 then + while not HasAnimDictLoaded("random@domestic") do + RequestAnimDict("random@domestic") + Wait(1) + end + TaskPlayAnim(ped, "random@domestic", "pickup_low", 8.00, -8.00, 500, 0, 0.00, 0, 0, 0) + TriggerServerEvent("tnj-stealshoes:server:TheftShoe", playerId) + SetPedComponentVariation(oped, 6, 34, 0, 2) + else + QBCore.Functions.Notify("No shoes to been stolen!", "error") + end + else + QBCore.Functions.Notify('You can\'t steal shoes in vehicle', "error") + end end else QBCore.Functions.Notify('No one nearby!', "error") diff --git a/config.lua b/config.lua index 706eace..2354f5d 100644 --- a/config.lua +++ b/config.lua @@ -1,2 +1,4 @@ Config = {} Config.QBTarget = true + +Config.Down = true --set to false if you want to get shoes if a player is not in last stand or down \ No newline at end of file diff --git a/server/main.lua b/server/main.lua index d8a3f7e..abff0dc 100644 --- a/server/main.lua +++ b/server/main.lua @@ -17,4 +17,10 @@ RegisterNetEvent("tnj-stealshoes:server:Complete", function(playerId) Receiver.Functions.AddItem("weapon_shoe", 1) TriggerClientEvent('inventory:client:ItemBox', Receiver.PlayerData.source, QBCore.Shared.Items["weapon_shoe"], 'add') end +end) + +QBCore.Functions.CreateCallback('shoes:server:isPlayerDead', function(_, cb, playerId) + local Player = QBCore.Functions.GetPlayer(playerId) + local status = Player.PlayerData.metadata["isdead"] or Player.PlayerData.metadata["inlaststand"] + cb(status) end) \ No newline at end of file