Thread: [Solved] Safe room L4D2
View Single Post
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-24-2020 , 19:37   Re: Safe room L4D2
Reply With Quote #5

Now I have test much.

*edit
*edit
*edit
*edit
Updated code.

Checkpoint Exit Door will be forced to open after 30 seconds at round start.
- To get door open automatically, there should be bots or players in team survivor.

PHP Code:
#include <sdktools>

Handle TimerCheckpointDoor;
bool DoOnce;

public 
void OnPluginStart()
{
    
HookEventEx("round_freeze_end"round_freeze_end);
    
HookEventEx("player_first_spawn"player_first_spawn);
}


public 
void round_freeze_end(Event event, const char[] namebool dontBroadcast)
{
    
// when map start

    
DoOnce false;

    if(
TimerCheckpointDoor == null) return;

    
delete TimerCheckpointDoor;
}


public 
void player_first_spawn(Event event, const char[] namebool dontBroadcast)
{
    
// Timer already executed
    
if(DoOnce || TimerCheckpointDoor != null) return;


    
int client GetClientOfUserId(event.GetInt("userid"));
    
    
// Don't check unnecessary events. Only players in team survivor
    
if(client == || !IsClientInGame(client) || GetClientTeam(client) != 2) return;

    
char doorname[30];
    
int door = -1;


    
int entity = -1;
    
    while( (
entity FindEntityByClassname(entity"prop_door_rotating_checkpoint")) != -)
    {
        
//PrintToServer("m_hasUnlockSequence %i,   %i", GetEntProp(entity, Prop_Data, "m_hasUnlockSequence"), entity);
        
GetEntPropString(entityProp_Data"m_iName"doornamesizeof(doorname));
        
        if(
StrEqual(doorname"checkpoint_exit"false))
        {
            
// yes
            
door entity;
            break;
        }
        else if(
StrEqual(doorname"checkpoint_entrance"false))
        {
            
// skip
            
continue;
        }
        else if(
GetEntProp(entityProp_Data"m_hasUnlockSequence") == 1)
        {
            
// empty targetname ex. Look door m_hasUnlockSequence
            
door entity;
            break;
        }
    }


    if(
door == -1) return;


    
SetVariantString("OnOpen !self:Lock::0.1:1");
    
AcceptEntityInput(door"AddOutput");
    
    
SetVariantString("OnUser1 !self:playeropen::0.1:1");
    
AcceptEntityInput(door"AddOutput");

    
SetVariantString("OnUser1 !self:playeropen::1.0:1");
    
AcceptEntityInput(door"AddOutput");
    
    
PrintToChatAll("\x05[SM] \x04Checkpoint Exit Door \x05will be forced open in 30 seconds");

    
DoOnce true;
    
TimerCheckpointDoor CreateTimer(30.0OpenDoorEntIndexToEntRef(door));
}

public 
Action OpenDoor(Handle timerint ref)
{
    
TimerCheckpointDoor null;

    
int door EntRefToEntIndex(ref);

    if(
door != -1)
    {
        for(
int i 1<= MaxClientsi++)
        {
            if(!
IsClientInGame(i) || GetClientTeam(i) != 2) continue;

            
AcceptEntityInput(door"FireUser1"i);
            
PrintToChatAll("\x05[SM] \x04Checkpoint Exit Door \x05will be forced open!");
            break;
        }
    }

Attached Files
File Type: sp Get Plugin or Get Source (L4D2openCheckpointDoor.sp - 168 views - 2.4 KB)
__________________
Do not Private Message @me

Last edited by Bacardi; 10-25-2020 at 20:58. Reason: updated code, again
Bacardi is offline