Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- client
- exports.ox_target:addGlobalPlayer({
- label = "Rob",
- name = 'script:rob',
- distance = 2.5,
- canInteract = function()
- -- here you can add checks when player can be robbed
- return true
- end
- onSelect = function(data)
- local targetPed = data.entity
- local targetNetworkId = NetworkGetPlayerIndexFromPed(targetPed)
- local targetServerId = GetPlayerServerId(targetNetworkId)
- TriggerServerEvent('script:server:rob', targetServerId)
- end
- })
- -- server
- local robbing = {}
- local blacklistedItems = {
- 'water'
- }
- RegisterNetEvent('script:server:rob', function(targetId)
- local src = source
- local Player = QBCore.Functions.GetPlayer(src)
- if not Player then
- -- player cant be nil
- return
- end
- local Target = QBCore.Functions.GetPlayer(targetId)
- if not Target then
- -- target cant be nil
- return
- end
- local playerPed = GetPlayerPed(src)
- local targetPed = GetPlayerPed(targetId)
- local playerCoords = GetEntityCoords(playerPed)
- local targetCoords = GetEntityCoords(targetPed)
- if #(playerCoords - targetCoords) > 2.5 then
- -- target is too far away
- return
- end
- if robbing[src] then
- -- already robbing
- return
- end
- exports.ox_inventory.forceOpenInventory(src, 'player', targetId)
- robbing[src] = targetId
- end)
- RegisterNetEvent('ox_inventory:closedInventory', function(source, target)
- if not robbing[source] then
- return
- end
- if robbing[source] ~= target then
- return
- end
- robbing[src] = nil
- end)
- exports.ox_inventory:registerHook('swapItems', function(payload)
- local source = payload.source
- if not robbing[source] then
- return true
- end
- if robbing[source] ~= payload.fromInventory then
- return true
- end
- local item = payload.fromSlot.name:lower()
- for k, v in pairs(blacklistedItems) do
- if v == item then
- return false
- end
- end
- return true
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement