Hello,
I’m trying to get an item to have a timer for be able to use it again later,
for example, use a heavy armor once and then wait 5 minutes to use it again,
Can someone help me with that? Can’t get it work.
Thanks
Hello,
I’m trying to get an item to have a timer for be able to use it again later,
for example, use a heavy armor once and then wait 5 minutes to use it again,
Can someone help me with that? Can’t get it work.
Thanks
You need to edit your inventory or the way the players use a item.
There you can implement when using the item to set a bool and after x minutes you set it back.
Something like this:
local TimeoutActive = false -- set the timeout default false
--Scenario: The Player use a item
if TimeoutActive then
print("You can't use this item now")
return
end
TimeoutActive = true -- activate the timeout
Citizen.SetTimeout(5000, function() -- This example is for 5000ms = 5s
TimeoutActive = false --deactivate the timeout
end)
This logic is just simple and have a timeout for all items, when you want it for specific items you need to rewrite it. Save the item name in a list to validate the timeout (remove the item in the list after x time)
Okey, i got it work now
But whenever i use the item again while the timeout is on, it removes 1 from my inventory,
Do you know hoy to fix that?
That means before your event here happens other code that already removes the item. you have to place the timeout at the beginning where your code logic starts thus
for example:
C = ClientSide
S = Server
Player want to use → C (Send Request) → S (Removes Item and do stuff) → C (Get the confirmation and do stuff)
In this example you need to set and validate the timeout before the client contacts the server (it also saves performance if the server is only used when the player is allowed to).
Got to be honest, i was not able to fix it with what you said
got a problem doing it, i am to lost
Tried changing the time out but nothing, or it cancels everything like i can’t use the item anymore or like there is no timeout at all
local QBCore = exports[‘qb-core’]:GetCoreObject()
local TimeoutActive = false
– Uso del bubbaloo
RegisterNetEvent(‘bubalus:client:UseBubalus’)
AddEventHandler(‘bubalus:client:UseBubalus’, function()
if TimeoutActive then
print(“No puedes comer bubbaloo en este momento”)
return
end
QBCore.Functions.Progressbar(“eat”, “Comiendo bubbaloo…”, 1000, false, true, {
disableMovement = false,
disableCarMovement = false,
disableMouse = false,
disableCombat = true,
}, {}, {}, {}, function() – Done
TriggerServerEvent(‘hud:server:RelieveStress’, math.random(Config.MinStress, Config.MaxStress)) – Elimina el estrés
TimeoutActive = true
Citizen.SetTimeout(5000, function ()
TimeoutActive = false
end)
end)
end)
Send me the whole resource please
main.lua (908 Bytes)
Here
In your case you need to make your timeout check on serverside where the item is registed. Save the timeout BOOL in an object to timeout specific player:
{
[2] = true, -- Player 2 has a timeout
[3] = false -- Player 3 don't have a timeout
}
Got it, thanks you!
I’m glad that you implement your feature. Please choose a solution to mark this thread as completed.
Greetings
Hello!
I just realized trying this script with more people, and the thing is, if 1 of us eat that nobody can eat it again till the timeout is out, i think that BOOL that you meant “to timeout specific player” i didnt do it correctly
is there anyway you could help me with that?
Thanks and sorry!
Hello CriisT0,
try to debug the code and analyse why each player have the same entry in the list. The PlayerID should be unique so also the entry in the list.
Regards👌