Key Movers

From Oldunreal-Wiki
Jump to navigation Jump to search

What we're going to do is make a subclass of a normal mover and add some code that will check to see if the player has a "key" of a specified type. If they do then the mover will do its thing normally, otherwise it won't...that way you could add lifts/doors/etc in your levels that need a specific key. (editor's note: please use this code responsibly, the world doesn't need more "find-the-key" puzzles :)


// =============================================
// kmover.KeyMover
// =============================================
class KeyMover expands Mover;
// This will be the class of the item we will open for, be it
// a weapon, or a keycard or whatever.  Just set this to the
// class in the properties of the mover in the level...
var() class keyclass;
state() BumpOpenTimed
{
  // Bump is called when an actor "bumps" us, and the mover code
  // uses this to check and see if it should do its thing, if its
  // a bump-based mover.  We'll just insert some code here to
  // check to see if the bumper is a Pawn (player/bot), and then
  // if they have our desired key.  If so then we call the normal
  // Bump() function in the Parent class, otherwise go ahead and
  // abort now.
  function Bump(actor Other)
  {
    local Inventory key;
    // BroadcastMessage("Bumped by "$Other.Name);
    // First check to make sure this is a Pawn, cause they are
    // only things that have inventories (i think:), and then
    // make sure we have a keyclass to check for.
    if (Other.IsA('Pawn') && keyclass != NONE)
    {
       // BroadcastMessage("Other.Class: "$Other.Class$", keyclass: "$keyclass);
       // Now we just use FindInventoryType() to see if they have
       // a copy of our desired key in their inventory...
       key = Pawn(Other).FindInventoryType(keyclass);
       // ...if so call the old Bump() function and let the mover
       // do its thing.
       if (key != NONE)
       {
         // Broadcastmessage("Found key");
         Super.Bump(Other);
       }
       // ...otherwise just do nothing.
       // else BroadcastMessage("Couldn't find key");
    }
  }
}

Thats all there is to it. You could take this even farther by having special id numbers in your key class so that you had to have the right key with the right id, or maybe take it even farther and let the player try to hack the id number with a special key or something... :)