Raised This Month: $32 Target: $400
 8% 

[snippet] getting the ents of the safe room doors


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gold Fish
Senior Member
Join Date: Mar 2020
Old 03-03-2021 , 05:19   [snippet] getting the ents of the safe room doors
Reply With Quote #1

I wrote a simple function that will accurately return the entity of each safe room door on any map.
To use it, it is enough to pass 2 arguments to the function, into which the entities from the starting shelter and the final one will be written. Arguments are passed to the function by reference.

PHP Code:
void getEntCheckpointDoorTo(int &startDoorint &endDoor) {
    
char smap[40];
    
endDoor 0;
    
startDoor 0;
    
int iEnt;
    
    
GetCurrentMap(smapsizeof(smap)-1);
    for (
iEnt=1iEnt GetMaxEntities(); iEnt++) {
        if (!
IsValidEntity(iEnt)) {
            continue;
        }
        
int hid GetEntProp(iEntProp_Data"m_iHammerID");
        if (
hid == 801110 || hid == 363772 || hid == 1036878 || hid == 1717496 || hid == 919930 || hid == 1466555 || hid == 2015668 || hid == 3493 || hid == 38734 || hid == 37385 || hid == 12104 || hid == 1295520 || hid == 449678 || hid == 1769704 || hid == 686116 || hid == 572034 || hid == 570342 || hid == 63868 || hid == 206826 || hid == 615299 || hid == 5675178 || hid == 4045747 || hid == 4078726 || hid == 13295 || hid == 901653 || hid == 1377406 || hid == 6922310 || hid == 4677827 || hid == 4510233 || hid == 4885522 || hid == 686720 || hid == 1386273 || hid == 1437033 || hid == 1598033 || hid == 267023 || hid == 3295576 || hid == 245989 || hid == 5869787 || hid == 4217718 || hid == 2473004 || hid == 221102) {    
            if (
endDoor == 0endDoor iEnt;
        }
        if (
hid == 437514 || hid == 44268 || hid == 1682887 || hid == 1717408 || hid == 894101 || hid == 1755442 || hid == 600844 || hid == 37230 || hid == 38123 || hid == 5031 || hid == 12253 || hid == 1797205 || hid == 549048 || hid == 244882 || hid == 955431 || hid == 482345 || hid == 20429 || hid == 200103 || hid == 1566706 || hid == 5675135 || hid == 4045682 || hid == 4078678 || hid == 3326690 || hid == 51 || hid == 827551 || hid == 5271886 || hid == 6913559 || hid == 3803428 || hid == 4937918 || hid == 3666066 || hid == 1386152 || hid == 1437236 || hid == 1265104 || hid == 921494 || hid == 1916929 || hid == 246095 || hid == 2008961 || hid == 1790283 || (hid == 1431968 && StrEqual(smap"c10m5_houseboat"false)) || (hid == 1646224 && StrEqual(smap"c10m4_mainstreet"false))) {    
            if (
startDoor == 0startDoor iEnt;
        }
    }

This code is useful for plugins such as KEYMAN or LockDown sistem


To get entities from custom maps, just dump all entities using a stripper, find the HammerID from the prop_door_rotating_checkpoint object in the dump and add it to the condition

For example, a simple plugin that creates a glow for each checkpoint door on the map (green is the start door, red is the door at the end)

Sorry for my English
Attached Files
File Type: sp Get Plugin or Get Source (checkpointDoorTtest.sp - 87 views - 3.3 KB)

Last edited by Gold Fish; 03-03-2021 at 05:27.
Gold Fish is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 03-03-2021 , 07:57   Re: [snippet] getting the ents of the safe room doors
Reply With Quote #2

I found this code snippet some months ago that detects saferoom doors too.

Still may not work on all maps and some custom maps.

PHP Code:
stock bool IsSafeDoorEntrance(entity){
    if(
IsSafeDoor(entity)){
        
char name[32];
        
GetEntPropString(entityProp_Data"m_iName"namesizeof(name));
        return (
strcmp(name"checkpoint_entrance") == 0);
    }
    return 
false;
}

stock bool IsSafeDoorExit(entity){
    if(
IsSafeDoor(entity)){
        
char name[32];
        
GetEntPropString(entityProp_Data"m_iName"namesizeof(name));
        return (
strcmp(name"checkpoint_exit") == 0);
    }
    return 
false;
}

stock bool IsSafeDoor(ent){

    if (
IsValidEntity(ent)) {
        
char classname[64];
        
GetEntityClassname(entclassnamesizeof(classname));
        return (
strcmp(classname"prop_door_rotating_checkpoint") == 0);
    }
    return 
false;

__________________
Marttt is offline
Gold Fish
Senior Member
Join Date: Mar 2020
Old 03-03-2021 , 08:21   Re: [snippet] getting the ents of the safe room doors
Reply With Quote #3

Quote:
Originally Posted by Marttt View Post
I found this code snippet some months ago that detects saferoom doors too.

Still may not work on all maps and some custom maps.

PHP Code:
stock bool IsSafeDoorEntrance(entity){
    if(
IsSafeDoor(entity)){
        
char name[32];
        
GetEntPropString(entityProp_Data"m_iName"namesizeof(name));
        return (
strcmp(name"checkpoint_entrance") == 0);
    }
    return 
false;
}

stock bool IsSafeDoorExit(entity){
    if(
IsSafeDoor(entity)){
        
char name[32];
        
GetEntPropString(entityProp_Data"m_iName"namesizeof(name));
        return (
strcmp(name"checkpoint_exit") == 0);
    }
    return 
false;
}

stock bool IsSafeDoor(ent){

    if (
IsValidEntity(ent)) {
        
char classname[64];
        
GetEntityClassname(entclassnamesizeof(classname));
        return (
strcmp(classname"prop_door_rotating_checkpoint") == 0);
    }
    return 
false;

I think my version is faster, since it uses minimal string operations =)
Gold Fish is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Chocolate Factory
Old 03-03-2021 , 10:24   Re: [snippet] getting the ents of the safe room doors
Reply With Quote #4

Quote:
Originally Posted by Gold Fish View Post
I think my version is faster, since it uses minimal string operations =)
While it may be faster, it is very tedious to get all hammer IDs of each saferoom door that exists in every map. That's why fetching their targetname is much more reliable than hardcoding to do the aforementioned.

Also:
PHP Code:
for (iEnt=1iEnt GetMaxEntities(); iEnt++) {
...
    
int hid GetEntProp(iEntProp_Data"m_iHammerID");
...

This is bad since you're creating multiple variables inside the loop.
cravenge is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 03-03-2021 , 11:08   Re: [snippet] getting the ents of the safe room doors
Reply With Quote #5

Just shared another code snippet as an another example, btw there are a lot of performance tweaks that can be done.

Examples: stopping to loop after finding the start and end saferoom, filtering to check only prop_door_rotating_checkpoint entities.

Like cravenge said is always a good practice to declare a variable, defined inside a loop, outside of it. (before for).

Also filtering by hammerid without map check can easily lead to false positives since these numbers can be related to other entities in other maps.
__________________
Marttt is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-03-2021 , 18:45   Re: [snippet] getting the ents of the safe room doors
Reply With Quote #6

I'm using this in my private plugin to hook the final doors.
Works on custom maps quite well.

PHP Code:
enum {
    
DOOR_FLAG_STARTS_OPEN 1,
    
DOOR_FLAG_STARTS_LOCKED 2048,
    
DOOR_FLAG_SILENT 4096,
    
DOOR_FLAG_USE_CLOSES 8192,
    
DOOR_FLAG_SILENT_NPC 16384,
    
DOOR_FLAG_IGNORE_USE 32768,
    
DOOR_FLAG_UNBREAKABLE 524288
}

void InitDoorEx()
{
    if (
IsFinaleMap()) // e.g. get from Left 4 DHooks Direct
    
{
        return;
    }
    
    static 
char sEntityName[128];
    static 
char sEntityModel[128];
    
    
int door = -1;
    while ((
door FindEntityByClassname(door"prop_door_rotating_checkpoint")) != -1)
    {
        if (!
IsValidEnt(door))
        {
            continue;
        }
        
        
GetEntPropString(doorProp_Data"m_iName"sEntityNamesizeof(sEntityName));
        
        if (
strcmp(sEntityName"checkpoint_entrance") == 0)
        {
            if (
IsValidDoorFlag(door))
            {
                
//HookDoor(door);
                
break;
            }
        }
        else
        {
            
GetEntPropString(doorProp_Data"m_ModelName"sEntityModelsizeof(sEntityModel));
            
            if (
strcmp(sEntityModel"models/props_doors/checkpoint_door_02.mdl") == || 
                
strcmp(sEntityModel"models/props_doors/checkpoint_door_-02.mdl") == 0)
            {
                if (
IsValidDoorFlag(door))
                {
                    
//HookDoor(door);
                    
break;
                }
            }
        }
    }
}

bool IsValidDoorFlag(int door)
{
    
int flags GetEntProp(doorProp_Send"m_spawnflags");
    if (( 
flags DOOR_FLAG_USE_CLOSES ) && ( flags DOOR_FLAG_IGNORE_USE == 0))
        return 
true;
    return 
false;
}

stock bool IsValidEnt(int entity)
{
    return (
entity && IsValidEntity(entity));

__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Gold Fish
Senior Member
Join Date: Mar 2020
Old 03-03-2021 , 19:47   Re: [snippet] getting the ents of the safe room doors
Reply With Quote #7

Quote:
Originally Posted by Dragokas View Post
I'm using this in my private plugin to hook the final doors.
Works on custom maps quite well.

PHP Code:
enum {
    
DOOR_FLAG_STARTS_OPEN 1,
    
DOOR_FLAG_STARTS_LOCKED 2048,
    
DOOR_FLAG_SILENT 4096,
    
DOOR_FLAG_USE_CLOSES 8192,
    
DOOR_FLAG_SILENT_NPC 16384,
    
DOOR_FLAG_IGNORE_USE 32768,
    
DOOR_FLAG_UNBREAKABLE 524288
}

void InitDoorEx()
{
    if (
IsFinaleMap()) // e.g. get from Left 4 DHooks Direct
    
{
        return;
    }
    
    static 
char sEntityName[128];
    static 
char sEntityModel[128];
    
    
int door = -1;
    while ((
door FindEntityByClassname(door"prop_door_rotating_checkpoint")) != -1)
    {
        if (!
IsValidEnt(door))
        {
            continue;
        }
        
        
GetEntPropString(doorProp_Data"m_iName"sEntityNamesizeof(sEntityName));
        
        if (
strcmp(sEntityName"checkpoint_entrance") == 0)
        {
            if (
IsValidDoorFlag(door))
            {
                
//HookDoor(door);
                
break;
            }
        }
        else
        {
            
GetEntPropString(doorProp_Data"m_ModelName"sEntityModelsizeof(sEntityModel));
            
            if (
strcmp(sEntityModel"models/props_doors/checkpoint_door_02.mdl") == || 
                
strcmp(sEntityModel"models/props_doors/checkpoint_door_-02.mdl") == 0)
            {
                if (
IsValidDoorFlag(door))
                {
                    
//HookDoor(door);
                    
break;
                }
            }
        }
    }
}

bool IsValidDoorFlag(int door)
{
    
int flags GetEntProp(doorProp_Send"m_spawnflags");
    if (( 
flags DOOR_FLAG_USE_CLOSES ) && ( flags DOOR_FLAG_IGNORE_USE == 0))
        return 
true;
    return 
false;
}

stock bool IsValidEnt(int entity)
{
    return (
entity && IsValidEntity(entity));

and how do you check from which safe room these doors are?
Gold Fish is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-04-2021 , 10:47   Re: [snippet] getting the ents of the safe room doors
Reply With Quote #8

By door entity flags. Final door has DOOR_FLAG_USE_CLOSES flag which runs the sequence of map end triggers.

Please, don't quote the whole code. It is just make no sense and makes it harder to read the topic.

BTW. For such topics, it is better to use Snippets and Tutorials section. I would suggest to press "complaint" button on your own post and ask moderators to move the topic. In "Scripting" section your topic will be lost very quickly.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 03-04-2021 at 10:48.
Dragokas is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:18.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode