chat.AddText in networking called twice, IsFirstTimePredicted() always false
9 replies, posted
I'm trying to trigger the server to send the client a message to print in their chat when a keyword is said.
It's sent through
Serverside
[CODE]
util.AddNetworkString("FAQ_sendClientFAQInfo")
net.Start("FAQ_sendClientFAQInfo")
net.WriteString(v[2])
net.Send(ply)
[/CODE]
Clientside
[CODE]
net.Receive("FAQ_sendClientFAQInfo", function(len, serv)
-- if not IsFirstTimePredicted() then return end <-- Always returns false
print(IsFirstTimePredicted()) -- false
local str = net.ReadString() -- "Seeing errors? Type /addons to get the textures!"
surface.PlaySound(FAQ_sound) -- "common/wpn_select.wav"
timer.Simple(0.1, function() chat.AddText(FAQ_textColor, ("FAQ: "..str)) end)
end)
[/CODE]
Chat
[IMG]http://i.imgur.com/4MSMePE.png[/IMG]
Console
[IMG]http://i.imgur.com/erxvp5f.png[/IMG]
What can I do to fix this? Or am I misusing IsFirstTimePredicted()?
TO CLARIFY, net.Send() is sending the message ONCE
net.Receive() is reading the message TWICE
The way you used v[2] in the server-side code leads me to believe you're most likely using it within a loop / function, if that were the case it'd be useful if you posted the whole thing rather than just that portion you provided.
Serverside
[CODE]
util.AddNetworkString("FAQ_sendClientFAQInfo")
function FAQ_CheckMessage(ply, text, isTeam)
if isTeam == true and FAQ_teamEnabled == false then return end
for k,v in pairs(FAQ_triggerWords) do
if string.find(text, v[1]) then
net.Start("FAQ_sendClientFAQInfo")
net.WriteString(v[2])
net.Send(ply)
end
end
end
hook.Add("PlayerSay", "FAQ Check Message", FAQ_CheckMessage)
[/CODE]
Shared
[CODE]
FAQ_triggerWords = {
{"errors", "Seeing errors? Type /addons to get the textures!"}
}
[/CODE]
You don't need to check if it's the first time.
[QUOTE=Chessnut;48491340]You don't need to check if it's the first time.[/QUOTE]
I forgot to mention, when I don't the net message is sent once, but received twice.
Look at the chat picture to see what I mean
[QUOTE=blindsighterr;48493084]I forgot to mention, when I don't the net message is sent once, but received twice.
Look at the chat picture to see what I mean[/QUOTE]
Because you are sending it twice.
[code]for k,v in pairs(FAQ_triggerWords) do[/code]
Get it out of the loop.
[QUOTE=Netheous;48493178]Because you are sending it twice.
[code]for k,v in pairs(FAQ_triggerWords) do[/code]
Get it out of the loop.[/QUOTE]
And why even have a loop in the first place? I mean that table is quite useless imo...
[QUOTE=Netheous;48493178]Because you are sending it twice.
[code]for k,v in pairs(FAQ_triggerWords) do[/code]
Get it out of the loop.[/QUOTE]
There's only one item, so why would it loop twice?
EDIT I put a print("Hello world") next to the net.Send() on the server side and it's only called once. The net message is sent ONCE but the client reads it TWICE. On client side in net.Receive() if I put a print("Hello world") it prints twice.
[editline]19th August 2015[/editline]
[QUOTE=JasonMan34;48493202]And why even have a loop in the first place? I mean that table is quite useless imo...[/QUOTE]
I plan on adding more items as that table is a configuration of the addon.
Add a break after you call net.Send
[QUOTE=Chessnut;48494695]Add a break after you call net.Send[/QUOTE]
That did the trick! Thanks
Sorry, you need to Log In to post a reply to this thread.