function ulx.rtd(calling_ply)
if (!IsValid(calling_ply)) then return end
calling_ply:PS_TakePoints(50)
if (calling_ply.TRTD_Cooldown == nil) then
calling_ply.TRTD_Cooldown = 0
end
if (calling_ply.TRTD_Cooldown-1 > CurTime()) then
ULib.tsayError(calling_ply, "You have to wait " .. math.Round(calling_ply.TRTD_Cooldown - CurTime()) .. " more seconds before you can Roll the Dice again.")
return
end
if (!calling_ply:Alive()) then
ULib.tsayError(calling_ply, "You can't Roll the Dice when you're dead.")
return
end
calling_ply.TRTD_Cooldown = CurTime() + TRTD.Settings.Cooldown:GetInt()
local effect = randomEffect(calling_ply)
MsgN("[".. TRTD.Settings.Tag:GetString() .."] " .. calling_ply:Nick() .. " has rolled " .. effect.name)
effect.enable(calling_ply)
if (effect.disable ~= nil && effect.duration ~= nil) then
-- Trigger the client-side countdown
net.Start("TRTD_EffectCountdown")
net.WriteInt(effect.duration, 6) -- Bit count of 6 allows any int between 0 and 63
net.Send(calling_ply)
-- Make sure all hook IDs are unique...
local session = util.CRC(SysTime())
local hookId = "TRTD_EffectTimer_" .. calling_ply:SteamID64() .. session
local timerId = "TRTD_DeathListener_" .. calling_ply:SteamID64() .. session
-- If the player dies during an effect, we want to stop it as well as the countdown
hook.Add("PlayerDeath", hookId, function(victim)
if (victim == calling_ply) then
net.Start("TRTD_EffectCountdownStop")
net.Send(calling_ply)
effect.disable(calling_ply)
timer.Destroy(timerId)
end
end)
-- Disable the effect
timer.Create(timerId, effect.duration, 1, function()
if (!IsValid(calling_ply)) then return end
effect.disable(calling_ply)
hook.Remove("PlayerDeath", hookId)
end)
end
local notification = {}
table.insert(notification, TRTD.Colors.Tag)
table.insert(notification, "[" .. TRTD.Settings.Tag:GetString() .. "] ")
table.insert(notification, team.GetColor(calling_ply:Team()))
table.insert(notification, calling_ply:Nick())
table.insert(notification, TRTD.Colors.Default)
table.insert(notification, " has received ")
table.insert(notification, TRTD.Colors.Effect)
table.insert(notification, effect.name)
table.insert(notification, TRTD.Colors.Default)
table.insert(notification, " from the dice.")
local effectNotifications = nil -- nil will send to all players
if (TRTD.Settings.Notifications:GetBool() == false) then
effectNotifications = calling_ply
end
ULib.tsayColor(effectNotifications, false, unpack(notification))
end
local rtd = ulx.command(TRTD.Settings.Category:GetString(), "ulx rtd", ulx.rtd, "!rtd", true)
rtd:defaultAccess(ULib.ACCESS_ALL)
rtd:help("Roll the Dice and receive a random, temporary effect.")