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

#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

9 Likes

#2

Great release can’t wait to give it a try

0 Likes

#3

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

0 Likes

#4

This is registered item by

ESX.RegisterUsableItem
0 Likes

#5

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?

0 Likes

#6

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

0 Likes

#7

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

0 Likes

#8

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.

0 Likes

#9

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

my view

0 Likes

#10

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


0 Likes

#11

still not working.
my console error:

player with bag on head:

FIXED: SendNUIMesxage rename to SendNUIMessage

0 Likes

#12

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

0 Likes

#13

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

0 Likes

#14

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

0 Likes

#15

Oh ?! Thanks you are the best :slight_smile:

0 Likes

#16

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

0 Likes

#17

Replace this code

SendNUIMesxage({type = 'openGeneral'})

With this code

SendNUIMessage({type = 'openGeneral'})

0 Likes

#18

Thanks! he spelled wrong?

0 Likes

#19

Yes he did! :slight_smile:

0 Likes

#20

I updated this in 1.0.1

0 Likes