Hello. Some time ago I was trying to solve problem of npcs that says message one by one with delay.
I don't know if anyone solved this, any way I thought I can share my code with you guys
It's an easy c++ function added to luascript.cpp and handled properly in lua: )
So lets go.
open your luascript.cpp and add method:
Under :
add:
and in luascript.h under:
add:
Ok now you have a function that works almost like selfSay but it takes nid (npc id ) as a parameter.
You can use this lua function to make npc say some stuff with delay.
I would explain what each parameter mean there, but I think you can figure it out yourself : )
Have fun with it, make it perfect etc : )
Regards.
I don't know if anyone solved this, any way I thought I can share my code with you guys
It's an easy c++ function added to luascript.cpp and handled properly in lua: )
So lets go.
open your luascript.cpp and add method:
Code:
int32_t LuaScriptInterface::luaDoNpcSay(lua_State* L)
{
//doNpcSay(nid,txt,speaktype,cid)
uint32_t uid =popNumber(L);
SpeakClasses type = SPEAK_SAY;
type = (SpeakClasses)popNumber(L);
std::string text = popString(L);
ScriptEnviroment* env = getEnv();
if(Creature* creature = env->getCreatureByUID(popNumber(L)))
{
Npc* npc = creature->getNpc();
Creature* creature = env->getCreatureByUID(uid);
if(npc){
npc->doSay(text,type,creature->getPlayer());
lua_pushboolean(L, true);
}
}
else
{
errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
lua_pushboolean(L, false);
}
return 1;
}
Code:
//doCreatureSay(uid, text[, type = SPEAK_SAY[, ghost = false[, cid = 0[, pos]]]])
lua_register(m_luaState, "doCreatureSay", LuaScriptInterface::luaDoCreatureSay);
Code:
//doNpcSay(nid,txt,speaktype[,cid])
lua_register(m_luaState, "doNpcSay", LuaScriptInterface::luaDoNpcSay);
and in luascript.h under:
Code:
static int32_t luaDoCreatureSay(lua_State* L);
Code:
static int32_t luaDoNpcSay(lua_State* L);
Ok now you have a function that works almost like selfSay but it takes nid (npc id ) as a parameter.
You can use this lua function to make npc say some stuff with delay.
Code:
local texts = {
{"this is showed always at 0", 1500},
{"im showed after 1500", (4000-1500)},
{"I will be show after 4 seconds xD", 5000},
{"test4", 5000},
}
function delays(nid,cid,array,iter,npcHandler)
if(not npcHandler:isFocused(cid)) then
return false
end
if array[iter] ~= nil then
doNpcSay(nid,array[iter][1],TALKTYPE_PRIVATE_NP,cid)
addEvent(delays,array[iter][2],nid,cid,array,iter+1,npcHandler)
end
end
--caling the function
delays(getNpcId(),cid,texts,1,npcHandler)
I would explain what each parameter mean there, but I think you can figure it out yourself : )
Have fun with it, make it perfect etc : )
Regards.
Last edited: