Garrys Mod Lua问题(检查相等并打印)

我没有任何错误。 我的脚本可以获取新武器的名称,但无法检查与hololink_swep是否相等。 等于的打印不出现。 请帮忙。

我的代码:

hook.Add("PlayerSwitchWeapon"function(ply,oldWeapon,newWeapon)
    print"您的新武器是".. newWeapon:GetClass().."。");
        if(newWeapon == hololink_swep)then
            print"这个武器很特殊".. newWeapon:GetClass().."。");
        结束
结束);
点赞
用户9819479
用户9819479

如果 (将新武器转换成字符串 等于 hololink_swep 转换成字符串),则

2019-09-18 16:57:07
用户11580088
用户11580088
hook.Add("PlayerSwitchWeapon", "some name of hook", function(ply, oldWeapon, newWeapon)
    print("您的新武器是 " .. newWeapon:GetClass() .. "。")
    if (newWeapon == "hololink_swep") then
        print("这个武器很特别" .. newWeapon:GetClass() .. "。")
    end
end)

同时请不要忘记给您的 hook 命名。我将示例命名为 some name of hook

2019-09-23 15:46:14