Hi guys I need help understanding something. I have been trying to get this working for some time now and I have looked every where but no luck. So I hope today you can help explain and show me where I am going wrong!
I am trying to get a timer to work with my round system. I have been trying to do this for ages, but the way perhaps or my knowledge is incorrect on how to do it. So this is what I have.
[B]Server side[/B]
function round.Begin()
if round.Begin then
util.AddNetworkString("myMessage")
net.Start("myMessage")
net.Broadcast = ply
end
end
[B]Client side[/B]
function hud()
local timeleft = math.Round(math.max(0, roundend - CurTime()), 2)
net.SendToServer ("myMessage", function(length, client)
draw.SimpleText( timeleft,"MyFont2", ScrW() / 2 - -700, ScrH() - 1000, Color(220, 78, 78, 255),TEXT_ALIGN_CENTER)
end)
end
I have been trying to understand this server to networking for ages now. Also please just don't link this. As I have been reading it and trying it for ages.
[url]http://gmodwiki.net/Lua/Libraries/net[/url]
Thankyou very much for any support. I have to gain an understanding from this.
-Duby
[QUOTE=DubyxD;43913691]Hi guys I need help understanding something. I have been trying to get this working for some time now and I have looked every where but no luck. So I hope today you can help explain and show me where I am going wrong!
I am trying to get a timer to work with my round system. I have been trying to do this for ages, but the way perhaps or my knowledge is incorrect on how to do it. So this is what I have.
[B]Server side[/B]
[code]
function round.Begin()
if round.Begin then
util.AddNetworkString("myMessage")
net.Start("myMessage")
net.Broadcast = ply
end
end
[/code]
[B]Client side[/B]
[code]
function hud()
local timeleft = math.Round(math.max(0, roundend - CurTime()), 2)
net.SendToServer ("myMessage", function(length, client)
draw.SimpleText( timeleft,"MyFont2", ScrW() / 2 - -700, ScrH() - 1000, Color(220, 78, 78, 255),TEXT_ALIGN_CENTER)
end)
end
[/code]
I have been trying to understand this server to networking for ages now. Also please just don't link this. As I have been reading it and trying it for ages.
[url]http://gmodwiki.net/Lua/Libraries/net[/url]
Thankyou very much for any support. I have to gain an understanding from this.
-Duby[/QUOTE]
Please use [noparse][code][/code][/noparse] tags in the future, though I fixed it anyway for the purposes of this quote.
[b]Server[/b]
[code]
util.AddNetworkString("roundstart") -- Renamed the netmessages.
util.AddNetworkString("roundend") -- It's better to define this at the top of your init file. I also renamed it.
function round:Begin() -- use : instead of .
if round.Begin then -- what is round.Begin? Have you defined it anywhere? I presume you have.
net.Start("roundend")
net.Broadcast() -- it's just net.Broadcast(), no need for ply.
end
end
[/code]
[b]Client[/b]
[code]
local roundended = false
function hud() -- assuming this is using the HUDPaint hook there's no reason to change it.
local timeleft = math.Round(math.max(0, roundend - CurTime()), 2) -- what's roundend? where was it defined?
if roundended == true then
draw.SimpleText( timeleft,"MyFont2", ScrW() / 2 - -700, ScrH() - 1000, Color(220, 78, 78, 255),TEXT_ALIGN_CENTER)
end
end
hook.Add("HUDPaint", "RoundHUD", hud)
net.Receive("roundstart", function(length) -- net.Receive, not net.SendToServer().
roundended = false
end)
net.Receive("roundend", function(length) -- net.Receive, not net.SendToServer().
roundended = true
end)
[/code]
This is as much as I can help you without further details or error logs.
[QUOTE=Mors Quaedam;43913811]Please use [noparse][code][/code][/noparse] tags in the future, though I fixed it anyway for the purposes of this quote.
[code]
function round:Begin() -- use : instead of .
if round.Begin then -- what is round.Begin? Have you defined it anywhere?
util.AddNetworkString("myMessage") -- It's better to define this at the top of your init file.
net.Start("myMessage")
net.Broadcast() -- it's just net.Broadcast(), no need for ply.
end
end
[/code]
[code]
function hud() -- assuming this is using the HUDPaint hook there's no reason to change it.
local timeleft = math.Round(math.max(0, roundend - CurTime()), 2) -- what's roundend? where was it defined?
net.Receive("myMessage", function(length) -- net.Receive, not net.SendToServer().
draw.SimpleText( timeleft,"MyFont2", ScrW() / 2 - -700, ScrH() - 1000, Color(220, 78, 78, 255),TEXT_ALIGN_CENTER)
end)
end
[/code]
This is as much as I can help you without further details or error logs.[/QUOTE]
Instead you should have put the net.Receive outside the hud function and used hook.Add() to call the hud and then use hook.Remove() when he's done, instead of adding a net.Receive every frame.
[QUOTE=brandonj4;43913858]Instead you should have put the net.Receive outside the hud function and used hook.Add() to call the hud and then use hook.Remove() when he's done, instead of adding a net.Receive every frame.[/QUOTE]
Yes, that would have been ideal, I did not want to confuse him too much though.
If it were me, I would define it separately then set something like "roundended" to true, and only draw that text if "roundended" is true.
[editline]14th February 2014[/editline]
Fixed it. Thanks.
Hmmmmm Very intresting. I really appreciate the fact that you took the time to comment it. Thankyou very much. :) I will look closely at how this works and try and apply it to other things.
[editline]14th February 2014[/editline]
Hmm the timer isn't appearing on my screen. I don't have any error's on my console either. But it also creates a time out for joining. 'this is for a gamemode if you didn't know'
Looks like you didn't [url=http://wiki.garrysmod.com/page/Net_Library_Usage]check the usage tutorial[/url] first.
Quite a lot of mistakes were made contrary to the information provided there.
Good luck with your gamemode though.
Thankyou for the good luck. But *facepalm* You didn't read what I posted correctly. I have read this 100s of times and I am stuck with getting it to work. Thus I need someone to show me how it can work with this correctly above ^. Then I can learn how to use it with other things..
Sorry, you need to Log In to post a reply to this thread.