AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Smoke events? (https://forums.alliedmods.net/showthread.php?t=162553)

CrazyChickenTest 07-20-2011 10:42

Smoke events?
 
How can I capture the coordination of exploded smoke grenade?
I try to do code which will be infect players who went into smoke.
Are there any events or something which could help me to do that?

Arkshine 07-20-2011 11:13

Re: Smoke events?
 
You can try something like :

Code:
stock getSGExplosionOrigin( const grenade, Float:origin[3] ) {     const m_SGExplosionPos = 115;         for( new i = 0; i < sizeof origin; i++ )     {         origin[ i ] = get_pdata_float( grenade, m_SGExplosionPos + i );     } }

and in your code :

Code:
new Float:smokeOrigin[3]; getSGExplosionOrigin( grenade, smokeOrigin );

Just an example.

Note : grenade is the "grenade" entity index.

abdul-rehman 07-20-2011 11:48

Re: Smoke events?
 
Quote:

Originally Posted by Arkshine (Post 1514593)
You can try something like :

Code:
stock getSGExplosionOrigin( const grenade, Float:origin[3] ) {     const m_SGExplosionPos = 115;         for( new i = 0; i < sizeof origin; i++ )     {         origin[ 0 ] = get_pdata_float( grenade, m_SGExplosionPos + i );     } }

I dont get it your only retrieving the x-axis value through the offset and not the y-axis or z-axis one?

Arkshine 07-20-2011 11:54

Re: Smoke events?
 
I've already fixed before you post ;) but yes, it was obviously a typo.

CrazyChickenTest 07-20-2011 12:08

Re: Smoke events?
 
ok but when I must called this function. how can I capture message when somebody threw smoke grenade?

bibu 07-20-2011 13:49

Re: Smoke events?
 
http://www.amxmodx.org/funcwiki.php?go=func&id=578

CrazyChickenTest 07-20-2011 13:51

Re: Smoke events?
 
thank You very much :)

Arkshine 07-20-2011 13:58

Re: Smoke events?
 
You can use grenade_throw forward to hook when a grenade is thrown.
This forward is based on SetModel forward, in others words grenade_throw is called right after a throw(ing?) when the grenade model is applied.

The problem is : the explosion comes after, so you may think that's not a good way.
Here, a preview of a basic flow (and only what we need) of a smoke grenade explosion :

Code:

You throw a grenade
    ┌ A new grenade entity spawns
    └ The smoke grenade model is applied on the entity → grenade_throw called.
        ┌ After 1.5 seconds, the grenade detonates
        ├ createsmoke.sc event is called. (big smoke)
        └ m_SGExplosionPos offset is set by the current grenade position.
            └ 0.1 second later, the grenade explodes.
                ┌ 0.1 second later, the smoke appears
                └ A second createsmoke.sc event is fired. (20 times, small smoke)
                    └ Grenade removed.

So, a solution would be to hook the createsmoke.sc event (the first) in grenade_throw and since we hook this forward, we don't need the offset anymore.
But since the player's id is not passed for this event, we need some trick.

An example :

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <csx>

new HandleFwdPlaybackEvent;
new Array:
HandleGrenadePlayerIdQueue;

public 
plugin_init()
{
    
register_plugin"""""" );
}

public 
grenade_throwplayergrenadeweaponId )
{
    if( 
weaponId == CSW_SMOKEGRENADE )
    {
        if( 
HandleGrenadePlayerIdQueue == Invalid_Array )
        {
            
HandleGrenadePlayerIdQueue ArrayCreate();
        }
    
        
ArrayPushCellHandleGrenadePlayerIdQueueplayer );
    
        if( !
HandleFwdPlaybackEvent )
        {
            
HandleFwdPlaybackEvent register_forwardFM_PlaybackEvent"OnPlaybackEvent" );
        }
    }
}

public 
OnPlaybackEvent( const flags, const client, const eventIndex, const Float:delay, const Float:origin[3] )
{
    if( 
HandleFwdPlaybackEvent )
    {
        new 
player ArrayGetCellHandleGrenadePlayerIdQueue);
        
ArrayDeleteItemHandleGrenadePlayerIdQueue);
        
        if( !
ArraySizeHandleGrenadePlayerIdQueue ) )
        {
            
ArrayDestroyHandleGrenadePlayerIdQueue );
            
            
unregister_forwardFM_PlaybackEventHandleFwdPlaybackEvent );
            
HandleFwdPlaybackEvent 0;
        }

        
// Use origin variable to get the explosion origin.
        //server_print( "Player %d - Explosion origin = %f %f %f", player, origin[ 0 ], origin[ 1 ], origin[ 2 ] );
    
}




Note #1 : It's an example, so it may need more check for example if player is still connected, or if you throw a grenade, the game is reset or new round and the grenade is removed right away without exploding, the Array would need to be destroy. Such situation where you need to check.

Note #2 : A more direct way would be simply to hook directly CGrenade::SG_Detonate() as post, with orpheu and retrieving the m_SGExplosionPos offset. If you don't care using Orpheu module, tell me.

CrazyChickenTest 07-21-2011 01:38

Re: Smoke events?
 
biig thanks again :)


All times are GMT -4. The time now is 00:48.

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