luascript.cpp - where else? x)
luascript.h
done!
I made it based on the placeNpc command, it does the same thing (summons npc) and its syntax is:
name is the name of the npc's xml file without .xml at the end(like in the command)
position is the position where the npc shall be summoned(like in doPlaceCreature)
you may think of it as a doPlaceCreature that instead of monsters places npcs
it can be useful to placeNpcs ingame (after the server is loaded) and without the need of a gamemaster (as happens with the command)
you can put it on actions/talkactions/movements/npc's scripts/creaturescripts(added recently ^^)/spells/weapons/ and anything else your crazy mind conceives (like an addEvent by global.lua that is independent of any other scripts found in the folders above and checks from hour to hour if a npc was killed, loading the first npc not from map but from global.lua so you can know his uniqueid and check his aliveness, and if so replaces it)
Code:
//placeNpc(name, pos)
lua_register(m_luaState, "placeNpc", LuaScriptInterface::luaPlaceNpc);
Code:
int32_t LuaScriptInterface::luaPlaceNpc(lua_State *L)
{
//placeNpc(name, pos)
Position pos;
uint32_t stackpos;
popPosition(L, pos, stackpos);
const char *name = popString(L);
ScriptEnviroment* env = getScriptEnv();
Npc* npc = new Npc(name);
if(!npc->isLoaded())
{
delete npc;
std::string error_str = (std::string)"Npc name(" + name + (std::string)") not found";
reportErrorFunc(error_str);
lua_pushnumber(L, LUA_ERROR);
return 1;
}
// Place the npc
if(!g_game.placeCreature(npc, (Position&)pos))
{
delete npc;
std::string error_str = (std::string)"Can not summon npc: " + name;
reportErrorFunc(error_str);
lua_pushnumber(L, LUA_ERROR);
return 1;
}
uint32_t cid = env->addThing((Thing*)npc);
lua_pushnumber(L, cid);
return 1;
}
Code:
static int32_t luaPlaceNpc(lua_State* L);
I made it based on the placeNpc command, it does the same thing (summons npc) and its syntax is:
Code:
placeNpc(name,position)
position is the position where the npc shall be summoned(like in doPlaceCreature)
you may think of it as a doPlaceCreature that instead of monsters places npcs
it can be useful to placeNpcs ingame (after the server is loaded) and without the need of a gamemaster (as happens with the command)
you can put it on actions/talkactions/movements/npc's scripts/creaturescripts(added recently ^^)/spells/weapons/ and anything else your crazy mind conceives (like an addEvent by global.lua that is independent of any other scripts found in the folders above and checks from hour to hour if a npc was killed, loading the first npc not from map but from global.lua so you can know his uniqueid and check his aliveness, and if so replaces it)
Last edited: