worldobject:索引worldobject时出现RegisterEvent错误

时间:2019-06-19 20:26:22

标签: lua azerothcore eluna-lua-engine

当我尝试使用网站上显示的示例进行世界对象注册事件时,我在世界对象上遇到错误,这意味着它是一个nil值,如下所示:

  

lua_scripts / test.lua:5:尝试索引全局'worldobject'(nil值)

尝试了一些具有相同结果的不同示例,因此自然而然地我希望它可能受到一些监督。

经过测试的示例:

local function YourFunction(eventid, delay, repeats, worldobject)
      worldobject:SendUnitSay("My name is " .. worldobject:GetName(), 255)
end
worldobject:RegisterEvent(YourFunction, 10000, 5)
local function Timed(eventid, delay, repeats, worldobject)
    print(worldobject:GetName())
end
worldobject:RegisterEvent(Timed, 1000, 5)

两者都返回开头指出的错误。

1 个答案:

答案 0 :(得分:5)

您必须指定哪个worldobject应该具有脚本。

以下是一个生物的示例:

local npcID = 100;
local YourNPC = {};

function YourNPC.YourFunction(eventid, delay, repeats, creature)
      creature:SendUnitSay("My name is " .. creature:GetName(), 255)
end

function YourNPC.OnSpawn(event, creature)
    creature:RegisterEvent(YourNPC.YourFunction, 10000, 5)
end

RegisterCreatureEvent(npcID, YourNPC.OnSpawn, 5)

在生物产生时,该生物会说出5次“我的名字是”,延迟10秒。 它只会对生物“ 100”起作用,因此,不要忘记更改ID。

Eluna官方文档:http://www.elunaengine.com/WorldObject/RegisterEvent.html