Author Topic: Need Some Coding Help/Advice  (Read 3534 times)

Offline Arnvorax

  • Acquaintance
  • *
  • Posts: 2
    • View Profile
Need Some Coding Help/Advice
« on: March 13, 2007, 11:09:57 pm »
I've recently discovered the Dead Souls mudlib and have gotten back into LPC coding after quite a long break, it's very addicting.  Anyway, on to my question,

Background :

I'm trying to implement a recognization system - IE - a player on the mud wont know the "name" of anyone until they recognize them as some name, can be pretty much any name they choose to recognize them as.  I've got that part mostly completed, as well as modifying ids so that if you know the player 'bob' as 'junior' you can see/kill/otherwise interact with them if they are in the same room with you using the string 'junior'. 

I modified the GetShort() function in /lib/props/description.c to the following

string GetShort() {
   string tmp = "";
    if( !Short ) {
   return 0;
    }
    if( functionp(Short) ) {
   if( functionp(Short) & FP_OWNER_DESTED ) {
       return "Error in evaluating function pointer.";
   }
   return evaluate(Short);
    }
    else if( arrayp(Short) ) {
   return Short[query_night()];
    }
    else {
      if(objectp(this_object()) && objectp(this_player())) {
         if(this_object()->is_player())
         {
            tmp += TP->GetRecognizedName(this_object()->GetKeyName());
            if(tmp != "")
            {
               tmp += ", ";
            }
            tmp += this_object()->GetAdjective();
            return tmp;
         }
      }
      return Short;
    }
}

it works correctly for things like "look" or "who" - displaying other peoples name as the name you know them by plus their Adjective (a string players can input that describes what you might see at a first glance toward them) or just their Adjective if you've never met them before and/or never recognized them. 

Problem/Question:

What I need help with is that it doesn't work sending messages - take the look command for instance,
it executes the following code,

this_player())->eventPrint(this_player()->GetShort() +
     " looks around.", this_player());

and this causes everyone in the room to see your Short description as you would see it, not as they would see if. 

I've seen this same system implemented on an older version of the nightmare mudlib that has been heavily modified, so I know its possible, but I have no clue how to go about getting it to work without having to change a lot of stuff and possible create a new sefun to deliver messages.

Any ideas?
« Last Edit: March 13, 2007, 11:13:31 pm by Arnvorax »

Offline memrosh

  • Acquaintance
  • *
  • Posts: 20
    • View Profile
Re: Need Some Coding Help/Advice
« Reply #1 on: March 14, 2007, 01:29:02 am »
Greetings,

The eventPrint you cited in your question is being directed to the room the player is in:
Code: [Select]
environment(this_player())->eventPrint(...In /lib/std/room.c the eventPrint then sorts it out and determines who is there to recieve the message. And sent to them with:
Code: [Select]
targs->eventPrint(msg, msg_class);It is in here that you may be able to 'pull a switch' on what each target will see as the 'name' of the actor who looked.
How to do this? Good question ;) The variable msg is all we have to work with and it could be anything so it may be dificult to pinpoint the actors own 'name' in it. the previous_object() function might work but would need to be experimented with to be sure.

Hope this helps some.
Glad to have another LPC explorer (and addict) among us  ;D
Memrosh

Side notes: When discussion code it is good to give what release version you are working with. There are several at the moment with major/minor difference that could help in pinpointing certain things.
Also- If you have a block of code that you want to present exactly as you have it, the button with the pound sign "#" will give you 'insert code' brackets to work with.

Offline Jimorie

  • Friend
  • **
  • Posts: 58
    • View Profile
Re: Need Some Coding Help/Advice
« Reply #2 on: March 14, 2007, 02:03:09 am »
I have implemented this kind of thing, but not on a Dead Souls MUD. You have to parse each message sent to each player and substitute eventual descriptions with names. This means that the message should probably be on an easily parsed format and probably hold some sort of reference back to the to be described object. If your mud is already doing things like ANSI code filtering or variable width linebreaking for all its output, that could be places to start looking at.

For example, on my MUD, the message, "You smile at the orc." Would look before being parsed like this:

"$Recg(</std/obj/player#123>, 32) $verb(\"smile\", </std/obj/player#123>) at $recg(</std/obj/orc#456>, 16)."

Where $recg() are expanded to whatever the receiving player would recognize the provided object as, modified by also given flags.

The big problem is efficiency. A system like this will increase your MUD:s cpu usage a lot. I have implemented this said system four times now with different approaches to try and find the fastest. It works, but I can't say I know how it would scale to a MUD with a lot of players, my guess is poorly.

Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
Re: Need Some Coding Help/Advice
« Reply #3 on: March 14, 2007, 07:57:55 am »
I have two comments.

1) I would suggest that you create a new variable to represent the Known version of the short desc.
For example, once the player knows the target, then you can use the variable ShortKnown() in each instance. It looks like you may have already created such a variable, GetRecognizedName.  To implement this, you will need to find every instance where GetShort is used and replace it with GetShortKnown. This is not really that big of a deal.  Thus, in the look command and for targetting verbs like 'kill' etc.
In your example, why cant you just change

this_player())->eventPrint(this_player()->GetShort()

to

this_player())->eventPrint(this_player()->GetRecognizedName()

2a) for L7 of your code, you do not need to repeat the functionp(Short) part of the code in the if statement. It is sufficient to just use
if( FP_OWNER_DESTED ) { for L7.
2b) You will need to use a double ampersand for an 'and' statement. if(X=2 && Y=3) {

Offline Jimorie

  • Friend
  • **
  • Posts: 58
    • View Profile
Re: Need Some Coding Help/Advice
« Reply #4 on: March 14, 2007, 12:22:02 pm »
Are you sure you know what you are talking about, Detah?

 :P

I don't quite see your point with the first comment and I think the second has one or two errors.

There is nothing wrong with the code on line 7. (I have no idea about the code as a whole though - didn't look at it.) The single ampersand is the bitwise and operator. He is checking the return value of functionp() with a predefined bitmask. Putting just the mask in the if statement is just like saying if (1) ... - not very meaningful. And I'm afraid you even managed to get things wrong in your own example. The expression (X=2 && Y=3) will always evaluate to 1, because you are using assignment in there, not equality checks - so again a meaningless if statement.

Rock on.

 :)

Offline Arnvorax

  • Acquaintance
  • *
  • Posts: 2
    • View Profile
Re: Need Some Coding Help/Advice
« Reply #5 on: March 14, 2007, 04:16:06 pm »
First off, I'd just like to say thanks for all of your replies and for trying to help at least.

As for line 7 of the code I pasted, I didn't make that, just the bit further down where it returns the correct recognized name for the player.  I guess Cratylus (spelling?) or someone helping him who coded the function originally added that part of the code. 

What I am doing is adding a mapping to each player that holds the name they know "bob" or everyone else as - the keyname of said player (bob in this case) being the key in the mapping that would return the name a particular player knows bob or any other player as. 

I managed to track down the eventPrint() function in interface.c and edit the message a player is receiving so that if bob types the command "look" in a room then every player in the room who gets the eventPrint function called on them will see the name they know bob as, without having to change a lot of code that's already in place. 

It works good, except in the case of something like

"look at george" - then it doesn't work so good, but I believe I'm on the right track. 

The mud I know where this system is implemented is on a mud called Shadowgate and it works good - it uses a very heavily modified version of nightmare running on some older version of Mudos - I was wondering if maybe something has changed since that version of mudos or since that version of nightmare (not sure which in either case, but they are old - game has been up since like 94 or something) - that has made what I'm wanting to do more difficult. 

I apologize if my post is hard to follow - I am not good very good at explaining what I'm trying to do - one of the reasons I hardly ever post on forums - the code seems to bounce around in my head in a way that makes sense in my mind but not so much when I try to tell someone else. 

Arnvorax