因此,我正在尝试创建一个小脚本,以便当GMOD中的玩家进入"!内容"例如,它们将通过一个窗口呈现,该窗口将引导它们访问该服务器的Steam内容。对于前面的例子,它工作,所以我然后尝试复制模板,只是更改功能名称等。我没有遇到与所示示例相同的结果,但似乎没有发生任何事情我不知道为什么我只有更改了函数名称和字符串。如果你能帮助我,那会很棒。提前谢谢。
Steam群聊脚本(作品)
function steamgroupCommand( ply, text)
if string.sub( text, 1, 6 ) == "!steam" then
ply:PrintMessage( 3, "It Worked!" )
ply:SendLua([[gui.OpenURL("http://steamcommunity.com/groups/PhantomNetworksCommunity")]])
for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. ply:Nick() .. " has used !steam to view our community Steam Group!" )
end
end
end
hook.Add( "PlayerSay", "Chat", steamgroupCommand )
不和谐聊天脚本(不起作用)
function discordCommand( ply, text)
if string.sub( text, 1, 8 ) == "!discord" then
ply:PrintMessage( 3, "It Worked!" )
ply:SendLua([[gui.OpenURL("https://discord.gg/35rQxcE")]])
for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. ply:Nick() .. " has used !discord to view our official Discord server!" )
end
end
end
hook.Add( "PlayerSay", "Chat", discordCommand )
答案 0 :(得分:0)
如果查看documentation of hook.Add
,您将看到有关所需参数的详细信息。
第二个参数对你很重要
因此,根据这一点,您需要更改hook.Add
的第二个参数
(在你的情况下,对于你的两个钩子都是"chat"
)对于每个钩子都是唯一的,不会覆盖你的其他钩子。
答案 1 :(得分:0)
这种方式可行,因为这是我在服务器上执行的操作。
if(CLIENT) then
concommand.Add("steam", function()
gui.OpenURL("http://steamcommunity.com/groups/PhantomNetworksCommunity")
end)
end
if(SERVER) then
hook.Add("PlayerSay", "OpenSteam", function(calling, txt, t)
local args = string.lower(txt)
if(args == "!steam") then
calling:ConCommand("steam")
return ""
end
end)
end
你可以在不和谐邀请中做同样的事情。
编辑:
我从来没有意识到你打印过聊天,所以我会告诉你一个很好的方法(或修复它):
if(CLIENT) then
concommand.Add("steam", function()
gui.OpenURL("http://steamcommunity.com/groups/PhantomNetworksCommunity")
end)
concommand.Add("discord", function()
gui.OpenURL("https://discord.gg/35rQxcE")
end)
concommand.Add(".prt", function(calling, cmds, args, argStr)
chat.AddText(Color(255, 255, 255), "Player", Color(98, 176, 255), args[1], Color(255, 255,255), " has used ", Color(255, 62, 62), "!steam", Color(255, 255, 255), " to view our community Steam Group!")
end)
concommand.Add(".disprt", function(calling, cmds, args, argStr)
chat.AddText(Color(255, 255, 255), "Player", Color(98, 176, 255), args[1], Color(255, 255,255), " has used ", Color(255, 62, 62), "!discord", Color(255, 255, 255), " to view our official Discord server!")
end)
end
if(SERVER) then
hook.Add("PlayerSay", "ChatCommands", function(calling, txt, t)
local args = string.lower(txt)
if(args == "!steam") then
calling:ConCommand("steam")
for _, ply in pairs(player.GetAll()) do
ply:ConCommand(".prt " .. calling:Nick())
end
return ""
end
if(args == "!discord") then
calling:ConCommand("discord")
for _, ply in pairs(player.GetAll()) do
ply:ConCommand(".disprt " .. calling:Nick())
end
return ""
end
end)
end
编辑2:
另一个可能的错误原因是两个钩子都有相同的名称,"Chat"
答案 2 :(得分:0)
问题是你要覆盖钩子。您应该将第二个参数更改为更具描述性的参数,例如:
hook.Add( "PlayerSay", "ChatSteamGroup", steamgroupCommand )
和hook.Add( "PlayerSay", "ChatDiscord", discordCommand )