Raised This Month: $ Target: $400
 0% 

Solved [HELP] Detect if Map has Water on Start


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hellmonja
Senior Member
Join Date: Oct 2015
Old 06-02-2020 , 09:31   [HELP] Detect if Map has Water on Start
Reply With Quote #1

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...
__________________

Last edited by hellmonja; 06-03-2020 at 01:53.
hellmonja is offline
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 06-02-2020 , 14:04   Re: [HELP] Detect if Map has Water on Start
Reply With Quote #2

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, ..... 
__________________
abdobiskra is offline
Send a message via Skype™ to abdobiskra
hellmonja
Senior Member
Join Date: Oct 2015
Old 06-02-2020 , 14:21   Re: [HELP] Detect if Map has Water on Start
Reply With Quote #3

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;

__________________
hellmonja is offline
Old 06-02-2020, 14:42
supertrio17
This message has been deleted by supertrio17. Reason: typo
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 06-02-2020 , 14:44   Re: [HELP] Detect if Map has Water on Start
Reply With Quote #5

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");
    }

supertrio17 is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 06-03-2020 , 01:53   Re: [HELP] Detect if Map has Water on Start
Reply With Quote #6

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!...
__________________

Last edited by hellmonja; 06-03-2020 at 01:53.
hellmonja is offline
thEsp
BANNED
Join Date: Aug 2017
Old 06-03-2020 , 06:52   Re: [HELP] Detect if Map has Water on Start
Reply With Quote #7

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.
thEsp is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 06-03-2020 , 13:26   Re: [HELP] Detect if Map has Water on Start
Reply With Quote #8

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...

__________________
hellmonja is offline
thEsp
BANNED
Join Date: Aug 2017
Old 06-03-2020 , 13:56   Re: [HELP] Detect if Map has Water on Start
Reply With Quote #9

Return PLUGIN_HANDLE, yes.
thEsp is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-03-2020 , 16:02   Re: [HELP] Detect if Map has Water on Start
Reply With Quote #10

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.
__________________

Last edited by HamletEagle; 06-03-2020 at 16:04.
HamletEagle is offline
Reply



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 16:50.


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