Hi
I have implemented some Chat Commands for a ChatBox I have been working on with another coder. It works pretty well, except that whenever anyone types a chat command (like /kill), the console command associated to the it gets executed on all players: i.e: all players will die.
Here is the code;
[lua]
function AddChatCommand(comm, desc, concomm, hide)
local c = {Command = comm, Description = desc, Console = concomm, Hidden = hide or true}
ChatCommands[comm] = c
end
function ShowVoteMenu()
RunConCommand("zsvotemenu")
end
-- Chat Commands
AddChatCommand("/votemap", "Opens the votemenu", ShowVoteMenu, false)
function ENChat.PlyChat(ply,ptext,pteam,pdead)
if ChatCommands[ptext] then
showchat = not ChatCommands[ptext].Hidden
ChatCommands[ptext].Console()
end
end
hook.Add("OnPlayerChat","ENChatOnChat",ENChat.PlyChat)
[/lua]
So, yeah this would run the console command "zsvotemenu" for everybody whenever somebody typed /votemap.
Any ideas?
One client can not run commands on other clients. This script is clientside.
Well I do not understand it. I did something like this:
[lua]
concommand.Add("zsvotemenu", function(sender, command, arguments)
if not sender:IsPlayer() then return end
print(sender:Nick() .. " sent this.")
end)
[/lua]
... which put this into the console:
nonSENSE sent this.
Player2 sent this.
Player3 sent this.
(for all players in the game).
When one player types the command in chat, OnPlayerChat hook gets called on all players who see the chat message. Your script then runs the command when the hook is called.
[QUOTE=raBBish;22899872]When one player types the command in chat, OnPlayerChat hook gets called on all players who see the chat message. Your script then runs the command when the hook is called.[/QUOTE]
That must be exactly what's happening. Thank you, this should work then!
Sorry, you need to Log In to post a reply to this thread.