Author Topic: Door that destroys keys.  (Read 1840 times)

Offline Raudhrskal

  • BFF
  • ***
  • Posts: 214
  • The MUD community needs YOUR help!
    • View Profile
Door that destroys keys.
« on: September 21, 2008, 05:46:46 am »
For Aerlindir @ i3.

Side note:
Quote
Raudhrskal <ds> Well, with locks there is a stupid thing. In case of things that inherit LIB_LOCK, (containers, etc.), you can have an callback in key file. But doors/enters don't do it ;( It's an inconsistency, and probably should be fixed.
Code: [Select]
#include <lib.h>

inherit LIB_DOOR;

static void create() {
    door::create();

    SetSide("north", ([ "id" : ({"door leading north", "door", "north door"}),
        "short" : "a door leading north",
        "long" : "This is the south side of a door leading north.",
        "lockable" : 1 ]) );

    SetSide("south", ([ "id" : ({"door leading south", "door", "south door"}),
        "short" : "a door leading south",
        "long" : "This is the north side of a door leading south.",
        "lockable" : 1 ]) );

    SetClosed(1);
    SetLocked(1);

    //If you don't know, strings like "key to north side" are added in 'modify my_key id'
    SetKeys("north", ({ "key to north side" }));
    SetKeys("south", ({ "key to south side" }));
}

//You add THIS:
mixed eventUnlock(object who, object key)
  {
    if(GetLocked()) //if the door is unlocked, we just fall back to parent.
      {
      if(::eventUnlock(who,key)) //Handled?
  {
    if(!GetLocked()) //did the key unlocked the door?
      {
key->eventDestruct(); //kill it.
who->eventPrint("Your key crumbles to dust..."); //message ;)
      }
    return 1; // ::eventUnlock() returned 1, so must we.
  }
return 0;  // ::eventUnlock() returned 0, so must we.
      }
    return ::eventUnlock(who,key);  // Fall back to parent.
  }


void init(){
    ::init();
}
Tested.
'Skal

//EDIT - changed title.
« Last Edit: September 21, 2008, 05:54:39 am by Raudhrskal »
I think, therefore i may be wrong.
Please note that if you met a Raudhrskal in a place that's not related to muds, it wasn't me. *sigh*... back when I started there was zero hits on google for that name...