random_door.nut

random_door.nut
Code synopsis pretty much says it all.

Place this script in scripts/vscripts named random_door.nut

In a func_instance, place a NAMED prop_door_rotating. Turn off smartedit in Hammer and add a key vscripts with the value random_door

Place a prop_dyanmic that indicates when the door is closed with the SAME NAME, and optionally a func_nav_blocker with the SAME NAME.

If you're gonna have more than one, make sure your func_instance have fixup names. Also make sure that you can't break flow.

If you only two paths to the saferoom and both are locked..., in that case you'd need a fancier script to manage combinations of doors.

/*------------------------------------------------------------------------------------------
random_door.nut
author: Lee Pumphret 
https://www.leeland.info

Description: Randomly block and unblock doors on map spawn

Place this script in scripts/vscripts named random_door.nut

In a func_instance, place a NAMED prop_door_rotating. Turn off smartedit in Hammer and add a key 
vscripts with the value random_door

Place a prop_dyanmic that indicates when the door is closed with the SAME NAME, and optionally
a func_nav_blocker with the SAME NAME.

If you're gonna have more than one, make sure your func_instance have fixup names.

------------------------------------------------------------------------------------------*/

if (self.GetClassname() == "prop_door_rotating"){ // this is for console testing. Otherwise script would run on the door, nav and dynamic...
    
    OpenDoor <- RandomInt(0,4); //1 in 5   Chance of door being open, Modify as needed 0,1 would be 50/50 0,9 would be  1 in 10

    OpenDoor = OpenDoor == 0 ? true : false // normalize values

    printl("Door "+self.GetName()+ " open is "+OpenDoor);

    local e;
    while(e = Entities.FindByName(e,self.GetName())){
        printl("Found "+e+" class:"+e.GetClassname());
        switch (e.GetClassname()) {
            case "prop_door_rotating":
            DoEntFire("!self", OpenDoor ? "setbreakable" : "setunbreakable", "", 0.1, null, e);
            DoEntFire("!self", "close", "", 0.1, null, e);
            DoEntFire("!self", OpenDoor ? "unlock" : "lock", "", 0.2, null, e);
            break;

            case "prop_dynamic":
            DoEntFire("!self", OpenDoor ? "disable" : "enable", "", 0, null, e);
            DoEntFire("!self", OpenDoor ? "disablecollision" : "enablecollision", "", 0, null,e);
            break;

            case "func_nav_blocker":
            DoEntFire("!self", OpenDoor ? "unblocknav" : "blocknav", "", 0, null, e);



        }
    }


}
Scroll to top