因此,我目前正在嘗試創建一個小腳本,用於當GMOD中的玩家輸入「!content」時,例如,他們將通過將導致他們到Steam該服務器的內容。對於前面的例子,它的工作,所以我然後試圖複製的模板,只是改變功能名稱等我沒有遇到與示例相同的結果,但似乎沒有發生,我不知道爲什麼,因爲我只有改變了函數名和字符串。如果你能幫助我,這將是偉大的。提前致謝。Lua與GMOD自定義聊天腳本的問題
汽集團聊天腳本(工程)
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)
我忘了補充該文件位於\ garrysmod \ LUA \自動運行 – Ryke
你有多個掛鉤?你似乎對兩者都使用相同的標識符;每個標識符只能有一個鉤子函數:https://wiki.garrysmod.com/page/hook/Add –