Jump to content

Function for player command I can not figure out


Guest Ruafo

Recommended Posts

Ok, I'm trying develop a custom command for players. Similar to .goname but not exactly.

Basically I want players to be able to goname each other, but not go to opposite factions.

The problem I'm running into is for the life of me I can't figure out a good way to get the faction of the player and the target for comparison.

Here is where I'm going with the code:

uint8 p_race = _player->GetTeam();

uint8 t_race = target->GetTeam();

uint32 p_faction = Player::TeamForRace(p_race);

uint32 t_faction = Player::TeamForRace(t_race);

// Check that other player is same faction

if (!p_faction == t_faction)

{

SendSysMessage(LANG_NOTELE_OPPOSING_FACTION);

SetSentErrorMessage(true);

return false;

}

but I know I'm not doing it right because I can still go to opposite factions. What's the best way to call each player's faction?

(This is being created in the Level0.cpp file)

Thank you in advance for any help you can offer

Link to comment
Share on other sites

Ok, I guess I was wrong. I thought it worked... but I was wrong.

Vlad,

Here is my existing code. Is there anything wrong with it? The part in Green is the part I'm most concerned with. But maybe there is something else conflicting?

{

Player* target;

ObjectGuid target_guid;

std::string target_name;

if (!ExtractPlayerTarget(&args, &target, &target_guid, &target_name))

return false;

Player* _player = m_session->GetPlayer();

if (target == _player || target_guid == _player->GetObjectGuid())

{

SendSysMessage(LANG_CANT_TELEPORT_SELF);

SetSentErrorMessage(true);

return false;

}

if (target)

{

uint32 p_team = _player->Player::GetTeam();

uint32 t_team = target->Player::GetTeam();

// Check that other player is same faction

if (!(p_team == t_team))

{

SendSysMessage(LANG_NOTELE_OPPOSING_FACTION);

SetSentErrorMessage(true);

return false;

}

Link to comment
Share on other sites

This should do it

bool ChatHandler::HandleGonameCommand(char* args)
{
   Player* target;
   ObjectGuid target_guid;
   std::string target_name;
   if (!ExtractPlayerTarget(&args, &target, &target_guid, &target_name))
       return false;

   Player* _player = m_session->GetPlayer();
   if (target == _player || target_guid == _player->GetObjectGuid())
   {
       SendSysMessage(LANG_CANT_TELEPORT_SELF);
       SetSentErrorMessage(true);
       return false;
   }


   if (target)
   {
       if (target->GetTeam() != _player->GetTeam())
           return false;

       // check online security
       if (HasLowerSecurity(target))
           return false;

       std::string chrNameLink = playerLink(target_name);

       Map* cMap = target->GetMap();
       if (cMap->IsBattleGroundOrArena())
       {
           // only allow if gm mode is on
           if (!_player->isGameMaster())
           {
               PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,chrNameLink.c_str());
               SetSentErrorMessage(true);
               return false;
           }
           // if both players are in different bgs
           else if (_player->GetBattleGroundId() && _player->GetBattleGroundId() != target->GetBattleGroundId())
           {
               PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,chrNameLink.c_str());
               SetSentErrorMessage(true);
               return false;
           }
           // all's well, set bg id
           // when porting out from the bg, it will be reset to 0
           _player->SetBattleGroundId(target->GetBattleGroundId(), target->GetBattleGroundTypeId());
           // remember current position as entry point for return at bg end teleportation
           if (!_player->GetMap()->IsBattleGroundOrArena())
               _player->SetBattleGroundEntryPoint();
       }
       else if(cMap->IsDungeon())
       {
           // we have to go to instance, and can go to player only if:
           //   1) we are in his group (either as leader or as member)
           //   2) we are not bound to any group and have GM mode on
           if (_player->GetGroup())
           {
               // we are in group, we can go only if we are in the player group
               if (_player->GetGroup() != target->GetGroup())
               {
                   PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY,chrNameLink.c_str());
                   SetSentErrorMessage(true);
                   return false;
               }
           }
           else
           {
               // we are not in group, let's verify our GM mode
               if (!_player->isGameMaster())
               {
                   PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM,chrNameLink.c_str());
                   SetSentErrorMessage(true);
                   return false;
               }
           }

           // if the player or the player's group is bound to another instance
           // the player will not be bound to another one
           InstancePlayerBind *pBind = _player->GetBoundInstance(target->GetMapId(), target->GetDifficulty());
           if (!pBind)
           {
               Group *group = _player->GetGroup();
               // if no bind exists, create a solo bind
               InstanceGroupBind *gBind = group ? group->GetBoundInstance(target->GetMapId(), target) : NULL;
               // if no bind exists, create a solo bind
               if (!gBind)
               {
                   DungeonPersistentState *save = ((DungeonMap*)target->GetMap())->GetPersistanceState();

                   // if player is group leader then we need add group bind
                   if (group && group->IsLeader(_player->GetObjectGuid()))
                       group->BindToInstance(save, !save->CanReset());
                   else
                       _player->BindToInstance(save, !save->CanReset());
               }
           }

           _player->SetDifficulty(target->GetDifficulty());
       }

       PSendSysMessage(LANG_APPEARING_AT, chrNameLink.c_str());
       if (needReportToTarget(target))
           ChatHandler(target).PSendSysMessage(LANG_APPEARING_TO, GetNameLink().c_str());

       // stop flight if need
       if (_player->IsTaxiFlying())
       {
           _player->GetMotionMaster()->MovementExpired();
           _player->m_taxi.ClearTaxiDestinations();
       }
       // save only in non-flight case
       else
           _player->SaveRecallPosition();

       // to point to see at target with same orientation
       float x,y,z;
       target->GetContactPoint(_player,x,y,z);

       _player->TeleportTo(target->GetMapId(), x, y, z, _player->GetAngle(target), TELE_TO_GM_MODE);
   }
   else
   {
       // check offline security
       if (HasLowerSecurity(NULL, target_guid))
           return false;

       std::string nameLink = playerLink(target_name);

       PSendSysMessage(LANG_APPEARING_AT, nameLink.c_str());

       // to point where player stay (if loaded)
       float x,y,z,o;
       uint32 map;
       bool in_flight;
       if (!Player::LoadPositionFromDB(target_guid, map,x,y,z,o,in_flight))
           return false;

       return HandleGoHelper(_player, map, x, y, &z);
   }

   return true;
}

Just added this 2 lines on the first line after the if target bracket.

if (target->GetTeam() != _player->GetTeam())

return false;

EDIT: Lol it should be == not != xD

and as i can see it, the getteam function does not return a uint32 value, a simple hint when debugging is to just chat or slog your variables to the command executor, you will probably not get either 67 or 469 as feedback if you print those variables out.

Look at the definition for m_team and then look at the definition of Team after that.

// In fact !=0 values is alliance/horde root faction ids

enum Team

{

TEAM_NONE = 0, // used when team value unknown or not set, 0 is also meaning that can be used !team check

HORDE = 67,

ALLIANCE = 469,

};

Idk what enum means really, but im sure it does not say uint32 to me, anyways you should never create a variable you do not need to use more then once! ;)

Link to comment
Share on other sites

No problem! ;) Actually i think that you did try to make a uint32 value containing "NONE", "ALLIANCE" or "HORDE", maby if you put it into a string it would have worked to compare the variables, because as far as i know you can pus whatever possible data into a string ^^,

Anyways, here is wikipedias explanation of the datatype enum and to e honest, i didnt understand everything there! xD

http://en.wikipedia.org/wiki/Enumerated_type

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use