无法在 GMod 中使用 Hook PlayerSay

我在 IPS Hosting 的测试服务器上尝试了我的插件,但我的 PlayerSay Hook 不起作用了。 如果我在本地测试服务器上尝试,则可以正常工作。

hook.Add("PlayerSay", "Testing", function(ply, text)
    if string.lower(text) == "/test" then
        print("test")
    end
end)
点赞
用户12288662
用户12288662

PlayerSay 是一个服务器端的钩子。如果在聊天中输入“/test”并且在服务器控制台中没有看到打印输出,那么很可能是因为服务器未运行该代码。 要确保服务器运行了该代码,您的文件必须被包含在autorun文件夹中的文件中,或者必须将文件移至autorun文件夹中。

此外,请确保只有服务器运行该代码,因为客户端没有该钩子,如果该代码在客户端上运行,将会返回Lua错误。

if SERVER then -- 只在服务器运行,不在客户端运行
    hook.Add("PlayerSay", "Testing", function(ply, text)
        if string.lower(text) == "/test" then
            print("test")
        end
    end)
end

如果您仍然有不理解的地方,请告诉我,我可以编辑我的回答。

2021-07-19 12:57:28