I'm not the best at lua, though I know parts of it.
I've been trying to make a text entry, and if you
press a 'publish' button, other people will be able to
see the text by writing in a chat command.
The problem is, I cannot seem to get the message(s)
from the text entry to the player(s). I've been trying to
add it, so that when you press the button, it'll copy the
text, and then send it to the server, where the player then
can use a chat command, and the text will be pasted into
the chat.
I don't really have any 'stable' code, but this is parts of what
I currently have, which isn't working correctly:
[CODE]
--Server
function ShowNews(ply, text, public)
if(string.sub(text, 1) == "/news" or string.sub(text, 1) == "!news") then
net.Receive("myMessage", function(length, client)
client:ChatPrint(""..net:ReadString().."")
net.Send(client)
end)
return ""
else
end
end
hook.Add("PlayerSay","opennews", ShowNews)
util.AddNetworkString("myMessage")
--Client
net.Start("myMessage")
myMessage = Text:GetText()
net.WriteString(myMessage)
net.SendToServer()
end):SetIcon("icon16/feed.png")
[/CODE]
Yeah, I can't seem to figure stuff out.
Could anyone help me, if they know what's wrong?
I'll be checking this thread regularly, so if you have any
questions about stuff, then just post a comment or something.
None of your code makes sense, you are receving a net message inside of a function that isn't "open". You have weird stuff at the end of your net.Start for some reason and you don't need to use Net to do a ChatPrint, it's a serverside function.
There's a random 'else' in there on your server function... you should try and get the basics of coding down before you attempt something like this, you just mashed a bunch of lines of code together expecting something to happen, but that's not how it works :(
Here's a quicker simple version of your script:
[code]
local news = "This is a test news section!"
hook.Add("PlayerSay", "CheckForNewsChat", function(ply, msg)
if string.sub(text, 1, 5) == "/news" or string.sub(text, 1, 5) == "!news" then
ply:ChatPrint(news)
end
end)[/code]
A player can type "!postnews This is news."
Any other player can type "!news" and see the last news post.
it also accepts /postnews and /news
[CODE]
local current_news = ""
hook.Add("PlayerSay", "CheckForNewsChat", function(ply, msg)
if string.sub(text, 1, 5) == "/news" or string.sub(text, 1, 5) == "!news" then
ply:ChatPrint(current_news)
elseif string.sub(text, 1, 9) == "/postnews" or string.sub(text, 1, 9) == "!postnews" then
current_news = string.sub(text, 10)
end
end)[/CODE]
As I said, I'm not the best at lua,
but I've managed to make this work.
So yeah, this is solved.
Sorry, you need to Log In to post a reply to this thread.