+float door_check_keys(void) {
+ local entity door, p;
+
+
+ if (self.owner)
+ door = self.owner;
+ else
+ door = self;
+
+ if (other.owner)
+ p = other.owner;
+ else
+ p = other;
+
+ if (door.spawnflags & (SPAWNFLAGS_GOLD_KEY | SPAWNFLAGS_SILVER_KEY)) {
+ // this door require a key
+ // only a player can have a key
+ if (p.classname != "player")
+ return FALSE;
+
+ // check gold key
+ if (self.owner.spawnflags & SPAWNFLAGS_GOLD_KEY) {
+ if (!(other.itemkeys & KEYS_GOLD_KEY)) {
+ if (p.key_door_messagetime <= time) {
+ play2(other, "misc/talk.wav");
+ centerprint(other, "You don't have the gold key!");
+ p.key_door_messagetime = time + 2;
+ }
+ return FALSE;
+ } else {
+ self.owner.spawnflags &~= SPAWNFLAGS_GOLD_KEY;
+ }
+ }
+
+ // check silver key
+ if (self.owner.spawnflags & SPAWNFLAGS_SILVER_KEY) {
+ if (!(other.itemkeys & KEYS_SILVER_KEY)) {
+ if (p.key_door_messagetime <= time) {
+ play2(other, "misc/talk.wav");
+ centerprint(other, "You don't have the silver key!");
+ p.key_door_messagetime = time + 2;
+ }
+ return FALSE;
+ } else {
+ self.owner.spawnflags &~= SPAWNFLAGS_SILVER_KEY;
+ }
+ }
+
+ // door is now unlocked
+ play2(other, "misc/talk.wav");
+ centerprint(other, "Door unlocked!");
+ }
+
+ return TRUE;
+}
+
+