Esempio n. 1
0
bool TalkAction::placeNpc(Player* player, const std::string& words, const std::string& param)
{
	if (!player)
	{
		return false;
	}

	Npc* npc = Npc::createNpc(param);

	if (!npc)
	{
		player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "This NPC does not exist.");
		return false;
	}

	// Place the npc
	if (g_game.placeCreature(npc, player->getPosition()))
	{
		g_game.addMagicEffect(player->getPosition(), NM_ME_MAGIC_BLOOD);
		npc->setMasterPos(npc->getPosition());
		return true;
	}
	else
	{
		delete npc;
		player->sendCancelMessage(RET_NOTENOUGHROOM);
		g_game.addMagicEffect(player->getPosition(), NM_ME_PUFF);
	}

	return false;
}
Esempio n. 2
0
int NpcScriptInterface::luagetDistanceTo(lua_State *L)
{
	//getDistanceTo(uid)
	uint32_t uid = popNumber(L);

	ScriptEnviroment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	Thing* thing = env->getThingByUID(uid);
	if(thing && npc){
		Position thing_pos = thing->getPosition();
		Position npc_pos = npc->getPosition();
		if(npc_pos.z != thing_pos.z){
			lua_pushnumber(L, -1);
		}
		else{
			int32_t dist = std::max(std::abs(npc_pos.x - thing_pos.x), std::abs(npc_pos.y - thing_pos.y));
			lua_pushnumber(L, dist);
		}
	}
	else{
		reportErrorFunc(getErrorDesc(LUA_ERROR_THING_NOT_FOUND));
		lua_pushnil(L);
	}

	return 1;
}
Esempio n. 3
0
int32_t NpcScriptInterface::luaSelfGetPos(lua_State* L)
{
	//selfGetPosition()
	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		pushPosition(L, npc->getPosition(), 0);
	} else {
		lua_pushnil(L);
	}
	return 1;
}
Esempio n. 4
0
int32_t NpcScriptInterface::luaGetNpcPos(lua_State* L)
{
	//getNpcPos()
	Position pos;
	uint32_t stackpos = 0;

	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		pos = npc->getPosition();
		stackpos = npc->getParent()->__getIndexOfThing(npc);
	}

	pushPosition(L, pos, stackpos);
	return 1;
}
Esempio n. 5
0
int32_t NpcScriptInterface::luaSelfGetPos(lua_State* L)
{
	//selfGetPosition()
	ScriptEnvironment* env = getScriptEnv();
	Npc* npc = env->getNpc();

	if (npc) {
		Position pos = npc->getPosition();
		pushPosition(L, pos);
	} else {
		lua_pushnil(L);
	}

	return 1;
}
Esempio n. 6
0
void Commands::placeNpc(Player* player, const std::string& cmd, const std::string& param)
{
	Npc* npc = Npc::createNpc(param);
	if (!npc) {
		return;
	}

	// Place the npc
	if (g_game.placeCreature(npc, player->getPosition())) {
		g_game.addMagicEffect(player->getPosition(), NM_ME_MAGIC_BLOOD);
		npc->setMasterPos(npc->getPosition());
	} else {
		delete npc;
		player->sendCancelMessage(RET_NOTENOUGHROOM);
		g_game.addMagicEffect(player->getPosition(), NM_ME_POFF);
	}
}
Esempio n. 7
0
int NpcScriptInterface::luaSelfGetPos(lua_State *L)
{
	//selfGetPosition()
	ScriptEnviroment* env = getScriptEnv();
	Npc* npc = env->getNpc();
	if(npc){
		Position pos = npc->getPosition();
		lua_pushnumber(L, pos.x);
		lua_pushnumber(L, pos.y);
		lua_pushnumber(L, pos.z);
	}
	else{
		lua_pushnil(L);
		lua_pushnil(L);
		lua_pushnil(L);
	}

	return 3;
}
bool sortCondition(Npc &s1, Npc &s2) {
    return s1.getPosition().y < s2.getPosition().y;
}