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

How to check if a Player is in water.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Steveh
Member
Join Date: Oct 2010
Old 03-20-2011 , 06:42   How to check if a Player is in water.
Reply With Quote #1

Hello,

I need help with one of my plugins, in one part of it, It needs to check everyone is in water.

PHP Code:
    for(new 1<= MaxClientsi++){
        if(
IsClientInGame(i) && IsPlayerAlive(i) && !IsFakeClient(i)){
if((
GetEntityFlags(i) & FL_INWATER || GetEntityFlags(i) & FL_SWIM))
{
PrintToChat(i"You are in water"); 
}
}

I don't see why this doesn't work, as the water the players run into is deep.

Thanks,

Steveh
Steveh is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 03-20-2011 , 07:08   Re: How to check if a Player is in water.
Reply With Quote #2

helped me in TF2
Code:
if(GetEntityFlags(iClient) & FL_FLY) // lolwtf flying in water
Leonardo is offline
blodia
Veteran Member
Join Date: Sep 2009
Location: UK
Old 03-20-2011 , 08:05   Re: How to check if a Player is in water.
Reply With Quote #3

the search feature is your friend
http://forums.alliedmods.net/showthread.php?t=129795
blodia is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 03-20-2011 , 09:03   Re: How to check if a Player is in water.
Reply With Quote #4

blodia
can't see anything helphul there o.o
Leonardo is offline
psychonic

BAFFLED
Join Date: May 2008
Old 03-20-2011 , 09:52   Re: How to check if a Player is in water.
Reply With Quote #5

Quote:
Originally Posted by Steveh View Post
Hello,

I need help with one of my plugins, in one part of it, It needs to check everyone is in water.

PHP Code:
    for(new 1<= MaxClientsi++){
        if(
IsClientInGame(i) && IsPlayerAlive(i) && !IsFakeClient(i)){
if((
GetEntityFlags(i) & FL_INWATER || GetEntityFlags(i) & FL_SWIM))
{
PrintToChat(i"You are in water"); 
}
}

I don't see why this doesn't work, as the water the players run into is deep.

Thanks,

Steveh
Quote:
Originally Posted by Leonardo View Post
helped me in TF2
Code:
if(GetEntityFlags(iClient) & FL_FLY) // lolwtf flying in water
Most entity flags shifted on the engine that css and tf2 are on. There's an open bug that I hope to have resolved in the near future.

Quote:
Originally Posted by Leonardo View Post
blodia
can't see anything helphul there o.o
The water level prop and level defines would also check if in water, and if so, how far into the water (depth-wise). Indeed useful.
psychonic is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 03-20-2011 , 09:56   Re: How to check if a Player is in water.
Reply With Quote #6

oh dear
okay then
Leonardo is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 03-20-2011 , 15:42   Re: How to check if a Player is in water.
Reply With Quote #7

From one of my plugins. It's the napalm feature of ZR, it puts out napalm fire if you go in water. There's a cvar that controls how far into the water you need to be before it's doused.



Code:
/**
 * @section m_nWaterLevel defines.
 */
#define NAPALM_WLEVEL_DRY 0
#define NAPALM_WLEVEL_FEET 1
#define NAPALM_WLEVEL_HALF 2
#define NAPALM_WLEVEL_FULL 3
/**
 * @endsection
 */
Code:
Action:NapalmOnTakeDamage(client, damagetype)
{
    // Client was damaged by fire.
    if (damagetype & DMG_CSS_BURN)
    {
        // Only take action if it isn't disabled, or the option is valid.
        new douse = GetConVarInt(g_hCvarsList[CVAR_NAPALM_DOUSE]);
        
        if (douse > NAPALM_WLEVEL_DRY && douse <= NAPALM_WLEVEL_FULL)
        {
            // If the client water-level is equal or higher than the given, then we want to extinguish the flame.
            new waterlevel = GetEntProp(client, Prop_Data, "m_nWaterLevel");
            if (waterlevel >= douse)
            {
                // Put the fire out.
                
                //ExtinguishEntity(client);  <-- Don't use this.  Takes off the FL_ONFIRE flag, but flame doesn't get extinguished.
                
                // This works.
                new fire = GetEntPropEnt(client, Prop_Data, "m_hEffectEntity");
                if (IsValidEntity(fire))
                {
                    // Make sure the entity is a flame, so we can extinguish it.
                    decl String:classname[64];
                    GetEdictClassname(fire, classname, sizeof(classname));
                    if (StrEqual(classname, "entityflame", false))
                    {
                        SetEntPropFloat(fire, Prop_Data, "m_flLifetime", 0.0);
                    }
                    // Log what entity was in that property, for future reference.
                    else
                    {
                        LogEvent(false, LogTypeOld_Normal, LOG_GAME_EVENTS, LogModule_Napalm, "Napalm Douse", "Found unexpected entity in prop \"m_flLifetime\": \"%s\"", classname);
                    }
                }
            }
        }
    }
    
    // Let the damage module continue as usual.
    return Plugin_Continue;
}
__________________
Greyscale is offline
Steveh
Member
Join Date: Oct 2010
Old 03-21-2011 , 03:56   Re: How to check if a Player is in water.
Reply With Quote #8

Thanks for the help, the issue has been fixed.


Steveh
Steveh 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 07:51.


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