Implementing new functions to SimpleMUD

Posted by Thorbenn on Mon 28 Nov 2011 06:00 PM — 3 posts, 16,718 views.

#0
Hi all,

after getting an old version of gcc finally and an there for old version of redhat SimpleMud was finally able to be compiled under linux. Since i am new to programming Muds i have been playing around with SimpleMUD and trying to understand how it works(which so far has gone very well). Now for fun i have been implementing new features like being randomly ported to some room if you give in a specific command or implementing new directions to walk etc.

I have been trying to get a pvp system on the basis of the attack system from SimpleMUD implemented and so far it hasn't been very successful. All what i can do right now is attack the first player in the room. my question is how can i pick a specific player that will be given in by the attacking player for example "attack Thorbenn" and then Thorbenn should be attacked.

Here is the code:

void Game::PVP(const string& p_player )
{
Player& e = *m_player;

    area r = e.CurrentRoom();
sint64 now = Game::GetTimer().GetMS();
    
std::list<player>::iterator itr;
for (itr = r->Players().begin(); itr != r->Players().end(); itr++)
  {    
    Player& p = **itr; 
	break;
  }  // end of for loop   

    Player& p = **itr;
    int damage;
    if( e.Weapon() == 0 )
    {
        damage = BasicLib::RandomInt( 1, 3 );
        e.NextAttackTime() = now + seconds( 1 );
    }
    else
    {
        damage = BasicLib::RandomInt( e.Weapon()->Min(), e.Weapon()->Max() );
        e.NextAttackTime() = now + seconds( e.Weapon()->Speed() );
    }

    if( BasicLib::RandomInt( 0, 99 ) >= e.GetAttr(ACCURACY) - p.GetAttr( DODGING ) )
    {
        Game::SendRoom(newline + yellow + e.Name() + " slashes at " + p.Name() + 
                        " but misses!", e.CurrentRoom() );
        return;
    }

    damage += e.GetAttr(STRIKEDAMAGE);
    damage -= p.GetAttr( DAMAGEABSORB );

    if( damage < 1 )
        damage = 1;

    p.AddHitpoints( -damage );

Game::SendRoom(newline + red + e.Name() + " hits " + p.Name() + " and inflicts " + 
tostring( damage ) + " damage!", e.CurrentRoom() );

    if( p.HitPoints() <= 0 )
        PlayerKilled( p.ID() );
} 
Amended on Wed 30 Nov 2011 11:13 AM by Thorbenn
Australia Forum Administrator #1
This looks very very similar to your question here:

http://www.gammon.com.au/forum/?id=11304

Template:codetag
To make your code more readable please use [code] tags as described here.
#2
yes it is the same question :) sorry. The reason why i opened a thread is because maybe someone would more likely react to this than the one with the header how to get the mud to compile.

what i would like to know is how to get the name of the player when someone types the command and then the name. this is where i have troubles understanding how it gets the name. because the method which is used to whisper something to someone does something similar but doesn't work in the attack method.

is it possible by Players() to see if it where a player at the position of itr that gets counted higher in the for loop? i get the number that is input for the position of the player and then this player is attacked.

the question would be there again how do i read the input number and save it to an helping integer that then is looked for in the for loop.

for example

somehow get the input

int number= input;

for (itr = r->Players().begin(); itr != r->Players().end(); itr++)
  {

    if(itr==input)
       {
	break;
        }
  } 


in a way like this just how to get the input is my question