AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to block grenade throw (https://forums.alliedmods.net/showthread.php?t=214165)

FromTheFuture 04-23-2013 15:49

How to block grenade throw
 
How to block grenade throw? Grenade must stay on hands, not to be removed.

FromTheFuture 04-23-2013 16:18

Re: How to block grenade throw
 
I try with Ham_Item_Deploy, but if I have more than one grenade it's does not work.

PHP Code:

    RegisterHamHam_Item_Deploy"weapon_hegrenade""Deploy_Post", .Post true );

public 
Deploy_PostpEntity )
{
    if( !
IsValidPrivateDatapEntity ) )
    {
        return 
HAM_HANDLED;
    }

    new 
id get_pdata_cbasepEntity OFFSET_WEAPONOWNER OFFSET_LINUX_WEAPONS );
        
set_pdata_float(idm_flNextAttackget_gametime( ), OFFSET_LINUX );
    
    
    return 
HAM_IGNORED;



ConnorMcLeod 04-23-2013 16:50

Re: How to block grenade throw
 
In which context do you want to block it ?

FromTheFuture 04-24-2013 06:05

Re: How to block grenade throw
 
Blocking the next throw grenades if the previous shots in less than 15 seconds.
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <csx>
#include <hamsandwich>
#include <fakemeta>

#define PLUGIN "HeBlock"
#define VERSION "1.0"
#define AUTHOR "FromTheFuture"

 
 
#define IsValidPrivateData(%0)          ( pev_valid( %0 ) == 2 )
 
#define  m_flNextAttack                         83
 
#define OFFSET_LINUX_WEAPONS    4
#define OFFSET_LINUX                            5
#define OFFSET_WEAPONOWNER      41

new Floatg_fWaitTime[33];

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
RegisterHamHam_Item_Deploy"weapon_hegrenade""Deploy_Post", .Post true );
}

public 
Deploy_PostpEntity )
{
    if( !
IsValidPrivateDatapEntity ) )
    {
        return 
HAM_HANDLED;
    }

    new 
id get_pdata_cbasepEntity OFFSET_WEAPONOWNER OFFSET_LINUX_WEAPONS );
    new 
Float:Time get_gametime() - g_fWaitTime[id];
    
    if(
Time  15)
    {
        
client_print(idprint_center"Please, wait %0f seconds"15 Time);
        
set_pdata_float(idm_flNextAttackget_gametime( ), OFFSET_LINUX );
    }
    
    return 
HAM_IGNORED;
}

public 
grenade_throw(idgidwid)
{
    if(
wid != CSW_HEGRENADE)
    return;
    
    
g_fWaitTime[id] = get_gametime();
    



ConnorMcLeod 04-24-2013 12:51

Re: How to block grenade throw
 
set m_flNextPrimaryAttack on grenade entity then.
Gonna be a little animation starting to play due to client prediction.

PHP Code:

#include <amxmodx>
// #include <amxmisc>
#include <csx>
#include <hamsandwich>
#include <fakemeta>

#define PLUGIN "HeBlock"
#define VERSION "1.0"
#define AUTHOR "FromTheFuture"

#define IsValidPrivateData(%0)          ( pev_valid( %0 ) == 2 )

const XO_CBASEPLAYERITEM 4;
const 
m_pPlayer 41;

const 
XO_CBASEPLAYERWEAPON 4;
const 
m_flNextPrimaryAttack 46;

new 
Floatg_fNextThrowTime[33];

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
RegisterHamHam_Item_Deploy"weapon_hegrenade""OnCHEGrenadeDeploy_Post"true );
}

public 
OnCHEGrenadeDeploy_PostpEntity )
{
    if( !
IsValidPrivateDatapEntity ) )
    {
        return;
    }

    new 
id get_pdata_cbasepEntity m_pPlayer XO_CBASEPLAYERITEM );
    new 
Float:flWaitTime g_fNextThrowTime[id] - get_gametime();

    if( 
flWaitTime 0.0 )
    {
        
client_print(idprint_center"Please, wait %.0f seconds"flWaitTime);
        
set_pdata_float(pEntitym_flNextPrimaryAttackflWaitTimeXO_CBASEPLAYERWEAPON);
    }
}

public 
grenade_throw(idgidwid)
{
    if(
wid == CSW_HEGRENADE)
    {
        
g_fNextThrowTime[id] = get_gametime() + 15.0;
    }



FromTheFuture 04-25-2013 07:40

Re: How to block grenade throw
 
Plugin not work if I have two or more grenades.
Watch the video http://www.youtube.com/watch?v=HnImA...ature=youtu.be

ConnorMcLeod 04-25-2013 11:54

Re: How to block grenade throw
 
Try this :

Reference is https://raw.github.com/Arkshine/CSSD..._hegrenade.cpp
Interesting code is in function void CHEGrenade::WeaponIdle()
grenade_throw forward is sent during execution of CGrenade::ShootTimed2

PHP Code:

#include <amxmodx>
#include <cstrike>
#include <csx>
#include <hamsandwich>
#include <fakemeta>

#define PLUGIN "HeBlock"
#define VERSION "2.0"
#define AUTHOR "FromTheFuture"

const Float:THROW_HEGREN_DELAY 15.0;

const 
XO_CBASEPLAYERITEM 4;
const 
m_pPlayer 41;

const 
XO_CBASEPLAYERWEAPON 4;
const 
m_flNextPrimaryAttack 46;

new 
Floatg_fNextThrowTime[33];

new 
HamHook:g_iHhCHEGrenadeWeaponIdlePostHamHook:g_iHhCHEGrenadeHolster;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
RegisterHamHam_Item_Deploy"weapon_hegrenade""OnCHEGrenade_Deploy_Post"true );
    
DisableHamForward
    
(
        
g_iHhCHEGrenadeWeaponIdlePost RegisterHamHam_Weapon_WeaponIdle"weapon_hegrenade""OnCHEGrenade_WeaponIdle_Post"true )
    );
    
DisableHamForward
    
(
        
g_iHhCHEGrenadeHolster RegisterHamHam_Item_Holster"weapon_hegrenade""OnCHEGrenade_Holster"false )
    );
}

public 
OnCHEGrenade_Deploy_PostpEntity )
{
    new 
id get_pdata_cbasepEntity m_pPlayer XO_CBASEPLAYERITEM );
    new 
Float:flWaitTime g_fNextThrowTime[id] - get_gametime();

    if( 
flWaitTime 0.0 )
    {
        
client_print(idprint_center"Please, wait %.0f seconds"flWaitTime);
        
set_pdata_float(pEntitym_flNextPrimaryAttackflWaitTimeXO_CBASEPLAYERWEAPON);
    }
}

public 
OnCHEGrenade_HolsterpEntity )
{
    
DisableHamForwardg_iHhCHEGrenadeWeaponIdlePost );
    
DisableHamForwardg_iHhCHEGrenadeHolster );
}

public 
OnCHEGrenade_WeaponIdle_PostpEntity )
{
    
set_pdata_float(pEntitym_flNextPrimaryAttackTHROW_HEGREN_DELAY 0.5XO_CBASEPLAYERWEAPON);
}

public 
grenade_throw(idgidwid)
{
    if(
wid == CSW_HEGRENADE)
    {
        
g_fNextThrowTime[id] = get_gametime() + THROW_HEGREN_DELAY;
        if( 
cs_get_user_bpammo(idCSW_HEGRENADE) > )
        {
            
EnableHamForwardg_iHhCHEGrenadeWeaponIdlePost );
            
EnableHamForwardg_iHhCHEGrenadeHolster );
        }
    }



FromTheFuture 04-25-2013 12:52

Re: How to block grenade throw
 
Thank You, work, but with errors.
It's work if I throw first grenade, change active weapon, then set weapon to grenade again. But if I'm not change active weapon, try to throw second grenade at once - grenade will not be thrown, never.

May be block throw with CurWeapon?
PHP Code:

public evCurWeapon(id)
{

    new 
Float:Time get_gametime() - g_fWaitTime[id];
    
    if(
Time  15)
    {
        
client_print(idprint_center"Please, wait %0.0f seconds"15 Time);
        
engclient_cmd(id"weapon_knife");
    }
    


This code work, but how I can set active weapon from 1 slot (if have) or 2?

ConnorMcLeod 04-25-2013 13:59

Re: How to block grenade throw
 
Try this :)

PHP Code:

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

#define PLUGIN "HeBlock"
#define VERSION "2.1"
#define AUTHOR "FromTheFuture"

const Float:THROW_HEGREN_DELAY 15.0;

const 
XO_CBASEPLAYERITEM 4;
const 
m_pPlayer 41;

const 
XO_CBASEPLAYERWEAPON 4;
const 
m_flNextPrimaryAttack 46;

new 
Floatg_fNextThrowTime[33];

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
RegisterHamHam_Item_Deploy"weapon_hegrenade""OnCHEGrenade_Deploy_Post"true );
    
RegisterHamHam_Weapon_PrimaryAttack"weapon_hegrenade""OnCHEGrenade_PrimaryAttack"false );
}

public 
OnCHEGrenade_Deploy_PostpEntity )
{
    new 
id get_pdata_cbasepEntity m_pPlayer XO_CBASEPLAYERITEM );
    new 
Float:flWaitTime g_fNextThrowTime[id] - get_gametime();

    if( 
flWaitTime 0.0 )
    {
        
client_print(idprint_center"Please, wait %.0f seconds"flWaitTime);
        
set_pdata_float(pEntitym_flNextPrimaryAttackflWaitTimeXO_CBASEPLAYERWEAPON);
    }
}

public 
OnCHEGrenade_PrimaryAttackpEntity )
{
    new 
id get_pdata_cbasepEntity m_pPlayer XO_CBASEPLAYERITEM );
    new 
Float:flWaitTime g_fNextThrowTime[id] - get_gametime();

    if( 
flWaitTime 0.0 )
    {
        
client_print(idprint_center"Please, wait %.0f seconds"flWaitTime);
        
set_pdata_float(pEntitym_flNextPrimaryAttackflWaitTimeXO_CBASEPLAYERWEAPON);
        return 
HAM_SUPERCEDE;
    }
    return 
HAM_IGNORED;
}

public 
grenade_throw(idgidwid)
{
    if(
wid == CSW_HEGRENADE)
    {
        
g_fNextThrowTime[id] = get_gametime() + THROW_HEGREN_DELAY;
    }



FromTheFuture 04-25-2013 14:18

Re: How to block grenade throw
 
Work =)
Lilltle question, how can do to show left time whenever click on +attack, now I see time when change weapon to grenade.
And how to remove dot on message after number? Now I see "Please, wait 2. seconds"


All times are GMT -4. The time now is 10:46.

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