So a few things, for one I set it so it doesn't round the number so I can add .5 hours for a half an hour. This is for if someone does something extra or we sometimes do trivia for small amounts of time I can add say 15 minutes. If you could add something along the lines of !addtime name 15m for 15m that would be amazing. But feel free to add/modify/delete what ever you want, it basically yours.
Also could there be the potential to add time to a group of people? I am not sure how sql works for utime so wasn't sure if that was possible. But maybe a !addtime * or !addtime user.
Here is the code:
---------------------------------add time--------------------------------------
function ulx.addtime( calling_ply, target_ply, time )
local affected_plys = {}
function updatePlayer( ply )
sql.Query( "UPDATE utime SET totaltime = " .. math.floor( ply:GetUTimeTotalTime() ) .. " WHERE player = " .. ply:UniqueID() .. ";" )
end
function updateAll()
local players = player.GetAll()
for _, ply in ipairs( players ) do
if ply and ply:IsConnected() then
updatePlayer( ply )
end
end
end
local plyID = tostring(target_ply:UniqueID())
local ply = player.GetByUniqueID(plyID)
local ammount = tonumber(tostring(time))
ammount = ammount * 3600
newtime = ply:GetUTimeTotalTime() + ammount
ply:SetUTime( newtime )
ply:SetUTimeStart( CurTime() )
//sql.Query( "UPDATE utime SET totaltime = " .. math.floor(newtime) .. " WHERE player = " .. plyID .. ";" )
updateAll()
table.insert( affected_plys, target_ply )
ulx.fancyLogAdmin( calling_ply, "#A added #s hours to #T", time, affected_plys )
end
local addtime = ulx.command( CATEGORY_NAME, "ulx addtime", ulx.addtime, "!addtime" )
addtime:addParam{ type=ULib.cmds.PlayerArg }
addtime:addParam{ type=ULib.cmds.NumArg, min=0, default=1, hint="Hours" }
addtime:defaultAccess( ULib.ACCESS_SUPERADMIN )
addtime:help( "Add hours to a players time - !addtime" )