[Release] Head bag script [ESX] Version: 1.0.1

This is simple HEAD BAG SCRIPT for ESX

Required:
ESX

Download - ERROR WITH SendNUIMessage fixed in 1.0.1

Screenshots:

– How another people see player with head bag.

– What player with head bag see.

NOTE: You must create item in your database called headbag!!!

**Update 13.10.2018: Fixed last bug with SendNUIMessage

THIS SCRIPT IS NOT ANYMORE SUPPORTED

23 Likes

Great release can’t wait to give it a try

1 Like

this is sweet… so how do you open the headbag menu? or is it a item…

2 Likes

This is registered item by

ESX.RegisterUsableItem

so i add a headbag as a item. than when i use it it opens the headbag menu? so if have 1 bag. than i put it on someone and it uses the bag how do i take it off someone?

If you use headbag item then Menu open and you can put off or put on head bag on nearest player.

1 Like

ok i understand so it dosent use the item it just lets u open the menu with the item

1 Like

Yup maybe in next update i create something like if player looking on player with headbag then he can just click on his head and this way put off head bag.

I added item to db but problem is when I put bag on players head. images bellow
bag on head

my view

Can you try to put this in client.lua and tell me it is work?

Because for me it’s work good ;(

ESX = nil
local HaveBagOnHead = false

Citizen.CreateThread(function()
	while ESX == nil do
		TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
		Citizen.Wait(0)
	end
end)

function NajblizszyGracz() --This function send to server closestplayer

local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()
local player = GetPlayerPed(-1)

if closestPlayer == -1 or closestDistance > 2.0 then 
    ESX.ShowNotification('~r~There is no player nearby')
else
  if not HaveBagOnHead then
    TriggerServerEvent('esx_worek:sendclosest', GetPlayerServerId(closestPlayer))
    ESX.ShowNotification('~g~You put the head bag on ~w~' .. GetPlayerName(closestPlayer))
    TriggerServerEvent('esx_worek:closest')
  else
    ESX.ShowNotification('~r~This player already have a bag on head')
  end
end

end

RegisterNetEvent('esx_worek:naloz') --This event open menu
AddEventHandler('esx_worek:naloz', function()
    OpenBagMenu()
end)

RegisterNetEvent('esx_worek:nalozNa') --This event put head bag on nearest player
AddEventHandler('esx_worek:nalozNa', function(gracz)
    local playerPed = GetPlayerPed(-1)
    Worek = CreateObject(GetHashKey("prop_money_bag_01"), 0, 0, 0, true, true, true) -- Create head bag object!
    AttachEntityToEntity(Worek, GetPlayerPed(-1), GetPedBoneIndex(GetPlayerPed(-1), 12844), 0.2, 0.04, 0, 0, 270.0, 60.0, true, true, false, true, 1, true) -- Attach object to head
    SetNuiFocus(false,false)
    SendNUIMesxage({type = 'openGeneral'})
    HaveBagOnHead = true
end)    

AddEventHandler('playerSpawned', function() --This event delete head bag when player is spawn again
DeleteEntity(Worek)
SetEntityAsNoLongerNeeded(Worek)
SendNUIMesxage({type = 'closeAll'})
HaveBagOnHead = false
end)

RegisterNetEvent('esx_worek:zdejmijc') --This event delete head bag from player head
AddEventHandler('esx_worek:zdejmijc', function(gracz)
    ESX.ShowNotification('~g~Someone removed the bag from your head!')
    DeleteEntity(Worek)
    SetEntityAsNoLongerNeeded(Worek)
    SendNUIMesxage({type = 'closeAll'})
    HaveBagOnHead = false
end)

function OpenBagMenu() --This function is menu function

    local elements = {
          {label = 'Put bag on head', value = 'puton'},
          {label = 'Remove bag from head', value = 'putoff'},
          
        }
  
    ESX.UI.Menu.CloseAll()
  
    ESX.UI.Menu.Open(
      'default', GetCurrentResourceName(), 'headbagging',
      {
        title    = 'HEAD BAG MENU',
        align    = 'top-left',
        elements = elements
        },
  
            function(data2, menu2)
  
  
              local player, distance = ESX.Game.GetClosestPlayer()
  
              if distance ~= -1 and distance <= 2.0 then
  
                if data2.current.value == 'puton' then
                    NajblizszyGracz()
                end
  
                if data2.current.value == 'putoff' then
                  TriggerServerEvent('esx_worek:zdejmij')
                end
              else
                ESX.ShowNotification('~r~There is no player nearby.')
              end
            end,
      function(data2, menu2)
        menu2.close()
      end
    )
  
  end


still not working.
my console error:

player with bag on head:

FIXED: SendNUIMesxage rename to SendNUIMessage

1 Like

Thanks i must update this :blush: i don’t saw that sorry for problems :slight_smile:

Possible to make it for non ESX please ? O.o

1 Like

Yup when i end non esx version i realese it too :slight_smile:

Oh ?! Thanks you are the best :slight_smile:

people on my server can see when they have the bag on…

1 Like

Replace this code

SendNUIMesxage({type = 'openGeneral'})

With this code

SendNUIMessage({type = 'openGeneral'})

1 Like

Thanks! he spelled wrong?

Yes he did! :slight_smile:

I updated this in 1.0.1

1 Like