gpt4 book ai didi

audio - Gmod-Lua错误- 'Attempting to index field ' GM'(零值)

转载 作者:行者123 更新时间:2023-12-03 00:45:23 24 4
gpt4 key购买 nike

好的,几天前我刚刚了解了Lua,并且我尝试制作了一个非常基本的脚本,这当然是行不通的。

function GM:OnNPCKilled( victim, killer, weapon )
local noise = Sound("sadviolin.wav")
end

我得到错误:

Attempting to index field 'GM' (a nil value)



我要做的就是在NPC被杀死时播放声音。

最佳答案

从头开始创建游戏模式时,只能使用“GM:OnNPCKilled”
使用此代替:

function FOnNPCKilled( victim, killer, weapon )

local noise = Sound("sadviolin.wav")
end
hook.Add("OnNPCKilled", "UniqueIdentifier1", FOnNPCKilled)


顺便说一句,我修复了您的函数,并且我了解您要尝试做的事情,但是该代码不会在玩家死亡时发出声音,您只会创建具有声音值的var。
为此,请改用此方法:

function FOnNPCKilled( victim, killer, weapon )

surface.PlaySound( "sadviolin.wav", victim:GetPos() )

end

hook.Add("OnNPCKilled", "UniqueIdentifier1", FOnNPCKilled)

关于audio - Gmod-Lua错误- 'Attempting to index field ' GM'(零值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27834192/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com