Hey, Im just trying to make a clock to the server which will show up for players that join the server. The clock will be for a RP server.
The script is
cl_clock.lua
[code]
local function RcvHour( um )
Hour = um:ReadShort()
end
usermessage.Hook("SendHour", RcvHour)
local function RcvMinute( um )
Minute = um:ReadShort()
end
usermessage.Hook("SendMinute", RcvMinute)
function Time()
local frame = vgui.Create("DFrame")
frame:SetSize( 150, 25 )
frame:SetPos(0,155)
frame:SetVisible(true)
frame:SetTitle( "Time:" ..Hour.. ":" ..Minute )
function timethink()
frame:SetTitle( "Time:" ..Hour.. ":" ..Minute )
if (LocalPlayer():GetActiveWeapon():IsValid() and LocalPlayer():GetActiveWeapon():GetClass() == "gmod_camera") then
frame:SetVisible(false)
else
frame:SetVisible(true)
end
end
frame:ShowCloseButton (false)
end
concommand.Add( "rp_clock", Time )
[/code]
clock.lua (server side)
[code]
AddCSLuaFile( "cl_clock.lua" )
tHour = 12
tMinute = 00
function setup(ply)
ply:ConCommand( "rp_clock" )
end
local function SendHour( pl )
umsg.Start( "SendHour", pl )
umsg.Short( tHour )
umsg.End()
end
local function SendMinute( pl )
umsg.Start( "SendMinute", pl )
umsg.Short( tMinute )
umsg.End()
end
function sTime()
timer.Create( "minute", 2, 0, function()
tMinute += 1
if tMinute >= 60 then
tMinute = 00
tHour ++
end
if tHour == 24 then
tHour = 00
end
update(ply)
end )
[/code]
[b]1.[/b] First problem is that it doesn't show up auto when I join the game (When spawned)
[b]2.[/b] When I do rp_clock in console it shows up the Derma with tittle "Untitled DFrame" and give me a error "autorun/client/cl_clock.lua:19: attempt to concatenate global 'Hour' (a nil value)"
Im trying to make it send from server to client the time so every player that joins/are joined see the same time.
Please help me out :)
change the cl_clock.lua and clock.lua
to
cl_init.lua
and
init.lua
Put "local Hour" and "local Minute" at the top of cl_clock.
[QUOTE=Sonic Cow;17902610]change the cl_clock.lua and clock.lua
to
cl_init.lua
and
init.lua[/QUOTE]
Why the hell would you need to do that...
I made the locals. Now the cl_clock.lua is like:
[code]
local Hour
local Minute
local function RcvHour( um )
Hour = um:ReadShort()
end
usermessage.Hook("SendHour", RcvHour)
local function RcvMinute( um )
Minute = um:ReadShort()
end
usermessage.Hook("SendMinute", RcvMinute)
function Time()
local frame = vgui.Create("DFrame")
frame:SetSize( 150, 25 )
frame:SetPos(0,155)
frame:SetVisible(true)
frame:SetTitle( "Time:" ..Hour.. ":" ..Minute )
function timethink()
frame:SetTitle( "Time:" ..Hour.. ":" ..Minute )
if (LocalPlayer():GetActiveWeapon():IsValid() and LocalPlayer():GetActiveWeapon():GetClass() == "gmod_camera") then
frame:SetVisible(false)
else
frame:SetVisible(true)
end
end
frame:ShowCloseButton (false)
end
concommand.Add( "rp_clock", Time )
[/code]
But I still get a error when I type "rp_clock" in console and the error is:
[code]
autorun/client/cl_clock.lua:19: attempt to concatenate upvalue 'Minute' (a nil value)
[/code]
cl_clock.lua
[lua]
local Hour = 0; -- This is so that Hour and Minute have values to start with
local Minute = 0;
local function RcvHour( um )
Hour = um:ReadShort()
end
usermessage.Hook("SendHour", RcvHour)
local function RcvMinute( um )
Minute = um:ReadShort()
end
usermessage.Hook("SendMinute", RcvMinute)
function Time()
local frame = vgui.Create("DFrame")
frame:SetSize( 150, 25 )
frame:SetPos(0,155)
frame:SetVisible(true)
frame:SetTitle( "Time:" ..Hour.. ":" ..Minute )
function timethink()
frame:SetTitle( "Time:" ..Hour.. ":" ..Minute )
if (LocalPlayer():GetActiveWeapon():IsValid() and LocalPlayer():GetActiveWeapon():GetClass() == "gmod_camera") then
frame:SetVisible(false)
else
frame:SetVisible(true)
end
end
frame:ShowCloseButton (false)
end
concommand.Add( "rp_clock", Time )
[/lua]
clock.lua (server side)
[lua]
AddCSLuaFile( "cl_clock.lua" )
tHour = 12
tMinute = 00
function setup(ply)
timer.Simple( 1, function() ply:ConCommand( "rp_clock" ) end ) -- So we can send the umsgs first
end
hook.Add( "PlayerSpawn", "setup", setup );
local function SendHour( pl )
umsg.Start( "SendHour", pl )
umsg.Short( tHour )
umsg.End()
end
local function SendMinute( pl )
umsg.Start( "SendMinute", pl )
umsg.Short( tMinute )
umsg.End()
end
function sTime()
timer.Create( "minute", 2, 0, function()
tMinute += 1
if tMinute >= 60 then
tMinute = 00
tHour ++
end
if tHour == 24 then
tHour = 00
end
update(ply)
end )
[/lua]
There's a couple fixes. Dunno how you're calling sTime and the send* functions. Also, time on the DPanel won't update itself.
autorun/client/cl_clock.lua:19: attempt to concatenate upvalue 'Minute' (a nil value)
I get this now. I just copied the server lua you fixed. Because I dont see the cl_clock.lua and code?
Overview over my script now:
cl_clock.lua
[code]
local Hour
local Minute
local function RcvHour( um )
Hour = um:ReadShort()
end
usermessage.Hook("SendHour", RcvHour)
local function RcvMinute( um )
Minute = um:ReadShort()
end
usermessage.Hook("SendMinute", RcvMinute)
function Time()
local frame = vgui.Create("DFrame")
frame:SetSize( 150, 25 )
frame:SetPos(0,155)
frame:SetVisible(true)
frame:SetTitle( "Time:" ..Hour.. ":" ..Minute )
function timethink()
frame:SetTitle( "Time:" ..Hour.. ":" ..Minute )
if (LocalPlayer():GetActiveWeapon():IsValid() and LocalPlayer():GetActiveWeapon():GetClass() == "gmod_camera") then
frame:SetVisible(false)
else
frame:SetVisible(true)
end
end
frame:ShowCloseButton (false)
end
concommand.Add( "rp_clock", Time )
[/code]
clock.lua (server)
[code]
AddCSLuaFile( "cl_clock.lua" )
tHour = 12
tMinute = 00
function setup(ply)
timer.Simple( 1, function() ply:ConCommand( "rp_clock" ) end ) -- So we can send the umsgs first
end
hook.Add( "PlayerSpawn", "setup", setup );
local function SendHour( pl )
umsg.Start( "SendHour", pl )
umsg.Short( tHour )
umsg.End()
end
local function SendMinute( pl )
umsg.Start( "SendMinute", pl )
umsg.Short( tMinute )
umsg.End()
end
function sTime()
timer.Create( "minute", 2, 0, function()
tMinute += 1
if tMinute >= 60 then
tMinute = 00
tHour ++
end
if tHour == 24 then
tHour = 00
end
update(ply)
end )
[/code]
And I still get the error:
[code]
autorun/client/cl_clock.lua:19: attempt to concatenate upvalue 'Minute' (a nil value)
[/code]
I dont see anything wrong! Please help me !
Sorry, you need to Log In to post a reply to this thread.