Buy weed from shop - > get "drunk" effects when using weed

Hello :smiley:

Could anyone help me in the right direction `? I’m trying to add “drunk” effects when using “weed”.
buying weed →


using weed →

and get this screen after

I have the code to add to client/main.lua

(or do i need script to make this work - it works wehn i buy a beer and use the beer. :stuck_out_tongue: )

RegisterNetEvent('esx_basicneeds:onWeed')
AddEventHandler('esx_basicneeds:onWeed', function(prop_name)
	if not IsAnimated then
		prop_name = prop_name or 'ng_proc_cigarette01a'
		IsAnimated = true

		Citizen.CreateThread(function()
		local playerPed = PlayerPedId()
		local x,y,z = table.unpack(GetEntityCoords(playerPed))
		local prop = CreateObject(GetHashKey(prop_name), x, y, z + 0.2, true, true, true)
		local boneIndex = GetPedBoneIndex(playerPed, 18905)
		AttachEntityToEntity(prop, playerPed, boneIndex, 0.12, 0.028, 0.001, 10.0, 175.0, 0.0, true, true, false, true, 1, true)
		
		ESX.Streaming.RequestAnimDict('amb@world_human_aa_smoke@male@idle_a', function()
			TaskStartScenarioInPlace(playerPed, 'WORLD_HUMAN_SMOKING', 0, false)

			Citizen.Wait(3000)
			IsAnimated = false
			ClearPedSecondaryTask(playerPed)
			DeleteObject(prop)
		end)
	end)

	end
end)

Thanks for the help, if anyone.

Hey ! :slightly_smiling_face:

The code you are sharing, is this already the code that you are using or is it some code you plan to add ?
Can you show us the code that runs when you drink the beer ?

1 Like

Hey like @thibaultD said, I also don’t know if you planned this script or if it already works a bit.
But I can recommend you this script: GitHub - esx-community/esx_drugeffects.
I’m not sure if they have also a forum post.

1 Like

I got it :smiley: I dont know if i need all those codes but, it’s working perfect now :smiley:

Took some codes from that drugeffects and added to the code:
So thank you @melonenmario

To: \resources[legacy][esx_addons]\esx_basicneeds\server\main.lua

ESX.RegisterUsableItem('weed', function(source)
	local xPlayer = ESX.GetPlayerFromId(source)
	
	xPlayer.removeInventoryItem('weed', 1)

	TriggerClientEvent('esx_status:add', source, 'drug', 166000)
	TriggerClientEvent('esx_basicneeds:onMarijuana', source)
	xPlayer.showNotification(_U('used_weed'))
end)

and added this also.
\resources[legacy][esx_addons]\esx_basicneeds\client\main.lua

ESX = nil
local IsAlreadyDrug = false
local DrugLevel = -1

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

AddEventHandler('esx_status:loaded', function(status)

  TriggerEvent('esx_status:registerStatus', 'drug', 0, '#9ec617', 
    function(status)
      if status.val > 0 then
        return true
      else
        return false
      end
    end, function(status)
      status.remove(1500)
    end)

	Citizen.CreateThread(function()
		while true do

			Wait(1000)

			TriggerEvent('esx_status:getStatus', 'drug', function(status)

		if status.val > 0 then
          local start = true

          if IsAlreadyDrug then
            start = false
          end

          local level = 0

          if status.val <= 999999 then
            level = 0
          else
            overdose()
          end

          if level ~= DrugLevel then
          end

          IsAlreadyDrug = true
          DrugLevel = level
		end

		if status.val == 0 then
          
          if IsAlreadyDrug then
            Normal()
          end

          IsAlreadyDrug = false
          DrugLevel     = -1
		end
			end)
		end
	end)
end)

--When effects ends go back to normal
function Normal()

  Citizen.CreateThread(function()
    local playerPed = GetPlayerPed(-1)
			
    ClearTimecycleModifier()
    ResetScenarioTypesEnabled()
    --ResetPedMovementClipset(playerPed, 0) <- it might cause the push of the vehicles
    SetPedIsDrug(playerPed, false)
    SetPedMotionBlur(playerPed, false)
  end)
end

--In case too much drugs dies of overdose set everything back
function overdose()

  Citizen.CreateThread(function()
    local playerPed = GetPlayerPed(-1)
	
    SetEntityHealth(playerPed, 0)
    ClearTimecycleModifier()
    ResetScenarioTypesEnabled()
    ResetPedMovementClipset(playerPed, 0)
    SetPedIsDrug(playerPed, false)
    SetPedMotionBlur(playerPed, false)
  end)
end

--Drugs Effects

--Marijuana
RegisterNetEvent('esx_basicneeds:onMarijuana')
AddEventHandler('esx_basicneeds:onMarijuana', function()
  local playerPed = GetPlayerPed(-1)

    RequestAnimSet("move_m@hipster@a") 
    while not HasAnimSetLoaded("move_m@hipster@a") do
      Citizen.Wait(0)
    end    

    TaskStartScenarioInPlace(playerPed, "WORLD_HUMAN_SMOKING_POT", 0, 1)
    Citizen.Wait(3000)
    ClearPedTasksImmediately(playerPed)
    SetTimecycleModifier("spectator5")
    SetPedMotionBlur(playerPed, true)
    SetPedMovementClipset(playerPed, "move_m@hipster@a", true)
    SetPedIsDrug(playerPed, true)

    --Efects
    local player = PlayerId()
    SetRunSprintMultiplierForPlayer(player, 1.3)

    Wait(300000)

    SetRunSprintMultiplierForPlayer(player, 1.0)		
end)

Thanks for the reply also @thibaultD :smiley: Appreciate it.

1 Like