Ah I see, thank you.
Hmm not working.
client:
local cooldown = 0
RegisterNetEvent("cooldownt")
AddEventHandler("cooldownt", function()
cooldown = cooldown + 20
while cooldown ~= 0 do
Citizen.Wait(60000)
cooldown = cooldown - 1
end
end)
RegisterNetEvent('UpdateCooldown')
AddEventHandler('UpdateCooldown', function(newCooldown)
cooldown = newCooldown
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
DrawText2("Priority Cooldown: ~r~".. cooldown .." ~w~Mins")
end
end)
function DrawText2(text)
SetTextFont(0)
SetTextProportional(1)
SetTextScale(0.0, 0.50)
SetTextDropshadow(1, 0, 0, 0, 255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextEntry("STRING")
AddTextComponentString(text)
DrawText(0.40, 0.10)
end
server:
RegisterCommand("a2", function()
TriggerClientEvent("cooldownt", -1)
end, false)
Citizen.CreateThread(function()
while cooldown ~= 0 do
Citizen.Wait(0)
TriggerClientEvent('UpdateCooldown', -1, cooldown)
end
end)
No no⌠this
RegisterNetEvent("cooldownt")
AddEventHandler("cooldownt", function()
cooldown = cooldown + 20
while cooldown ~= 0 do
Citizen.Wait(1000)
cooldown = cooldown - 1
end
end)
Needs to go back on the server. Youâre going to do the loop on the server and each time it loops, trigger client event with the new value.
The only thing you are going to do on the client, is have an event handler to get the new value and draw the text.
So like this?
client:
RegisterNetEvent('UpdateCooldown')
AddEventHandler('UpdateCooldown', function(newCooldown)
cooldown = newCooldown
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
DrawText2("Priority Cooldown: ~r~".. cooldown .." ~w~Mins")
end
end)
function DrawText2(text)
SetTextFont(0)
SetTextProportional(1)
SetTextScale(0.0, 0.50)
SetTextDropshadow(1, 0, 0, 0, 255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextEntry("STRING")
AddTextComponentString(text)
DrawText(0.40, 0.10)
end
Server:
cooldown = 0
RegisterCommand("a2", function()
TriggerServerEvent("cooldownt", -1)
end, false)
Citizen.CreateThread(function()
while cooldown ~= 0 do
Citizen.Wait(0)
TriggerClientEvent('UpdateCooldown', -1, cooldown)
end
end)
RegisterNetEvent("cooldownt")
AddEventHandler("cooldownt", function()
cooldown = cooldown + 20
while cooldown ~= 0 do
Citizen.Wait(1000)
cooldown = cooldown - 1
end
end)
Put this TriggerClientEvent('UpdateCooldown', -1, cooldown)
inside the while cooldown ~= 0 do
loop. You donât need to have it spamming every frame. That will just lag.
Youâll need a way to trigger the event RegisterNetEvent("cooldownt")
, but it looks ok
so
RegisterCommand("a2", function()
TriggerEvent("cooldownt", -1)
end, false)
would this work?
Cause now the DrawText is not appearing at all.
Now the DrawText is not working. I donât think it can find the variable.
Did you do this so it sends the variable?
while cooldown ~= 0 do
Citizen.Wait(1000)
cooldown = cooldown - 1
TriggerClientEvent('UpdateCooldown', -1, cooldown)
end
Do you have any errors in your F8 console or server console? Add in some Print() to see if the variables are changing.
I do, this is my server.lua
cooldown = 0
RegisterCommand("a2", function()
TriggerEvent("cooldownt")
end, false)
RegisterNetEvent("cooldownt")
AddEventHandler("cooldownt", function()
cooldown = cooldown + 20
while cooldown ~= 0 do
Citizen.Wait(1000)
cooldown = cooldown - 1
TriggerClientEvent('UpdateCooldown', -1, cooldown)
end
end)
and this is my client:
RegisterNetEvent('UpdateCooldown')
AddEventHandler('UpdateCooldown', function(newCooldown)
cooldown = newCooldown
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
DrawText2("Priority Cooldown: ~r~".. cooldown .." ~w~Mins")
end
end)
function DrawText2(text)
SetTextFont(0)
SetTextProportional(1)
SetTextScale(0.0, 0.50)
SetTextDropshadow(1, 0, 0, 0, 255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextEntry("STRING")
AddTextComponentString(text)
DrawText(0.40, 0.10)
end
Yet still there is not DrawText. Could it possibly be that I need to restart the server not the resource?
Is cooldown
still defined on your client code? You need local cooldown = 0
at the very top, not inside any functions
Ah I see, will try that now.
It works, thanks a lot
Hey, it works great. And I was trying to make a command to cancel the cooldown to 0. I managed to do it a couple times but then after one minute it would go to -1. Do you have any idea of how to make it so it resets to 0 and then does not go to -1?
Thanks,
Scotty
Maybe try a while cooldown > 0 do
This is not working:
RegisterNetEvent("cooldownreset")
AddEventHandler("cooldownreset", function()
cooldown = 0
end)
Its likely because you are setting cooldown to 0 during the Wait(1000)
part of your loop. This is after it has already checked if it is not 0, but then waits a second.
Put the wait
at the end like this, so it will not start another loop if cooldown is 0, and there will be no chance for it to become 0 before it actually subtracts. Youâll probably need to make the + 20
a + 21
to compensate for this.
while cooldown ~= 0 do
cooldown = cooldown - 1
TriggerClientEvent('UpdateCooldown', -1, cooldown)
Citizen.Wait(1000)
end
Is this for the reset issue? The only issue I have now is the reset not working and the cooldown going to 40 if the command is done twice.
That is to avoid it going to -1. If you want to avoid the command being run twice, put an if statement inside the event handler checking if cooldown is 0 or not.
Thanks, I got it to kind of work. So it works correctly. But once it hits 0. I cannot do the command again. If I do it just stays at 0.