Jump to content

New to mangos, trying to add to kill function


Guest aztectrev

Recommended Posts

I'm trying to rewrite the gm 'die' command so an admin with equal to or less rights than you cant kill you.

I'm new to C++ and MaNGOS but have done other programming languages so can follow the code logic.

I only added a few line but already stuggling, wondered if anyone could give me a quick help.

so far i got

bool ChatHandler::HandleDieCommand(const char* /*args*/)
{
   Unit* target = getSelectedUnit();

   if(!target || !m_session->GetPlayer()->GetSelection())
   {
       SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
       SetSentErrorMessage(true);
       return false;
   }
   if( target->isAlive() )
   {
       Player* targetPlayer = getSelectedPlayer();
       // check if target is player
       if( targetPlayer )
       {
           // check if player has greater than or equal rights
           if( /*dont know how to check player/target security right such as gm and admin */ )
           {
               //send error message
               SendSysMessage("You cannot kill that player");
               SetSentErrorMessage(true);
           }
           else
           {
               // is player with less rights than you so kill
               m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
           }
       }
       else
       {
           // if not player kill anyway
           m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
       }
   }
   return true;
}

Hope someone can help :lol:

thought this would be a start to learning C++ if i managed this :)

Link to comment
Share on other sites

I guess I already implemented such stuff in master. It doesn't have checks in Level3.cpp because no higher rank is officialy supported (maybe console, but seriously, who can kill a console?).

see http://repo.or.cz/w/getmangos.git?a=commitdiff;h=c000d23;hp=3d00e18

If you want to restrict interaction within the same security level (SEC_GAMEMASTER vs. SEC_GAMEMASTER for example), you can modify it a bit and add checks to Level3.cpp.

Good luck!

Link to comment
Share on other sites

I wanted to create this so other people testing the server with me all are set to security level 3 and use the die command alot, but sometimes can be bad if another player is selected by mistake (and especially if your brother is annoyed with me and keeps hitting the die command on me :( )

anyways thanks for the link. i just couldnt work out how to access the GetSecurity function for another player.

This is the bit i needed to know, so cheers:

getSelectedPlayer()->GetSession()->GetSecurity()

fixed:

// check if player has greater than or equal rights
if(targetPlayer->GetSession()->GetSecurity() >= m_session->GetPlayer()->GetSession()->GetSecurity()  )
{
   //send error message
   SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
   SetSentErrorMessage(true);
}
else
{
   // is player with less rights than you so kill
   m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
}

Now when i try to kill another admin i get the LANG_YOURS_SECURITY_IS_LOW message :lol:

Link to comment
Share on other sites

I wanted to create this so other people testing the server with me all are set to security level 3 and use the die command alot, but sometimes can be bad if another player is selected by mistake (and especially if your brother is annoyed with me and keeps hitting the die command on me :( )

anyways thanks for the link. i just couldnt work out how to access the GetSecurity function for another player.

This is the bit i needed to know, so cheers:

m_session->GetPlayer()->GetSession()->GetSecurity()

fixed:

// check if player has greater than or equal rights
if(targetPlayer->GetSession()->GetSecurity() >= m_session->GetPlayer()->GetSession()->GetSecurity()  )
{
   //send error message
   SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
   SetSentErrorMessage(true);
}
else
{
   // is player with less rights than you so kill
   m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
}

Now when i try to kill another admin i get the LANG_YOURS_SECURITY_IS_LOW message :lol:

I guess you can use m_session->GetSecurity() directly, since it's your session.

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