Modme Forums
Menu:

Keycard to open a certain door (s)

Game Modding | Call of Duty: Black Ops 3 | Scripting


ModmeBot:

Thread By: Slysur
Is there any script that could create a keycard (you pick up) that will open a certain door or multiple ones? thanks in advanced


ModmeBot:

Reply By: natesmithzombies
I am at work and Uni all day. I cannot test myself but I believe this should work:



Instructions

--------------

1) Got to your mapname.gsc and at the bottom add this code:

function init_keycard()
{
    level.key_obtained = false;
    key = GetEnt( "key_trigger", "targetname" );
    key SetCursorHint( "HINT_NOICON" );
    key SetHintString( "Press and Hold ^3&&1^7 to Pick Up Keycard" );
    key thread wait_for_pickup();
     
    key_doors = GetEntArray( "key_door", "targetname" );
    foreach( door in key_doors )
    {
        door SetCursorHint( "HINT_NOICON" );
        door SetHintString( "A Key is Required to Open the Door" );
        door thread wait_for_unlock();
    }
}
 
function wait_for_pickup()
{
    self waittill( "trigger", player );
    model = GetEnt( self.target, "targetname" );
    model delete();
    self delete();
    level.key_obtained = true;
    iprintlnbold( "The Keycard Has Been Obtained" );
}
 
function wait_for_unlock()
{
    level endon( "intermission" );
     
    while( !level.key_obtained )
        wait(0.25);
     
    self SetHintString( "Press and Hold ^3&&1^7 to Unlock Door" );
    self waittill( "trigger", player );
    models = GetEntArray( self.target, "targetname" );
    PlaySoundAtPosition( "zmb_cha_ching", player.origin );
    spawn_flag = models[0].script_flag;
    flag::set( spawn_flag );
    wait(0.05);
    foreach( model in models )
        model delete();
    self delete();
}



2) Near the top mapname.gsc you will see the main function:

function main()
{

Underneath that add this line:

level init_keycard(); 



3) Open Radiant and open the "Entity Browser". Insert a trigger>use and give it the following KVP's by pressing "N" on your keyboard.

targetname - key_trigger



Place only one of these in your map. It is the trigger for your key.



4) Now place a script>model in "Entity Browser". Select the trigger you placed in Step 3 and then select the model you just placed. Press "W" on your keyboard and then you will notice the targetname of the script model is "auto#" where # is some number. The target of the trigger should be the same auto#.



5) Now you are to place a trigger for the doors. Place a trigger>use again and give it the following KVPs:

targetname - key_door



Place as many of these as you would like around the map.



6) For each placed door trigger, place a script>model or a script>brushmodel for your door. Select first the trigger and then the script>model or script>brushmodel and link them by pressing "W" like you did in Step 4. Additionally add a KVP to initiate the spawners in that zone by adding this KVP:

script_flag - spawner_flag



"spawner_flag" should be the flag that you would use in the add_adjacent_zone function when setting up zones. Be sure script_flag is on the model and not the trigger. Also note that if your door is in pieces do this for each piece of the door.



That should be all you need. Ideally you would want a HUD to show the player has a key, but thats a bit more in depth than I can do for you right now. It isn't hard to add at all though if you take a look at how hud functions work. Let me know if this works, as I cannot test myself.


ModmeBot:

Reply By: dj_jorn
==================================================



^1

^1^

^1ERR(6E) scripts/zm/zm_fabrik.gsc (481,0) : Compiler Internal Error : Uninitialized local variable 'model'


ModmeBot:

Reply By: natesmithzombies

dj_jorn==================================================



^1

^1^

^1ERR(6E) scripts/zm/zm_fabrik.gsc (481,0) : Compiler Internal Error : Uninitialized local variable 'model'


One of these days I will be able to right code without having to compile for a typo lol. I updated it. It should be error free now


ModmeBot:

Reply By: Slysur
Now getting this error





^1}

^1^

^1ERR(6E) scripts/zm/zm_throwback.gsc (329,1) : Compiler Internal Error : Uninitialized local variable 'i'


ModmeBot:

Reply By: TheKillerey
I added this code:

for( i = 0; i < models.size; i++ )
    {
    spawn_flag = models[i].script_flag;
    flag::set( spawn_flag );
    }



Works for me now


ModmeBot:

Reply By: Blink-420

TheKillereyI added this code:

for( i = 0; i < models.size; i++ )
    {
    spawn_flag = models[i].script_flag;
    flag::set( spawn_flag );
    }



Works for me now


Works great :) Thanks for this.


ModmeBot:

Reply By: natesmithzombies
Man thats what I get for rushing at work haha. I updated the code another time to work for future visitors to this post. Nice work guys!


ModmeBot:

Reply By: Slysur
Thanks everyone! This is working great


ModmeBot:

Reply By: Blink-420

natesmithzombiesMan thats what I get for rushing at work haha. I updated the code another time to work for future visitors to this post. Nice work guys!


Love this script, been very helpful. I've tried using playfx for and effect to happen on the origin of the model when the door is unlocked... Ive used this

playfx(level._effect["powerup_grabbed"] ,GetEnt("key_door_thermite","targetname").origin);

And placed it at the bottom of

function wait_for_unlock_thermite()
{
    level endon( "intermission" );
      
    while( !level.key_obtained_thermite )
        wait(0.25);
      
    self SetHintString( "Press and Hold ^3&&1^7 to use thermite" );
    self waittill( "trigger", player );
    models = GetEntArray( self.target, "targetname" );
    PlaySoundAtPosition( "zmb_cha_ching", player.origin );
    for( i = 0; i < models.size; i++ )
    {
    spawn_flag = models[i].script_flag;
    flag::set( spawn_flag );
	}



But can't seem to get an fx to play.. do you mind giving me some direction to what I'm doing wrong or even how I can do this? Thanks, Nate!


ModmeBot:

Reply By: natesmithzombies

Blink-420
natesmithzombiesMan thats what I get for rushing at work haha. I updated the code another time to work for future visitors to this post. Nice work guys!


Love this script, been very helpful. I've tried using playfx for and effect to happen on the origin of the model when the door is unlocked... Ive used this

playfx(level._effect["powerup_grabbed"] ,GetEnt("key_door_thermite","targetname").origin);

But can't seem to get an fx to play.. do you mind giving me some direction to what I'm doing wrong or even how I can do this? Thanks, Nate!


I think your issue is that you have an array of doors with the targetname "key_door_thermite". You could try this but it might look a bit funny depending on how many script_models or script_brushmodels you have with that targetname:

playfx(level._effect["powerup_grabbed"] ,GetEnt("key_door_thermite","targetname").origin);

function wait_for_unlock()
{
    level endon( "intermission" );
      
    while( !level.key_obtained )
        wait(0.25);
      
    self SetHintString( "Press and Hold ^3&&1^7 to Unlock Door" );
    self waittill( "trigger", player );
    models = GetEntArray( self.target, "targetname" );
    PlaySoundAtPosition( "zmb_cha_ching", player.origin );
    spawn_flag = models[0].script_flag;
    flag::set( spawn_flag );
    wait(0.05);
    foreach( model in models )
	{
		playfx(level._effect["powerup_grabbed"], model.origin);
	    model delete();		
	}
    self delete();
}