D4rkSiD3Rs |
07-01-2018 17:35 |
Re: Adding Burst-Fire Mode to a weapon
Quote:
Originally Posted by maqi
(Post 2600413)
This should work
PHP Code:
#include < amxmodx >
#include < hamsandwich >
#include < fakemeta >
#include < cstrike >
#pragma semicolon 1
#define PLUGIN "Force burst"
#define VERSION "1.0a"
#define TASKID_BURST 16123
new const m_rgpPlayerItems_CBasePlayer[6] = {367,368,...};
public plugin_init( )
{
register_plugin( PLUGIN, VERSION, "maqi" );
RegisterHam( Ham_Spawn, "player", "Event_PlayerSpawnPost", 1 );
register_event( "WeapPickup", "Event_WeaponPickup", "be" );
}
public Event_WeaponPickup( iIndex )
{
if( !is_user_connected( iIndex ) )
return;
if( remove_task( TASKID_BURST + iIndex ) )
set_task( 0.5, "Task_EnablePlayerBurst", TASKID_BURST + iIndex );
}
public Event_PlayerSpawnPost( iIndex )
{
if( !is_user_connected( iIndex ) )
return;
if( remove_task( TASKID_BURST + iIndex ) )
set_task( 0.5, "Task_EnablePlayerBurst", TASKID_BURST + iIndex );
}
public Task_EnablePlayerBurst( const iTaskID )
{
new iIndex = iTaskID - TASKID_BURST;
if( user_has_weapon( iIndex, CSW_FAMAS ) && HamGetWeaponEntityID( iIndex, CSW_FAMAS ) )
EnableWeaponBurst( iIndex, CSW_FAMAS );
if( user_has_weapon( iIndex, CSW_GLOCK18 ) && HamGetWeaponEntityID( iIndex, CSW_GLOCK18 ) )
EnableWeaponBurst( iIndex, CSW_GLOCK18 );
}
EnableWeaponBurst( iIndex, iWeapon )
{
if( !cs_get_weapon_burst( HamGetWeaponEntityID( iIndex, iWeapon ) ) )
cs_set_weapon_burst( HamGetWeaponEntityID( iIndex, iWeapon ), 1 );
}
stock HamGetWeaponEntityID( iIndex, iWeaponID )
{
new iWeaponEnt;
for(new i=1; i<6; i++)
{
iWeaponEnt = get_pdata_cbase( iIndex, m_rgpPlayerItems_CBasePlayer[i] );
while( pev_valid(iWeaponEnt) )
{
if( get_pdata_int(iWeaponEnt, 43, 4) == iWeaponID )
return iWeaponEnt;
iWeaponEnt = get_pdata_cbase( iWeaponEnt, 42, 4 );
}
}
return 0;
}
EDIT: Edited the code above to actually work when people are buying/picking up weapons.
|
I tested it on my furien mod but it's not working! I edited it to be on M249
PHP Code:
#include < amxmodx >
#include < hamsandwich >
#include < fakemeta >
#include < cstrike >
#pragma semicolon 1
#define PLUGIN "Force burst"
#define VERSION "1.0a"
#define TASKID_BURST 16123
new const m_rgpPlayerItems_CBasePlayer[6] = {367,368,...};
public plugin_init( )
{
register_plugin( PLUGIN, VERSION, "maqi" );
RegisterHam( Ham_Spawn, "player", "Event_PlayerSpawnPost", 1 );
register_event( "WeapPickup", "Event_WeaponPickup", "be" );
}
public Event_WeaponPickup( iIndex )
{
if( !is_user_connected( iIndex ) )
return;
if( remove_task( TASKID_BURST + iIndex ) )
set_task( 0.5, "Task_EnablePlayerBurst", TASKID_BURST + iIndex );
}
public Event_PlayerSpawnPost( iIndex )
{
if( !is_user_connected( iIndex ) )
return;
if( remove_task( TASKID_BURST + iIndex ) )
set_task( 0.5, "Task_EnablePlayerBurst", TASKID_BURST + iIndex );
}
public Task_EnablePlayerBurst( const iTaskID )
{
new iIndex = iTaskID - TASKID_BURST;
if( user_has_weapon( iIndex, CSW_M249 ) && HamGetWeaponEntityID( iIndex, CSW_M249 ) )
EnableWeaponBurst( iIndex, CSW_M249 );
}
EnableWeaponBurst( iIndex, iWeapon )
{
if( !cs_get_weapon_burst( HamGetWeaponEntityID( iIndex, iWeapon ) ) )
cs_set_weapon_burst( HamGetWeaponEntityID( iIndex, iWeapon ), 1 );
}
stock HamGetWeaponEntityID( iIndex, iWeaponID )
{
new iWeaponEnt;
for(new i=1; i<6; i++)
{
iWeaponEnt = get_pdata_cbase( iIndex, m_rgpPlayerItems_CBasePlayer[i] );
while( pev_valid(iWeaponEnt) )
{
if( get_pdata_int(iWeaponEnt, 43, 4) == iWeaponID )
return iWeaponEnt;
iWeaponEnt = get_pdata_cbase( iWeaponEnt, 42, 4 );
}
}
return 0;
}
|