Skip to content

Commit

Permalink
Error handing /time args + time chat suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyste committed Oct 31, 2019
1 parent 5bd1c82 commit 60862a5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
8 changes: 8 additions & 0 deletions ss_cli_time.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ Citizen.CreateThread( function()
NetworkOverrideClockTime( math.floor( secondOfDay / 3600 ), math.floor( (secondOfDay - (h * 3600)) / 60 ), secondOfDay - (math.floor( secondOfDay / 3600 ) * 3600) - (math.floor( (secondOfDay - (h * 3600)) / 60 ) * 60) )
end
end)

RegisterNetEvent("addTimeChatSuggests")
AddEventHandler("addTimeChatSuggests", function()
TriggerEvent('chat:addSuggestion', '/time', 'Change the time.', {
{ name="hour" , help="Hour of day in 24 hour format."},
{ name="minute", help="Minute of the hour."}
})
end)
28 changes: 20 additions & 8 deletions ss_srv_time.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ Citizen.CreateThread(function()
end
end)

RegisterServerEvent( "addTimeChatSuggests" )
AddEventHandler( "addTimeChatSuggests", function()
if IsPlayerAceAllowed(source, "changeTime") then
TriggerClientEvent ("addTimeChatSuggests",source)
end
end)


Citizen.CreateThread( function()
local timeBuffer = 0.0
local h = 0
Expand Down Expand Up @@ -61,15 +69,19 @@ RegisterCommand('time', function(source,args,rawCommand)
end
else
if IsPlayerAceAllowed(source, "changeTime") then
ProcessTimeCommand(args[1],args[2])
h = math.floor( secondOfDay / 3600 )
m = math.floor( (secondOfDay - (h * 3600)) / 60 )
TraceMsg(GetPlayerName(source).." has changed time to " ..string.format("%02d", h)..":"..string.format("%02d",m))
if tonumber(args[1]) ~= nil and tonumber(args[2]) ~= nil then
ProcessTimeCommand(args[1],args[2])
h = math.floor( secondOfDay / 3600 )
m = math.floor( (secondOfDay - (h * 3600)) / 60 )
TraceMsg(GetPlayerName(source).." has changed time to " ..string.format("%02d", h)..":"..string.format("%02d",m))
else
TraceMsg("Invalid syntax, correct syntax is: time <hour> <minute>.",true)
end
else
TraceMsg('Access for command /time denied for player: '.. GetPlayerName(source),true)
end
end
end, false)
end, true)

RegisterCommand('freezetime', function(source,args,rawCommand)
h = math.floor( secondOfDay / 3600 )
Expand All @@ -86,20 +98,20 @@ RegisterCommand('freezetime', function(source,args,rawCommand)
TraceMsg('Access for command /freezetime denied for player: '.. GetPlayerName(source),true)
end
end
end, false)
end, true)


function ProcessTimeCommand(arg1,arg2)
local h = 0
local m = 0
local argh = tonumber(arg1)
local argm = tonumber(arg2)
if argh < 24 then
if argh < 24 and argh ~= nil then
h = argh
else
h = 0
end
if argm < 60 then
if argm < 60 and arm ~= nil then
m = argm
else
m = 0
Expand Down
2 changes: 1 addition & 1 deletion ss_srv_weather.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ RegisterCommand('weather', function(source, args)
end

end
end, false)
end, true)

0 comments on commit 60862a5

Please sign in to comment.