Ulysses
General => Developers Corner => Topic started by: JasonMan on July 28, 2015, 08:42:00 AM
-
I modified this (http://forums.ulyssesmod.net/index.php?topic=7259.0) ulx unstuck for prophunt:
function ulx.unstuck( calling_ply )
if not calling_ply:Alive() and calling_ply:IsValid() then
ULib.tsayColor( calling_ply, _, Color( 255, 0, 0 ), "You must be alive to use this command!" )
else
if CurTime() - ( lasttime or 0 ) < 15 then
local cooldowntime = 15 - CurTime() + lasttime
ULib.tsayColor( calling_ply, _, Color( 255, 255, 255 ), "You must wait ", Color( 50, 50, 50 ), tostring( math.floor( cooldowntime ) ) , Color( 255, 255, 255 ), " more seconds before using this command again" )
else
if calling_ply:Team() == TEAM_HUNTERS then
smgnadeammo = calling_ply:GetAmmoCount( 9 )
end
lasttime = CurTime()
if calling_ply:IsValid() then
calling_ply:Spawn()
if calling_ply:Team() == TEAM_HUNTERS then
timer.Simple( 0.3, function()
calling_ply:SetAmmo( smgnadeammo, 9 )
end )
end
end
ULib.tsayColor( nil, _, Color( 255, 255, 255 ), calling_ply:Nick(), Color(0, 0, 255), " has been unstuck!" )
end
end
end
local unstuck = ulx.command( CATEGORY_NAME, "ulx unstuck", ulx.unstuck, "!unstuck" )
unstuck:defaultAccess( ULib.ACCESS_ALL )
unstuck:help( "Respawn yourself. There's a 15 seconds cooldown" )
Problem is: If one player uses the command, the cooldown period starts for all players on the server
-
That's because you're setting lasttime as a global.
You need to have lasttime be specific for the player.
do calling_ply.lasttime
then first line after your else, do
if not calling_ply.lasttime then calling_ply.lasttime = CurTime() - 20 end
-
That's because you're setting lasttime as a global.
You need to have lasttime be specific for the player.
do calling_ply.lasttime
then first line after your else, do
if not calling_ply.lasttime then calling_ply.lasttime = CurTime() - 20 end
Ye I knew I was setting it as a global but I didn't think about doing that, thanks :D
Also about that "if not calling_ply.lasttime then calling_ply.lasttime = CurTime() - 20 end"
I had that (if not ... lasttime = 0 ) but I thought that lasttime or 0 was cleaner.
Any specific reason on why do it that way?
-
Either way works. I just prefer to set the variable if it's nil manually rather than writing it into any logic that might need it in the function.