Jump to content

Bloquear PVP em mapa


kaiquegames069
 Share

Recommended Posts

Eu fiz assim e me da erros.

 

bool battle_is_attackable(LPCHARACTER ch, LPCHARACTER victim)
{
    // Bloqueio de PvP em Mapa
    switch(ch->GetMapIndex()){
        case ID: 64
            { if (victim->IsPC() && ch->IsPC())
                    return false;
            }
    }
    // Bloqueio de PvP em Mapa

    // »ó´ë¹æÀÌ Á×¾úÀ¸¸é Áß´ÜÇÑ´Ù.
    if (victim->IsDead())
        return false;

Link to comment
Share on other sites

  • 1 month later...
1 hora atrás, kaiquegames069 disse:

Tem alguma forma dessa função só funcionar quando eu ativar o evento pvm?

No caso:

game.set_event_flag("evento_pvm", 1)  - Os players não conseguem atacar outros players.

game.set_event_flag("evento_pvm", 0) - Os players já podem atacar normalmente.

	DWORD dwFlagBlockAtaque = quest::CQuestManager::instance().GetEventFlag("evento_pvm");
	
	if ((dwFlagBlockAtaque == 1) && (GetMapIndex() == 1 || GetMapIndex() == 21 || GetMapIndex() == 41)) {
		if (victim->IsPC() && ch->IsPC())
			return false;
	}

Isso deve funcionar.

Edited by Sinval
Link to comment
Share on other sites

55 minutos atrás, kaiquegames069 disse:

Tem alguma forma dessa função só funcionar quando eu ativar o evento pvm?

No caso:

game.set_event_flag("evento_pvm", 1)  - Os players não conseguem atacar outros players.

game.set_event_flag("evento_pvm", 0) - Os players já podem atacar normalmente.

 

#include "questmanager.h"
	if (quest::CQuestManager::instance().GetEventFlag("disable_event_pvm") == 0)
    {
        switch (ch->GetMapIndex())
        {
            case 1:
            {
                if (victim->IsPC() && ch->IsPC())
                return false;
            }
        }
    }

Link to comment
Share on other sites

ch->GetMapIndex() é a função que diz em que mapa o jogador está

O que o switch faz é avaliar o valor dessa mesma função

ch->GetMapIndex()

 

case X:   Permite realizar uma ação quando o valor da função for X

 

Também poderia ser feito com if, mas com case fica mais rápido adicionar novos valores, pois podes ter vários case a realizar a mesma função. Em termos de escrita fica mais curto do que if e visualmente mais apelativo no tema do tópico

case 1:
case 3:
case 4:
{
açãoASD();
açãoQWE();
}
case 2:
case 6:
{
açãoZXC();
}

 

Também podes realizar uma ação caso o valor da função seja diferente dos colocados nos case. Isto será realizado caso a função não seja nenhum dos valores anteriores.

default equivale ao else do if

Através do seguinte:

default:
{
açãoQWERTY();
}

____________

Exemplo do uso de if e for (função do Vegas):

#ifdef ENABLE_NEW_AFFECT_POTION
			int listAffects[] = {
				AFFECT_POTION_1, AFFECT_POTION_2, AFFECT_POTION_3, AFFECT_POTION_4, AFFECT_POTION_5, AFFECT_POTION_6};
			
			for (int i = 0; i < _countof(listAffects); i++)
			{
				if (pkAff->dwType == listAffects[i])
				{
					++it;
					continue;
				}
			}
#endif

Exemplo de como neste caso, um switch seria bem mais simples e rápido, sendo por isso mais eficiente no tempo gasto a codificar:

#ifdef ENABLE_NEW_AFFECT_POTION
			switch (pkAff->dwType){
				case AFFECT_POTION_1:
				case AFFECT_POTION_2:
				case AFFECT_POTION_3:
				case AFFECT_POTION_4:
				case AFFECT_POTION_5:
				case AFFECT_POTION_6:
				{	++it;
					continue;}}
#endif

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...