Garry的Mod - Props在启动Lua脚本后不会产生

时间:2016-10-05 19:40:42

标签: lua

我有一个gmod的测试服务器。我编写了一个在我启动时运行良好的脚本,但它有很多缺点。

我尝试编写一个脚本,如果他们输入“!speed fast”或“!speed normal”这样的命令,只会改变用户的速度。它看起来像这样:

table = {}
table[0]="!help"
table[1]="!speed normal"
table[2]="!speed fast"
table[3]="!speed sanic"    
hook.Add("PlayerSay", "Chat", function(ply, message, teamchat)
    if message == "!speed normal" then
        GAMEMODE:SetPlayerSpeed(ply, 250, 500 )
    elseif message == "!speed fast" then
        GAMEMODE:SetPlayerSpeed(ply, 1000, 2000 )
    elseif message == "!speed sanic" then
        GAMEMODE:SetPlayerSpeed(ply, 10000, 20000)
    elseif message == "!help" then
        for key, value in pairs(table) do
            PrintMessage( HUD_PRINTTALK, value)
        end
    end
end)

正如您所看到的,如果脚本在聊天中键入“!speed normal”,“!speed fast”或“!speed sanic”,则会更改用户速度。该脚本还包含每个命令的表,如果用户在聊天中键入“!help”,则会显示该表。

当我启动脚本时,它的效果非常好,但是如果我在启动后尝试生成道具,则道具不会产生。即使我先生成一个道具,然后启动脚本并尝试“撤消”道具,“撤消”功能将无效!该脚本使Sandbox游戏模式完全无用,因为你甚至无法生成道具!

我试图先在互联网上搜索一下,但我还没有偶然发现这样的事情,所以我希望有人能得到解决方案!请帮忙

1 个答案:

答案 0 :(得分:2)

我的猜测是,这种情况正在发生,因为你正在覆盖全球tableThe table library contains helper functions for tables。尝试将表格table重命名为其他内容,例如commands。我还建议您将其声明为local commands,因此它不会替换任何其他全局,因此它不会干扰其他任何内容,如其他脚本或库。

另外,作为额外提示,lua表的索引为1,因此您可以将重命名的表声明为:

local commands = {
    "!help",
    "!speed normal",
    "!speed fast",
    "!speed sanic",
}

然后,您可以使用普通for

对其进行迭代
for index = 1, #commands do
    PrintMessage(HUD_PRINTTALK, commands[index])
end

我认为这让我觉得它更清洁了。