Ir para conteúdo

Posts Recomendados

Nome: doPlayerSetInvisible(cid)

Tipo: Função Lua/C++

Autor: Oneshot

 


 

Todos sabem que na maioria dos servidores atuais existe uma função "interna" para talkactions que deixa o jogador invisível.

 

Como já vi alguns pedidos de funções parecidas nas seções de pedidos, fiz algumas adaptações nesta função interna para que funcionasse como uma função Lua, a qual você poderá usar em actions e etcétera.

 

Sendo assim, basta seguir os passos abaixo.

 


 

1. Vá em luascript.h e procure pela linha abaixo:

 

static int32_t luaDoCreatureSetNoMove(lua_State* L);

 

Adicione logo abaixo:

 

static int32_t luaDoPlayerSetInvisible(lua_State* L);

 

 

2. Em luascript.cpp, procure por:

 

0.3.6

lua_register(m_luaState, "doCreatureSetNoMove", LuaScriptInterface::luaDoCreatureSetNoMove);

 

0.4

lua_register(m_luaState, "doCreatureSetNoMove", LuaInterface::luaDoCreatureSetNoMove);

 

Adicione logo abaixo:

 

0.3.6

lua_register(m_luaState, "doPlayerSetInvisible", LuaScriptInterface::luaDoPlayerSetInvisible);

 

0.4

lua_register(m_luaState, "doPlayerSetInvisible", LuaInterface::luaDoPlayerSetInvisible);

 

3. Ainda em luascript.cpp, procure por:

 

0.3.6

int32_t LuaScriptInterface::luaDoCreatureSetNoMove(lua_State* L)

[b]0.4[/b]
[code]
int32_t LuaInterface::luaDoCreatureSetNoMove(lua_State* L)

 

Adicione logo abaixo do fim da função:

 

0.3.6


int32_t LuaScriptInterface::luaDoPlayerSetInvisible(lua_State* L)
{
  //doPlayerSetInvisible(cid)

  ScriptEnviroment* env = getEnv();
  Player* player = env->getPlayerByUID(popNumber(L));
  if(!player)
  {
  errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  lua_pushboolean(L, false);
  return 1;
  }

  SpectatorVec::iterator it;
  SpectatorVec list = g_game.getSpectators(player->getPosition());
  Player* tmpPlayer = NULL;

  Condition* condition = NULL;
if((condition = player->getCondition(CONDITION_GAMEMASTER, CONDITIONID_DEFAULT, GAMEMASTER_INVISIBLE)))
{
	player->setHideHealth(false);
	g.game->addCreatureHealth(player);
	IOLoginData::getInstance()->updateOnlineStatus(player->getGUID(), true);
	for(AutoList<Player>::iterator pit = Player::autoList.begin(); pit != Player::autoList.end(); ++pit)
	{
		if((tmpPlayer = pit->second) && !tmpPlayer->canSeeCreature(player))
			tmpPlayer->notifyLogIn(player);
	}

	for(it = list.begin(); it != list.end(); ++it)
	{
		if((tmpPlayer = (*it)->getPlayer()) && !tmpPlayer->canSeeCreature(player))
			tmpPlayer->sendMagicEffect(player->getPosition(), MAGIC_EFFECT_TELEPORT);
	}

	player->removeCondition(condition);
	g_game.internalCreatureChangeVisible(player, VISIBLE_GHOST_APPEAR);
}
else if((condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_GAMEMASTER, -1, 0, false, GAMEMASTER_INVISIBLE)))
{
	player->addCondition(condition);
	player->setHideHealth(true);
	g.game->addCreatureHealth(player);
	g_game.internalCreatureChangeVisible(player, VISIBLE_GHOST_DISAPPEAR);
	for(it = list.begin(); it != list.end(); ++it)
	{
		if((tmpPlayer = (*it)->getPlayer()) && !tmpPlayer->canSeeCreature(player))
			tmpPlayer->sendMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
	}

	for(AutoList<Player>::iterator pit = Player::autoList.begin(); pit != Player::autoList.end(); ++pit)
	{
		if((tmpPlayer = pit->second) && !tmpPlayer->canSeeCreature(player))
			tmpPlayer->notifyLogOut(player);
	}

	IOLoginData::getInstance()->updateOnlineStatus(player->getGUID(), false);
	if(player->isTrading())
		g_game.internalCloseTrade(player);

	player->clearPartyInvitations();
	if(player->getParty())
		player->getParty()->leave(player);
}
lua_pushboolean(L, true);
return 1;
}

 

0.4


int32_t LuaInterface::luaDoPlayerSetInvisible(lua_State* L)
{
  //doPlayerSetInvisible(cid)

  ScriptEnviroment* env = getEnv();
  Player* player = env->getPlayerByUID(popNumber(L));
  if(!player)
  {
  errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  lua_pushboolean(L, false);
  return 1;
  }

  SpectatorVec::iterator it;
  SpectatorVec list = g_game.getSpectators(player->getPosition());
  Player* tmpPlayer = NULL;

  Condition* condition = NULL;
if((condition = player->getCondition(CONDITION_GAMEMASTER, CONDITIONID_DEFAULT, GAMEMASTER_INVISIBLE)))
{
	player->setHideHealth(false);
	g.game->addCreatureHealth(player);
	IOLoginData::getInstance()->updateOnlineStatus(player->getGUID(), true);
	for(AutoList<Player>::iterator pit = Player::autoList.begin(); pit != Player::autoList.end(); ++pit)
	{
		if((tmpPlayer = pit->second) && !tmpPlayer->canSeeCreature(player))
			tmpPlayer->notifyLogIn(player);
	}

	for(it = list.begin(); it != list.end(); ++it)
	{
		if((tmpPlayer = (*it)->getPlayer()) && !tmpPlayer->canSeeCreature(player))
			tmpPlayer->sendMagicEffect(player->getPosition(), MAGIC_EFFECT_TELEPORT);
	}

	player->removeCondition(condition);
	g_game.internalCreatureChangeVisible(player, VISIBLE_GHOST_APPEAR);
}
else if((condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_GAMEMASTER, -1, 0, false, GAMEMASTER_INVISIBLE)))
{
	player->addCondition(condition);
	player->setHideHealth(true);
	g.game->addCreatureHealth(player);
	g_game.internalCreatureChangeVisible(player, VISIBLE_GHOST_DISAPPEAR);
	for(it = list.begin(); it != list.end(); ++it)
	{
		if((tmpPlayer = (*it)->getPlayer()) && !tmpPlayer->canSeeCreature(player))
			tmpPlayer->sendMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
	}

	for(AutoList<Player>::iterator pit = Player::autoList.begin(); pit != Player::autoList.end(); ++pit)
	{
		if((tmpPlayer = pit->second) && !tmpPlayer->canSeeCreature(player))
			tmpPlayer->notifyLogOut(player);
	}

	IOLoginData::getInstance()->updateOnlineStatus(player->getGUID(), false);
	if(player->isTrading())
		g_game.internalCloseTrade(player);

	player->clearPartyInvitations();
	if(player->getParty())
		player->getParty()->leave(player);
}
lua_pushboolean(L, true);
return 1;
}

 


 

Eu só adaptei a função interna exclusiva das talkactions para uma função Lua. É claro que eu poderia fazer algo BEM melhor, editando a função canSee, por exemplo.

 

Abraços.

Editado por Oneshot
Link para o comentário
https://xtibia.com/forum/topic/203754-doplayersetinvisiblecid/
Compartilhar em outros sites

×
×
  • Criar Novo...