AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved [HELP] Detect if Map has Water on Start (https://forums.alliedmods.net/showthread.php?t=324960)

hellmonja 06-02-2020 09:31

[HELP] Detect if Map has Water on Start
 
Is it possible to detect if a map has water at the start of a game so I can disable my plugin?

I saw this code that detects if there's a bombsite anywhere on the map:
PHP Code:

if(find_ent_by_class(-1"func_bomb_target") <= && find_ent_by_class(-1"info_bomb_target") <= 0
     
pause("d"); 

I have a plugin that deals with water so I tried modifying the code into this:
PHP Code:

if(find_ent_by_class(-1"func_water") <= 0
     
pause("d"); 

But it doesn't work and never returns true...

abdobiskra 06-02-2020 14:04

Re: [HELP] Detect if Map has Water on Start
 
PHP Code:

public plugin_precache ()
{
    if(
find_ent_by_class(-1"func_water") > 0)
        
pause("d");


you can use too:
PHP Code:

register_forward FM_KeyValue, ..... 


hellmonja 06-02-2020 14:21

Re: [HELP] Detect if Map has Water on Start
 
Like this?
PHP Code:

register_forward(FM_KeyValue"Foward_KeyValue" );
...

public 
Foward_KeyValue ( const EntId, const KvdId )
{
    if ( 
pev_valid EntId ) )
    {
        
szKeyClassName16 ];
        
get_kvdKvdIdKV_ClassNameszKeyClassNamecharsmaxszKeyClassName ) );
        
        if( 
equalszKeyClassName"func_water" ) > 0)
        {
            
pause("d");
            return 
FMRES_SUPERCEDE;
        }
    }
    
    return 
FMRES_IGNORED;



supertrio17 06-02-2020 14:44

Re: [HELP] Detect if Map has Water on Start
 
This should do it, I will try it on my own plugin and I will tell you what happens.
PHP Code:

#include <amxmodx>
#include <engine>

public plugin_precache()
{
    if(
find_ent_by_class(-1"func_water") > 0)
    {
        
pause("d");
    }



hellmonja 06-03-2020 01:53

Re: [HELP] Detect if Map has Water on Start
 
This works:
PHP Code:

if(engfunc(EngFunc_FindEntityByString, -1"classname""func_water"))
    
g_water true

Very useful if your plugin deals with water alone. Just invert the condition and put pause("d") in there and plugin should disable itself. Thanks everyone!...

thEsp 06-03-2020 06:52

Re: [HELP] Detect if Map has Water on Start
 
I believe checking if an entity has classname "func_water" on pfn_spawn would be better. I am not sure if in this case it helps, but I had a plugin that removed bombsites/hostages with this method, because looping through each entity would be very slow.

hellmonja 06-03-2020 13:26

Re: [HELP] Detect if Map has Water on Start
 
pfn_spawn, interesting. So it catches the entity as it is spawned and checks if it is func_water. Yes it sounds better than looping thru all of them after they've all loaded up.

So like this?
PHP Code:

pfn_spawn(ent)
{
        new 
sz_classname[32]
        
pev(entpev_classnamesz_classnamecharmax(sz_classname));

        if(
equal(sz_classname"func_water"))
               
blahblah...



thEsp 06-03-2020 13:56

Re: [HELP] Detect if Map has Water on Start
 
Return PLUGIN_HANDLE, yes.

HamletEagle 06-03-2020 16:02

Re: [HELP] Detect if Map has Water on Start
 
For amxx >= 1.9 the best way is to use cs_find_ent_by_class. CS keeps track of entities using a hashtable which provides very fast lookup(it is faster than find_ent_by_class). This will not work if you search for entities you created with create_entity/fakemeta equivalent because the entities are not added to the hashtable. If this is the case, use cs_create_entity to create the entity.

hellmonja 06-05-2020 14:13

Re: [HELP] Detect if Map has Water on Start
 
Like this?
PHP Code:

public plugin_init()
{
        if(
cs_find_ent_by_class(-1"func_water"))
    {
        
register_forward(FM_PlayerPreThink,"FM_Water_PreThink");
        
register_forward(FM_PlayerPostThink,"FM_Water_PostThink");
    }
... 

It's giving out errors. I'm probably doing something wrong...


All times are GMT -4. The time now is 16:50.

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