logoHourGlass
CreateNPC

NL.CreateNPC

NL.CreateNPC(Dofile, InitFuncName)

函數功能

使用Lua腳本創建NPC,並執行Dofile文件中的InitFuncName函數。

參數說明

  • Dofile:字符串 要加載的腳本文件名,如果爲當前文件,則定義nil即可
  • InitFuncName:字符串 Init函數的名稱,NPC創建後執行的函數,申明格式請參考下面的[InitCallBack]

返回值

創建成功則返回 對象index, 失敗則返回負數

語法

InitCallBack(CharIndex)

參數說明

CharIndex: 數值型 響應事件的對象index,該值由Lua引擎傳遞給本函數。

返回值

返回0即可

參考實例

init.lua

if(TestNPC == nil)then
  TestNPC = NL.CreateNpc("lua/testnpc.lua","MyCharInit");
end

testnpc.lua

function MyCharInit(_myIndex)
  return true;
end