[SOLVED] Using an item that decreases player speed

I have an item called “candy” that I want to be able to give to people and have them consume that immobilizes them.
My code below currently works for making them feel intoxicated, but it doesn’t slow their movement down at all.

I’ve tried both SetPedMoveRateOverride and SetRunSprintMultiplierForPlayer, but it appears neither of these slow the player down at all.

If there’s anybody who knows a suitable replacement, please let me know!

My current code:

RegisterNetEvent('esx_drugeffects:onCandy')
AddEventHandler('esx_drugeffects:onCandy', function()
  
  local playerPed = GetPlayerPed(-1)

  RequestAnimSet("MOVE_M@DRUNK@VERYDRUNK")
	while not HasAnimSetLoaded("MOVE_M@DRUNK@VERYDRUNK") do
		Citizen.Wait(0)
  end 

    Citizen.Wait(10000)
    local player = PlayerId()
    ClearPedTasksImmediately(playerPed)
    SetTimecycleModifier("spectator5")
    SetPedMotionBlur(playerPed, true)
    SetPedMovementClipset(playerPed, "MOVE_M@DRUNK@VERYDRUNK", true)
    SetPedIsDrunk(playerPed, true)
    
    -- Effects
    SetPedMoveRateOverride(PlayerPedId(), 0.1)
        
    -- Wait and Reset Effects
    Wait(900000)
    SetPedMoveRateOverride(PlayerPedId(), 1.0)
    
end)

SetPedMoveRateOverride has to be set every frame

1 Like

Can you give an example?

every frame he means doing it in a client thread

like:


local DoEffects = false

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(16)
        
        if DoEffects then
        	SetPedMoveRateOverride(PlayerPedId(), 0.1)
        end
        
    end
end)

you just have to set the ‘DoEffects’ to true in the client event:
(and get rid of other override calls)

SetPedMovementClipset(playerPed, "MOVE_M@DRUNK@VERYDRUNK", true)
    SetPedIsDrunk(playerPed, true)
    
    -- Effects
    -- SetPedMoveRateOverride(PlayerPedId(), 0.1)
    DoEffects = true

and


    -- Wait and Reset Effects
    Wait(900000)
    --SetPedMoveRateOverride(PlayerPedId(), 1.0)
    DoEffects = false
3 Likes

Thanks for that!
Apparently in the documentation it said that it didn’t, but now that I’ve got it in there it works.

glad to help :smiley:

Wouldn’t you have to state what DoEffects is doing? like
local DoEffects = SetPedMoveRateOverride(PlayerPedId(), 0.1)

DoEffects in this case is just a bool that is being toggled to determine if the Override should take place, and this is being checked every frame (16 milisecs).

it has to be declared in the client (outside of the thread) to be toggled by a separate Event (the client event being triggered)

every time the event is called it will toggle On, then when the “wait” period is over it will toggle back to false and the override should automatically stop taking place (in other words the gta/fivem server automatically sets the moverate value back to 1.0 if the override was not called at a given interval, so we dont need to set it back to default ourselves)

ahh okay so in server.lua under registerable item. you would do something like

ESX.RegisterUsableItem('coke', function(source)
	local _source = source
	local xPlayer = ESX.GetPlayerFromId(_source)

	xPlayer.removeInventoryItem('coke', 1)


	--TriggerClientEvent('esx_illegal_drugs:onCoke', _source)
	DoEffects = true
	Citizen.Wait(120000)
	DoEffects = false
	TriggerClientEvent('esx:showNotification', _source, _U('used_one_coke'))
end)

^ like this
or
like this;

ESX.RegisterUsableItem('coke', function(source)
	local _source = source
	local xPlayer = ESX.GetPlayerFromId(_source)

	xPlayer.removeInventoryItem('coke', 1)


	--TriggerClientEvent('esx_illegal_drugs:onCoke', _source)
	TriggerClientEvent('DoEffects', _source)
	TriggerClientEvent('esx:showNotification', _source, _U('used_one_coke'))
end)

if you are trying to trigger it froma server event you would have to do it like this:

from server:

TriggerClientEvent('clientUsesCoke', player)

and in client:

declare

local DoEffects = false
at the top of the script.

then add a Citizen.Thread like the one above.

and then have an event:

RegisterNetEvent('clientUsesCoke')
AddEventHandler('clientUsesCoke', function()

        DoEffects = true
        TriggerClientEvent('esx:showNotification', _source, _U('used_one_coke'))
	
        Wait(120000)
	DoEffects = false

end)

Thank-You, Works perfectly. Appreciate it.

glad to help! :smiley: got a two-for-one in this thread lol

1 Like

Can you create an File For your example script? i cant know what i have to do.

i am looking for a script like ,
player use item '“cocaine”
then run faster and have unlimited stamina for 1 minute
do you know if there is something like that ?