[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUDs
. -> [Folder]  General
. . -> [Subject]  Implementing new functions to SimpleMUD

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Implementing new functions to SimpleMUD

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Thorbenn   (25 posts)  [Biography] bio
Date Mon 28 Nov 2011 06:00 PM (UTC)  quote  ]

Amended on Wed 30 Nov 2011 11:13 AM (UTC) by Thorbenn

Message
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() );
} 
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Tue 29 Nov 2011 08:06 PM (UTC)  quote  ]
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Thorbenn   (25 posts)  [Biography] bio
Date Reply #2 on Wed 30 Nov 2011 11:10 AM (UTC)  quote  ]

Amended on Wed 30 Nov 2011 11:12 AM (UTC) by Thorbenn

Message
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
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


779 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]