Jump to content
  • Advertisement
Sign in to follow this  
SelethD

Text in a MUD?

This topic is 5398 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, Im trying to make a little MUD and I have been looking through source code of old MUD's like Tele-Arena. And I have noticed that they have a text file called like Messages.dat or somthing and inside it looks like this. /* Messages for the Mud */ INTRO { Welcome to My MUD! by Some Programmer version 1.1 } DEAD {*** Player %s had been killed!} and so on, so my question is how do you get these messages to work in the actual mud code, like if someone logs in to the game //player logged on SendText(INTRO); //or player has died SendText(DEAD,cPlayer->Name); Anyone have any knowledge of this topic? Or links? Anything?

Share this post


Link to post
Share on other sites
Advertisement
Pretty much, though the %s indicates that these strings were almost certainly passed to the *printf style functions.

Share this post


Link to post
Share on other sites
There is a function futher into the code that would send the text, This in most cases would collect the string from the file anf format it according to the way the varibles are designed.

For example
DEAD {*** Player %s had been killed!}

Would be loaded up and saved into some sort of array. then when a character has been killed the MUD Server would read the array for the DEAD Message and then forward the message to the sendtext function this function would replace the %s with the characters name and it would be sent to the MUD clients.

For the formatting you could have
%s Character name, Sent to all characters playing ie 'Mykre'
%d Direction, ie used when a player enters or leaves. '%s Leaves to the %d.' would be 'Mykre Leaves to the North.'

Hope this helps.

Share this post


Link to post
Share on other sites
It would be parsed at loading time. The code reading the file would see

DEAD = {*** Player %s has been killed!}

and grab the first word as an ID, and the text inside braces as the text. And go off and do something like

insertIntoHashtable(gameText, idString, textString);

(because all the old MUDs were written in plain C, you see ;) )

Nowadays it would probably look more like

using namespace std;
map<string, string> gameText;
// parse the line to put "DEAD" into idString and
// "*** Player %s has been killed!" into textString
gameText[idString] = textString;

// upon death
outputMessage = gameText["DEAD"];
// Substitute in the player name. Possibly by old-school C
// hackery; possibly with boost::format or something.

Share this post


Link to post
Share on other sites
One modification you might want to make is to have %1s %2s etc where %1s will always represent one thing and %2s represents another, so you could change the order of stuff in the string, like at first you might start out with "Killed {%1s killed %2s.}", but latter you could change it to "Killed {%2s died at the hands of %1s}" so now it says who died first. If you didn't have some kind of numbered system, the first thing in the string would always have to be first unless you modified the C++ code, which would be bad.

Share this post


Link to post
Share on other sites
Hey thanks for all the feedback, I guess ill just play with it some more.

Zahlman kinda gets what im asking, how you can use the 'tag' for the text to display it inside your code. Its just that his example is totally 'greek' to me. So ill experiment with it, and I might just have to make my own way 'as usual'.

I was just curious as the how the 'old schoolers' did it.

Thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!