• RP clock
    16 replies, posted
Is there anyway to make a clock that goes at a faster scale, so that you could actually RP with the time. Like every 3 or 4 seconds is a minute.
A useful way of doing this is by using [b][url=http://wiki.garrysmod.com/?title=G.SetGlobalInt]G.SetGlobalInt [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] and [b][url=http://wiki.garrysmod.com/?title=G.GetGlobalInt]G.GetGlobalInt [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]. On the server, you would set the global int of "rp_clock" or something to whatever time value you wanted, and then that's synchronized with the client who can output it in a clock.
You could do that, though it seems sort of unnecessary to set it every 3 or 4 seconds. What if it was set when the player spawned, and then re-set every hour, allowing the client to 'interpolate' between the hours, and getting re-synced on the hour (Fake hours for all of these) if they get off.
Right but couldn't there be issues with the client getting the wrong time if he hangs up or something?
[lua] if SERVER then function GM:InitPostEntity() SetGlobalInt("Hour",0) -- start times when server loads SetGlobalInt("Min",0) -- start times when server loads SetGlobalInt("Sec",0) -- start times when server loads end function GM:Think() if GetGlobalInt("Sec") < 60 then SetGlobalInt("Sec", GetGlobalInt("Sec") + 0.1) --Change 0.1 to how fast you want it to be, it is how fast the game ticks. else SetGlobalInt("Sec", 0) SetGlobalInt("Min", GetGlobalInt("Min") + 1) end if GetGlobalInt("Min") >= 60 then SetGlobalInt("Sec",0) SetGlobalInt("Min",0) SetGlobalInt("Hour", GetGlobalInt("Hour") + 1) end if GetGlobalInt("Hour") >= 24 then SetGlobalInt("Sec", 0) SetGlobalInt("Min",0) SetGlobalInt("Hour",0) end end else function clockhud() draw.SimpleText("Role Play Time", "Default", ScrW()*0.035, ScrH()*0.01, Color( 255, 104, 86, 255 ),0,0) draw.SimpleText(GetGlobalInt("Hour")..":"..GetGlobalInt("Min")..":"..math.Round(GetGlobalInt("Sec")), "Default", ScrW()*0.05, ScrH()*0.026, Color( 255, 104, 86, 255 ),0,0) end hook.Add("HUDPaint", "clockhud", clockhud) end [/lua] Into Shared...works nicely, I'm going to use it lol
CurTime() is synced, no? Just multiply it by how many times faster you want the time to be.
Thats what i use, for example, you can use this math.floor((CurTime()/4)%1440) It gets you the current minute of the day, 4 seconds being a minute, you can run it on both sides without any networking cost, and its synced
[QUOTE=iRzilla;26823696]Is it wise to set a global integer every second?[/QUOTE] [del]SetGlobalInt is not networked,i think that all it does is to set the _G["VariableName"]/_G.VariableName to the value.[/del]
[b][url=http://wiki.garrysmod.com/?title=G.CurTime]G.CurTime [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] says that "Gets the current time in seconds since server start. Mainly used for timers. Only runs while players are connected." Does this mean that if you try to use CurTime on a client when no clients exist it'll return nil?
[QUOTE=iRzilla;26827567]Read that back to your self.. That makes no sense at all.[/QUOTE] Sure it does, if you have a dedicated server you can have 0 players on it.
And you can tell it to run code on clients. [editline]20th December 2010[/editline] I think in my original question I meant to ask if CurTime() was run when no clients were connected to a dedicated server.
The shit I posted never stops :smug:
Sorry, you need to Log In to post a reply to this thread.