• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

PvP System

merfus

Member
Joined
Dec 27, 2011
Messages
214
Reaction score
5
Location
Poland
Edit:

I got this system but for 7.6 can anyone change it for tfs 0.3.6pl1? Or it will work on TFS 0.3.6pl1?
And if anyone can change something in this script for that it always are secure mode on (player can't do secure mode off) but if you just change it for 0.3.6pl1 it will be great.

How it works?
Secure mode off - you can't kill and attack anyone.
Secure mode on - you can attack with spells and kill only the marked player, if you use spells like AOE and it hits some player but you don't marked him, you dont deal him dmg and don't get skull (it just ignore player)

i got this system but for 7.6 can anyone change it for tfs 0.3.6pl1? Or it will work on tfs 0.3.6pl1?
And if anyone can change something in this script for that it always are secure mode on (player can't do secure mode off) but if you just change that for tfs 0.3.6pl1 it will be gr

written by baabuseek with credits to conan for testing.

Here is script:

In game.cpp below:

PHP:
#ifdef yur_rings_amulets
		damage = applyamulets(targetplayer, damage, me->attacktype);
#endif //yur_rings_amulets

add

PHP:
#ifdef _ng_bbk_pvp__     
			pvparena = ispvparena(attackplayer) && ispvparena(targetplayer);  
			creature *monster = dynamic_cast<monster*>(targetcreature);
   if (damage > 0) {
        creature *targetmonster = dynamic_cast<creature*>(targetcreature);
          if(attackplayer  && attackplayer->atkmode == 1 && !pvparena)
            {
              if(targetplayer == targetmonster)
               {
                  if(targetplayer->party == 0 || attackplayer->party == 0 && attackplayer->party != targetplayer->party){
                  damage = 0;
                  }
               }
         }
   }

 if (attackplayer && !monster && damage > 0) {
            creature *attackedcreature = game->getplayerbyid(attackplayer->attackedcreature);
      if(attackplayer->atkmode == 0 && attackplayer->access <= g_config.access_protect && !pvparena)
            {
                if(attackedcreature != targetplayer)
                {
                    if(targetplayer->party == 0 || attackplayer->party == 0 && attackplayer->party != targetplayer->party){
                    damage = 0;
                    }
                }
            }
    }
#endif //_ng_bbk_pvp__

slighty below below that:

PHP:
if (damage > 0) {
	if(attackplayer && attackplayer->access < g_config.access_protect) {

change that:

PHP:
if(targetplayer && targetplayer != attackplayer && game->getworldtype() != world_type_no_pvp)

for:

PHP:
#ifdef _ng_bbk_pvp__
				if(targetplayer && targetplayer != attackplayer && game->getworldtype() != world_type_no_pvp && damage != 0 && !pvparena)
#else
				if(targetplayer && targetplayer != attackplayer && game->getworldtype() != world_type_no_pvp)
#endif //_ng_bbk_pvp__

again little below
PHP:
		attackplayer->pzlocked = true;
}

change that:

PHP:
if(targetcreature->access < g_config.access_protect && targetplayer && game->getworldtype() != world_type_no_pvp)

for

PHP:
#ifdef _ng_bbk_pvp__
			if(targetcreature->access < g_config.access_protect && targetplayer && game->getworldtype() != world_type_no_pvp && !pvparena)
#else
			if(targetcreature->access < g_config.access_protect && targetplayer && game->getworldtype() != world_type_no_pvp)
#endif //_ng_bbk_pvp__

still in game.cpp, find
PHP:
	case fight_magicdist:
		If((std::abs(creature->pos.x-attackedcreature->pos.x) <= 8) &&
			(std::abs(creature->pos.y-attackedcreature->pos.y) <= 5) &&
			(creature->pos.z == attackedcreature->pos.z)) {

				//if(map->canthrowitemto(creature->pos, attackedcreature->pos, false, true))
				if(map->canthrowobjectto(creature->pos, attackedcreature->pos, block_projectile) == ret_noerror)
					inreach = true;
			}
	break;

}

and below this change that line:
PHP:
if (player && player->access < g_config.access_protect)

for

PHP:
#ifdef _ng_bbk_pvp__
  bool pvparena = false;
  pvparena = ispvparena(player) && ispvparena(attackedplayer);
	if (player && player->access < g_config.access_protect && !pvparena)
#else
	if (player && player->access < g_config.access_protect)
#endif //_ng_bbk_pvp__

below this

PHP:
	player->sendicons();
	if(attackedplayer)
		player->pzlocked = true;
}[php]

change that:

[php]if(attackedplayer && attackedplayer->access < g_config.access_protect)

for

PHP:
#ifdef _ng_bbk_pvp__
	if(attackedplayer && attackedplayer->access < g_config.access_protect && !pvparena)
#else
	if(attackedplayer && attackedplayer->access < g_config.access_protect)
#endif //_ng_bbk_pvp__

still in game.cpp in function

PHP:
void game::checkcreatureattacking(unsigned long id)

find that

PHP:
else {
	if (creature->attackedcreature != 0)
	{
		creature *attackedcreature = getcreaturebyid(creature->attackedcreature);

and under that add:

PHP:
#ifdef _ng_bbk_pvp__
player *player = dynamic_cast<player*>(creature);
player *attackedplayer = dynamic_cast<player*>(attackedcreature);
bool pvparena = false;
       pvparena = ispvparena(player) && ispvparena(attackedplayer);  
      if(player && player->atkmode == 1 && attackedplayer && !pvparena) {
  if(attackedplayer->party == 0 || player->party == 0 && player->party != attackedplayer->party){
     player->sendcancelattacking();
     player->sendtextmessage(msg_smallinfo, "turn off secure mode if you really want to attack unmarked players.");
     playersetattackedcreature(player, 0);
    return;
  }
        }
#endif //_ng_bbk_pvp__[php]

in function:

[php]void game::onpvp(creature* creature, creature* attacked, bool murder)

under that:

PHP:
if (player->party != 0 && attackedplayer->party != 0 && player->party == attackedplayer->party)
	return;

add:

PHP:
#ifdef _ng_bbk_pvp__    
 bool pvparena = false;
  pvparena = ispvparena(player) && ispvparena(attackedplayer);  
  
  	if (pvparena)
		return;
       
     creature *attackedcreature = getcreaturebyid(player->attackedcreature);
      if(player->atkmode == 0)
        {
           if(attackedcreature != attackedplayer)
          {
            return;
          }
     }
    if (player->atkmode == 1)
        return;
#endif //_ng_bbk_pvp__

at the bottom game.cpp add:

PHP:
#ifdef _ng_bbk_pvp__
bool game::ispvparena(creature* c)
{
	if (!c)
		return false;
	tile *tile = map->gettile(c->pos);
	return tile && tile->ispvparena();
}
#endif //_ng_bbk_pvp__

now in game.h below that:

PHP:
class game {
public:
	Game();
  ~game();

add

PHP:
#ifdef _ng_bbk_pvp__
	bool ispvparena(creature* c);
#endif //_ng_bbk_pvp__

now in player.cpp below that

PHP:
guildid    = 0;

add

PHP:
#ifdef _ng_bbk_pvp__	
	atkmode = 0;
#endif //_ng_bbk_pvp__

now in protocol76.cpp (i dont have it in tfs 0.3.6pl1) below:

PHP:
void protocol76::parsemodes(networkmessage &msg)
{

change that:

PHP:
#ifdef yur_fight_mode
	player->setfightmode(msg.getbyte());
#endif //yur_fight_mode
	//player->fightmode = msg.getbyte();
	//player->followmode = msg.getbyte();
}

for

PHP:
#ifdef yur_fight_mode
	player->setfightmode(msg.getbyte());
#endif //yur_fight_mode
	player->followmode = msg.getbyte();
#ifdef _ng_bbk_pvp__    
    player->atkmode = msg.getbyte();
#endif //_ng_bbk_pvp__ 
}

now in player.h below:

PHP:
class player : Public creature
{
public:

add

PHP:
#ifdef _ng_bbk_pvp__    
bool atkmode;
#endif //_ng_bbk_pvp__
char followmode;

next change that:

PHP:
char fightmode, followmode;

for

PHP:
char fightmode;

at the bottom of project add:

PHP:
-d_ng_bbk_pvp__

rebuild all!
 
Last edited:
I got this system but for 7.6 can anyone change it for tfs 0.3.6pl1? Or it will work on TFS 0.3.6pl1?
And if anyone can change something in this script for that it always are secure mode on (player can't do secure mode off) but if you just change it for 0.3.6pl1 it will be great.

Written by Baabuseek with credits to Conan for testing.

Here is script (Translated to english):

in game.cpp below:

PHP:
#ifdef YUR_RINGS_AMULETS
		damage = applyAmulets(targetPlayer, damage, me->attackType);
#endif //YUR_RINGS_AMULETS

add

PHP:
#ifdef _NG_BBK_PVP__     
			pvpArena = isPvpArena(attackPlayer) && isPvpArena(targetPlayer);  
			Creature *monster = dynamic_cast<Monster*>(targetCreature);
   if (damage > 0) {
        Creature *targetMonster = dynamic_cast<Creature*>(targetCreature);
          if(attackPlayer  && attackPlayer->atkMode == 1 && !pvpArena)
            {
              if(targetPlayer == targetMonster)
               {
                  if(targetPlayer->party == 0 || attackPlayer->party == 0 && attackPlayer->party != targetPlayer->party){
                  damage = 0;
                  }
               }
         }
   }

 if (attackPlayer && !monster && damage > 0) {
            Creature *attackedCreature = game->getPlayerByID(attackPlayer->attackedCreature);
      if(attackPlayer->atkMode == 0 && attackPlayer->access <= g_config.ACCESS_PROTECT && !pvpArena)
            {
                if(attackedCreature != targetPlayer)
                {
                    if(targetPlayer->party == 0 || attackPlayer->party == 0 && attackPlayer->party != targetPlayer->party){
                    damage = 0;
                    }
                }
            }
    }
#endif //_NG_BBK_PVP__

slighty below below that:

PHP:
if (damage > 0) {
	if(attackPlayer && attackPlayer->access < g_config.ACCESS_PROTECT) {

change that:

PHP:
if(targetPlayer && targetPlayer != attackPlayer && game->getWorldType() != WORLD_TYPE_NO_PVP)

for:

PHP:
#ifdef _NG_BBK_PVP__
				if(targetPlayer && targetPlayer != attackPlayer && game->getWorldType() != WORLD_TYPE_NO_PVP && damage != 0 && !pvpArena)
#else
				if(targetPlayer && targetPlayer != attackPlayer && game->getWorldType() != WORLD_TYPE_NO_PVP)
#endif //_NG_BBK_PVP__

Again little below
PHP:
		attackPlayer->pzLocked = true;
}

change that:

PHP:
if(targetCreature->access < g_config.ACCESS_PROTECT && targetPlayer && game->getWorldType() != WORLD_TYPE_NO_PVP)

for

PHP:
#ifdef _NG_BBK_PVP__
			if(targetCreature->access < g_config.ACCESS_PROTECT && targetPlayer && game->getWorldType() != WORLD_TYPE_NO_PVP && !pvpArena)
#else
			if(targetCreature->access < g_config.ACCESS_PROTECT && targetPlayer && game->getWorldType() != WORLD_TYPE_NO_PVP)
#endif //_NG_BBK_PVP__

Still in game.cpp, find
PHP:
	case FIGHT_MAGICDIST:
		if((std::abs(creature->pos.x-attackedCreature->pos.x) <= 8) &&
			(std::abs(creature->pos.y-attackedCreature->pos.y) <= 5) &&
			(creature->pos.z == attackedCreature->pos.z)) {

				//if(map->canThrowItemTo(creature->pos, attackedCreature->pos, false, true))
				if(map->canThrowObjectTo(creature->pos, attackedCreature->pos, BLOCK_PROJECTILE) == RET_NOERROR)
					inReach = true;
			}
	break;

}

and below this change that line:
PHP:
if (player && player->access < g_config.ACCESS_PROTECT)

for

PHP:
#ifdef _NG_BBK_PVP__
  bool pvpArena = false;
  pvpArena = isPvpArena(player) && isPvpArena(attackedPlayer);
	if (player && player->access < g_config.ACCESS_PROTECT && !pvpArena)
#else
	if (player && player->access < g_config.ACCESS_PROTECT)
#endif //_NG_BBK_PVP__

below this

PHP:
	player->sendIcons();
	if(attackedPlayer)
		player->pzLocked = true;
}[php]

change that:

[php]if(attackedPlayer && attackedPlayer->access < g_config.ACCESS_PROTECT)

for

PHP:
#ifdef _NG_BBK_PVP__
	if(attackedPlayer && attackedPlayer->access < g_config.ACCESS_PROTECT && !pvpArena)
#else
	if(attackedPlayer && attackedPlayer->access < g_config.ACCESS_PROTECT)
#endif //_NG_BBK_PVP__

Still in game.cpp in function

PHP:
void Game::checkCreatureAttacking(unsigned long id)

find that

PHP:
else {
	if (creature->attackedCreature != 0)
	{
		Creature *attackedCreature = getCreatureByID(creature->attackedCreature);

and under that add:

PHP:
#ifdef _NG_BBK_PVP__
Player *player = dynamic_cast<Player*>(creature);
Player *attackedPlayer = dynamic_cast<Player*>(attackedCreature);
bool pvpArena = false;
       pvpArena = isPvpArena(player) && isPvpArena(attackedPlayer);  
      if(player && player->atkMode == 1 && attackedPlayer && !pvpArena) {
  if(attackedPlayer->party == 0 || player->party == 0 && player->party != attackedPlayer->party){
     player->sendCancelAttacking();
     player->sendTextMessage(MSG_SMALLINFO, "Turn off secure mode if you really want to attack unmarked players.");
     playerSetAttackedCreature(player, 0);
    return;
  }
        }
#endif //_NG_BBK_PVP__[php]

in function:

[php]void Game::onPvP(Creature* creature, Creature* attacked, bool murder)

under that:

PHP:
if (player->party != 0 && attackedPlayer->party != 0 && player->party == attackedPlayer->party)
	return;

add:

PHP:
#ifdef _NG_BBK_PVP__    
 bool pvpArena = false;
  pvpArena = isPvpArena(player) && isPvpArena(attackedPlayer);  
  
  	if (pvpArena)
		return;
       
     Creature *attackedCreature = getCreatureByID(player->attackedCreature);
      if(player->atkMode == 0)
        {
           if(attackedCreature != attackedPlayer)
          {
            return;
          }
     }
    if (player->atkMode == 1)
        return;
#endif //_NG_BBK_PVP__

at the bottom game.cpp add:

PHP:
#ifdef _NG_BBK_PVP__
bool Game::isPvpArena(Creature* c)
{
	if (!c)
		return false;
	Tile *tile = map->getTile(c->pos);
	return tile && tile->isPvpArena();
}
#endif //_NG_BBK_PVP__

Now in game.h below that:

PHP:
class Game {
public:
	Game();
  ~Game();

add

PHP:
#ifdef _NG_BBK_PVP__
	bool isPvpArena(Creature* c);
#endif //_NG_BBK_PVP__

Now in player.cpp below that

PHP:
guildId    = 0;

add

PHP:
#ifdef _NG_BBK_PVP__	
	atkMode = 0;
#endif //_NG_BBK_PVP__

Now in protocol76.cpp (i dont have it in tfs 0.3.6pl1) below:

PHP:
void Protocol76::parseModes(NetworkMessage &msg)
{

change that:

PHP:
#ifdef YUR_FIGHT_MODE
	player->setFightMode(msg.GetByte());
#endif //YUR_FIGHT_MODE
	//player->fightMode = msg.GetByte();
	//player->followMode = msg.GetByte();
}

for

PHP:
#ifdef YUR_FIGHT_MODE
	player->setFightMode(msg.GetByte());
#endif //YUR_FIGHT_MODE
	player->followMode = msg.GetByte();
#ifdef _NG_BBK_PVP__    
    player->atkMode = msg.GetByte();
#endif //_NG_BBK_PVP__ 
}

Now in player.h below:

PHP:
class Player : public Creature
{
public:

add

PHP:
#ifdef _NG_BBK_PVP__    
bool atkMode;
#endif //_NG_BBK_PVP__
char followMode;

next change that:

PHP:
char fightMode, followMode;

for

PHP:
char fightMode;

At the bottom of project add:

PHP:
-D_NG_BBK_PVP__

REBUILD ALL!
 
Last edited:
Find
Code:
int32_t LuaScriptInterface::luaGetPlayerSex(lua_State* L)
{
    //getPlayerSex(cid[, full = false])
    bool full = false;
    if(lua_gettop(L) > 1)
        full = popNumber(L);

    ScriptEnviroment* env = getEnv();
    Player* player = env->getPlayerByUID((uint32_t)popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
    }
    else
        lua_pushnumber(L, player->getSex(full));

    return 1;
}
And above add this
Code:
int32_t LuaScriptInterface::luaGetPlayerSecureMode(lua_State* L)
{
    //getPlayerSecureMode(cid)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getPlayerByUID((uint32_t)popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
    }
    else
        lua_pushnumber(L, player->getSecureMode());

    return 1;
}

Find this
Code:
//getCreatureHealth(cid)
lua_register(m_luaState, "getCreatureHealth", LuaScriptInterface::luaGetCreatureHealth);

And above paste this
Code:
//getPlayerSecureMode(cid)
lua_register(m_luaState, "getPlayerSecureMode", LuaScriptInterface::luaGetPlayerSecureMode);

Now find
Code:
static int32_t luaDoRemoveItem(lua_State* L);

And above paste this
Code:
static int32_t luaGetPlayerSecureMode(lua_State* L);

Now you can paste this in creaturescripts
Code:
function onCombat(cid, target)
if isPlayer(target) and getPlayerSecureMode(cid) == 0 then return false end 
return true
end
 
Back
Top