Raised This Month: $51 Target: $400
 12% 

Water


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hellkong
Member
Join Date: Nov 2021
Old 11-06-2021 , 12:47   Water
Reply With Quote #1

Good evening,

I request a code that hooks the event of something touchs the water, let's say a player or a bullet hits water surface so i can emit a sound (like jump in wave sound) or spawn an entity or something only in our water surface.

+ want hook of bullet alone, I want to spawn a sprite.

Thank you.

Last edited by Hellkong; 11-06-2021 at 13:40.
Hellkong is offline
JusTGo
Veteran Member
Join Date: Mar 2013
Old 11-06-2021 , 13:16   Re: Water
Reply With Quote #2

check https://forums.alliedmods.net/showthread.php?t=69835
__________________
JusTGo is offline
Hellkong
Member
Join Date: Nov 2021
Old 11-06-2021 , 13:39   Re: Water
Reply With Quote #3

Not what i want, this is a think func calling it many times while player in water.
I'll reform my words
I want to hook the the event only when he touchs the surface only (1 event , one possible event not consistent ), and I want another through TraceAttack (bullet event) if possible (to spawn streak splash)
Hellkong is offline
JusTGo
Veteran Member
Join Date: Mar 2013
Old 11-06-2021 , 14:04   Re: Water
Reply With Quote #4

As far as I know, there isn't an event that you can easily hook to detect players entering the water, but with some work in the think func you can create a variable to save player state and check if the player is actually entering the water and do your work there.
__________________

Last edited by JusTGo; 11-06-2021 at 14:05.
JusTGo is offline
JusTGo
Veteran Member
Join Date: Mar 2013
Old 11-06-2021 , 14:29   Re: Water
Reply With Quote #5

Something like this should work for players:

PHP Code:
#include amxmodx
#include fakemeta

new gInWater[MAX_PLAYERS+1]

public 
plugin_init()
{
    
register_plugin("Water check""1.0""JustGo")
    
register_forward(FM_PlayerPreThink"playerPreThink");
}

public 
playerPreThink(id)
{
    if(!
is_user_alive(id)) return FMRES_IGNORED

    
if(isInWater(id))
    {
        if(!
gInWater[id])
        {
            
gInWater[id] = 1
            playerEnterWater
(id)
        }
    }
    else
    {
        if(
gInWater[id])
        {
            
gInWater[id] = 0
        
}
    }

    return 
FMRES_IGNORED
}

// Do your work here
playerEnterWater(id)
{
    
client_print(idprint_chat"* You entered water.")
}

isInWater(id)
{
    return (
pev(id,pev_flags) & FL_INWATER)

__________________
JusTGo is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-06-2021 , 15:19   Re: Water
Reply With Quote #6

pev_waterlevel


// waterlevel 0 - not in water
// waterlevel 1 - feet in water
// waterlevel 2 - waist in water
// waterlevel 3 - head in water


About checking if a bullet hit the water surface you need to check if the weapon trace line penetrated the water box.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 11-06-2021 at 15:32.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 11-06-2021 , 21:19   Re: Water
Reply With Quote #7

There's also this water check.
PHP Code:
new Float:vOrigin[3];
pev(idpev_originvOrigin);

if(
engfunc(EngFunc_PointContentsvOrigin) == CONTENTS_WATER) {
// In water
} else {
// otherwise

__________________
GitHub
SteamWishlist

六四天安門事件

Last edited by +ARUKARI-; 11-06-2021 at 21:22.
+ARUKARI- is offline
Hellkong
Member
Join Date: Nov 2021
Old 11-07-2021 , 02:56   Re: Water
Reply With Quote #8

Quote:
Originally Posted by JusTGo View Post
Something like this should work for players:
I thought there should be a special event for such cases but I guess not, your code should work fine in emiting sounds, but not spawning something precisely on the surface. I'll try something familiar.

Quote:
Originally Posted by Natsheh View Post
pev_waterlevel


// waterlevel 0 - not in water
// waterlevel 1 - feet in water
// waterlevel 2 - waist in water
// waterlevel 3 - head in water


About checking if a bullet hit the water surface you need to check if the weapon trace line penetrated the water box.
Something like?

PHP Code:
public plugin_init()
{
    
RegisterHam(Ham_TraceAttack"func_water""Fw_TraceAttack"// We use "func_water" for more precising.
}
public 
Fw_TraceAttack(EntityAttackerFloat:DamageFloat:Direction[3], PtrDamagetype)
{
    if(!
is_user_connected(Attacker))
        return 
FMRES_IGNORED

    
new Float:fEnd[3]
    
get_tr2(PtrTR_vecEndPosfEnd)

    if(
engfunc(EngFunc_PointContentsfEnd) == CONTENTS_WATER) {
    
// etc
    
}

Quote:
Originally Posted by +ARUKARI- View Post
There's also this water check.
Check the mini code above if it is correct?

Last edited by Hellkong; 11-07-2021 at 02:57. Reason: Forgot [/QUOTE]
Hellkong is offline
JusTGo
Veteran Member
Join Date: Mar 2013
Old 11-07-2021 , 03:29   Re: Water
Reply With Quote #9

Quote:
Originally Posted by Hellkong View Post
I thought there should be a special event for such cases but I guess not, your code should work fine in emitting sounds, but not spawning something precisely on the surface. I'll try something familiar.
I guess to do it precisely on the surface you might try changing the InWater function in the code I posted to something like this:

PHP Code:
isInWater(id)
{
    new 
watertype pev(idpev_watertype)
    return (
watertype <= CONTENTS_WATER && watertype CONTENTS_TRANSLUCENT)

__________________

Last edited by JusTGo; 11-07-2021 at 03:30.
JusTGo is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-07-2021 , 05:44   Re: Water
Reply With Quote #10

Quote:
Originally Posted by Hellkong View Post
I thought there should be a special event for such cases but I guess not, your code should work fine in emiting sounds, but not spawning something precisely on the surface. I'll try something familiar.


Something like?

PHP Code:
public plugin_init()
{
    
RegisterHam(Ham_TraceAttack"func_water""Fw_TraceAttack"// We use "func_water" for more precising.
}
public 
Fw_TraceAttack(EntityAttackerFloat:DamageFloat:Direction[3], PtrDamagetype)
{
    if(!
is_user_connected(Attacker))
        return 
FMRES_IGNORED

    
new Float:fEnd[3]
    
get_tr2(PtrTR_vecEndPosfEnd)

    if(
engfunc(EngFunc_PointContentsfEnd) == CONTENTS_WATER) {
    
// etc
    
}



Check the mini code above if it is correct?
No, you need to hook FM_Traceline and check if the weapon traceline attack passes through the water.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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 18:07.


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