Участник
Пользователь
- Сообщения
- 78
- Реакции
- 1
Приветствую, вопрос данной темы следующий, как можно реализовать 2 режим у минигана на ЛКМ, что бы просто барабан раскручивался но не стрелял, если что за основу данного плагина был взят данный плагин, просто я лично долго думал над этим вопросм, но всё же не смог прийти к решению, так же выслушаю критику или же предложения по улучшению кода.
C#:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <xs>
#include <reapi>
#define ITEM_FLAG_NOFIREUNDERWATER BIT( 5 )
#define INSTANCE(%0) ( ( %0 == -1 ) ? 0 : %0 )
#define IsCustomWeapon(%0,%1) bool: ( get_entvar( %0, var_impulse ) == %1 )
#define GetWeaponClip(%0) get_member( %0, m_Weapon_iClip )
#define SetWeaponClip(%0,%1) set_member( %0, m_Weapon_iClip, %1 )
#define GetWeaponAmmoType(%0) get_member( %0, m_Weapon_iPrimaryAmmoType )
#define SetWeaponAmmoType(%0,%1) set_member( %0, m_Weapon_iPrimaryAmmoType, %1 )
#define GetWeaponAmmo(%0,%1) get_member( %0, m_rgAmmo, %1 )
#define SetWeaponAmmo(%0,%1,%2) set_member( %0, m_rgAmmo, %1, %2 )
enum {
WEAPON_ANIM_IDLE,
WEAPON_ANIM_DRAW,
WEAPON_ANIM_SHOOT,
WEAPON_ANIM_RELOAD,
WEAPON_ANIM_FIRE_READY,
WEAPON_ANIM_IDLE_CHANGE,
WEAPON_ANIM_FIRE_CHANGE
}; new const Float: WEAPON_ANIM_TIME[ ] = { 1.0, 5.0 };
new const WEAPON_REFERENCE[ ] = "weapon_m249";
new const WEAPON_WEAPONLIST[ ] = "weapon_m134";
new const WEAPON_ANIMATION[ ] = "onehanded";
new const WEAPON_MODEL_VIEW[ ] = "models/m134/v_m134.mdl";
new const WEAPON_MODEL_PLAYER[ ] = "models/m134/p_m134.mdl";
new const WEAPON_MODEL_WORLD[ ] = "models/m134/w_m134.mdl";
new const WEAPON_SOUNDS[ ][ ] = {
"weapons/m134-1.wav",
"weapons/m134_spinup.wav",
"weapons/m134_spindown.wav",
"weapons/m134_pinpull.wav",
"weapons/m134_clipoff.wav",
"weapons/m134_clipon.wav"
};
const WEAPON_MODEL_WORLD_BODY = 0;
const WEAPON_CLIP = 100; // Патроны в обойме.
const WEAPON_AMMO = 200; // Запасные патроны.
const Float: WEAPON_DAMAGE = 10.0; // Урон
const WEAPON_DMG_TYPE = ( DMG_BULLET | DMG_NEVERGIB );
const Float: WEAPON_FIRE_RATE = 0.075; // Скорострельность.
const Float: WEAPON_MOVE_SPEED = 225.0; // Скорость бега.
new g_iAllocString_WeaponUID;
public plugin_init( ) {
register_clcmd("m134", "Native__GiveWeapon")
register_forward( FM_UpdateClientData, "UpdateClientData_Post", true );
RegisterHookChain( RG_CWeaponBox_SetModel, "CWeaponBox__SetModel_Pre", false );
RegisterHam( Ham_Spawn, WEAPON_REFERENCE, "CBasePlayerWeapon__Spawn_Post", true );
RegisterHam( Ham_Item_Deploy, WEAPON_REFERENCE, "CBasePlayerWeapon__Deploy_Post", true );
RegisterHam( Ham_Item_Holster, WEAPON_REFERENCE, "CBasePlayerWeapon__Holster_Post", true );
RegisterHam( Ham_Item_AddToPlayer, WEAPON_REFERENCE, "CBasePlayerWeapon__AddToPlayer_Post", true );
RegisterHam( Ham_Weapon_Reload, WEAPON_REFERENCE, "CBasePlayerWeapon__Reload_Pre", false );
RegisterHam( Ham_Weapon_WeaponIdle, WEAPON_REFERENCE, "CBasePlayerWeapon__WeaponIdle_Pre", false );
RegisterHam( Ham_Weapon_PrimaryAttack, WEAPON_REFERENCE, "CBasePlayerWeapon__PrimaryAttack_Pre", false );
g_iAllocString_WeaponUID = engfunc( EngFunc_AllocString, WEAPON_WEAPONLIST );
}
public plugin_precache( ) {
engfunc( EngFunc_PrecacheModel, WEAPON_MODEL_VIEW );
engfunc( EngFunc_PrecacheModel, WEAPON_MODEL_PLAYER );
engfunc( EngFunc_PrecacheModel, WEAPON_MODEL_WORLD );
for ( new i; i < sizeof WEAPON_SOUNDS; i++ )
engfunc( EngFunc_PrecacheSound, WEAPON_SOUNDS[ i ] );
UTIL_PrecacheWeaponlist( WEAPON_WEAPONLIST );
}
public plugin_natives( ) register_native( "give_user_m134predator", "Native__GiveWeapon" );
public Native__GiveWeapon( id )
return rg_give_custom_item( id, WEAPON_REFERENCE, GT_DROP_AND_REPLACE, g_iAllocString_WeaponUID );
public UpdateClientData_Post( const pPlayer, const iSendWeapons, const CD_Handle ) {
if ( !is_user_alive( pPlayer ) )
return;
static pActiveItem; pActiveItem = get_member( pPlayer, m_pActiveItem );
if ( is_nullent( pActiveItem ) || !IsCustomWeapon( pActiveItem, g_iAllocString_WeaponUID ) )
return;
set_cd( CD_Handle, CD_flNextAttack, get_gametime( ) + 0.001 );
}
public CWeaponBox__SetModel_Pre( const pWeaponBox, const szModel[ ] ) {
if ( !IsCustomWeapon( UTIL_GetWeaponBoxItem( pWeaponBox ), g_iAllocString_WeaponUID ) )
return HC_CONTINUE;
SetHookChainArg( 2, ATYPE_STRING, WEAPON_MODEL_WORLD );
set_entvar( pWeaponBox, var_body, WEAPON_MODEL_WORLD_BODY );
return HC_CONTINUE;
}
public CBasePlayerWeapon__Spawn_Post( const pItem ) {
if ( !IsCustomWeapon( pItem, g_iAllocString_WeaponUID ) )
return;
set_member( pItem, m_Weapon_iClip, WEAPON_CLIP );
set_member( pItem, m_Weapon_iDefaultAmmo, WEAPON_AMMO );
set_entvar( pItem, var_classname, WEAPON_WEAPONLIST );
rg_set_iteminfo( pItem, ItemInfo_pszName, WEAPON_WEAPONLIST );
rg_set_iteminfo( pItem, ItemInfo_iMaxClip, WEAPON_CLIP );
rg_set_iteminfo( pItem, ItemInfo_iMaxAmmo1, WEAPON_AMMO );
rg_set_iteminfo( pItem, ItemInfo_iFlags, ITEM_FLAG_NOFIREUNDERWATER );
}
public CBasePlayerWeapon__Deploy_Post( const pItem ) {
if ( !IsCustomWeapon( pItem, g_iAllocString_WeaponUID ) )
return;
new pPlayer = get_member( pItem, m_pPlayer );
set_entvar( pPlayer, var_viewmodel, WEAPON_MODEL_VIEW );
set_entvar( pPlayer, var_weaponmodel, WEAPON_MODEL_PLAYER );
UTIL_SendWeaponAnim( MSG_ONE, pPlayer, WEAPON_ANIM_DRAW );
remove_task( pItem );
set_member( pItem, m_Weapon_fMaxSpeed, WEAPON_MOVE_SPEED );
set_member( pItem, m_Weapon_flTimeWeaponIdle, WEAPON_ANIM_TIME[ 0 ] );
set_member( pItem, m_Weapon_flNextPrimaryAttack, WEAPON_ANIM_TIME[ 0 ] );
set_member( pItem, m_Weapon_flNextSecondaryAttack, WEAPON_ANIM_TIME[ 0 ] );
set_member( pPlayer, m_flNextAttack, WEAPON_ANIM_TIME[ 0 ] );
set_member( pPlayer, m_szAnimExtention, WEAPON_ANIMATION );
}
public CBasePlayerWeapon__Holster_Post( const pItem ) {
if ( !IsCustomWeapon( pItem, g_iAllocString_WeaponUID ) )
return;
set_member( pItem, m_Weapon_fInReload, 0 );
}
public CBasePlayerWeapon__AddToPlayer_Post( const pItem, const pPlayer ) {
new iWeaponUID = get_entvar( pItem, var_impulse );
if ( iWeaponUID != 0 && iWeaponUID != g_iAllocString_WeaponUID )
return;
UTIL_WeaponList( MSG_ONE, pPlayer, pItem );
}
public CBasePlayerWeapon__Reload_Pre( const pItem ) {
if ( !IsCustomWeapon( pItem, g_iAllocString_WeaponUID ) )
return HAM_IGNORED;
static pPlayer; pPlayer = get_member( pItem, m_pPlayer );
UTIL_MinigunReload( pPlayer, pItem, WEAPON_ANIM_RELOAD, WEAPON_ANIM_TIME[ 1 ] );
return HAM_SUPERCEDE;
}
public CBasePlayerWeapon__WeaponIdle_Pre( const pItem ) {
if ( !IsCustomWeapon( pItem, g_iAllocString_WeaponUID ) || get_member( pItem, m_Weapon_flTimeWeaponIdle ) > 0.0 )
return HAM_IGNORED;
new pPlayer = get_member( pItem, m_pPlayer );
new iClip = GetWeaponClip( pItem );
new iAmmoType = GetWeaponAmmoType( pItem );
new iAmmo = GetWeaponAmmo( pPlayer, iAmmoType );
if ( iClip == 0 && iAmmo ) ExecuteHamB( Ham_Weapon_Reload, pItem );
else {
UTIL_SendWeaponAnim( MSG_ONE, pPlayer, WEAPON_ANIM_IDLE );
set_member( pItem, m_Weapon_flTimeWeaponIdle, WEAPON_ANIM_TIME[ 0 ] );
}
return HAM_SUPERCEDE;
}
public CBasePlayerWeapon__PrimaryAttack_Pre( const pItem ) {
if ( !IsCustomWeapon( pItem, g_iAllocString_WeaponUID ) )
return HAM_IGNORED;
new pPlayer = get_member( pItem, m_pPlayer );
static iClip; iClip = GetWeaponClip( pItem );
if ( !iClip ) {
ExecuteHamB( Ham_Weapon_Reload, pItem );
return HAM_SUPERCEDE;
}
UTIL_SendWeaponAnim( MSG_ONE, pPlayer, WEAPON_ANIM_SHOOT );
rg_send_audio( pPlayer, WEAPON_SOUNDS[ 0 ]);
UTIL_FireBuckshots( pPlayer, pItem, Float: { 0.05, 0.05, 0.0 }, 3000.0, WEAPON_DAMAGE, WEAPON_DMG_TYPE );
new Float: vecPunchAngle[ 3 ]; get_entvar( pPlayer, var_punchangle, vecPunchAngle );
vecPunchAngle[ 0 ] -= random_float( 0.25, 0.75 )
set_entvar( pPlayer, var_punchangle, vecPunchAngle );
SetWeaponClip( pItem, --iClip );
set_member( pItem, m_Weapon_flNextPrimaryAttack, WEAPON_FIRE_RATE );
set_member( pItem, m_Weapon_flNextSecondaryAttack, WEAPON_ANIM_TIME[ 0 ] );
set_member( pItem, m_Weapon_flTimeWeaponIdle, WEAPON_ANIM_TIME[ 0 ] );
return HAM_SUPERCEDE;
}
stock UTIL_PrecacheWeaponlist( const szWeaponList[ ] ) {
new szBuffer[ 128 ], pFile;
format( szBuffer, charsmax( szBuffer ), "sprites/%s.txt", szWeaponList );
engfunc( EngFunc_PrecacheGeneric, szBuffer );
if ( !( pFile = fopen( szBuffer, "rb" ) ) )
return;
new szSprName[ 64 ], iPos;
while ( !feof( pFile ) ) {
fgets( pFile, szBuffer, charsmax( szBuffer ) );
trim( szBuffer );
if ( !strlen( szBuffer ) )
continue;
if ( ( iPos = containi( szBuffer, "640" ) ) == -1 )
continue;
format( szBuffer, charsmax( szBuffer ), "%s", szBuffer[ iPos + 3 ] );
trim( szBuffer );
strtok( szBuffer, szSprName, charsmax( szSprName ), szBuffer, charsmax( szBuffer ), ' ', 1 );
trim( szSprName );
engfunc( EngFunc_PrecacheGeneric, fmt( "sprites/%s.spr", szSprName ) );
}
fclose( pFile );
}
stock UTIL_SendWeaponAnim( const iDest, const pPlayer, const iAnim ) {
set_entvar( pPlayer, var_weaponanim, iAnim );
message_begin( iDest, SVC_WEAPONANIM, _, pPlayer );
write_byte( iAnim );
write_byte( 0 );
message_end( );
}
stock UTIL_WeaponList( const iDest, const pPlayer, const pItem ) {
static iMsgID_Weaponlist; if ( !iMsgID_Weaponlist ) iMsgID_Weaponlist = get_user_msgid( "WeaponList" );
new szWeaponName[ 32 ]; rg_get_iteminfo( pItem, ItemInfo_pszName, szWeaponName, charsmax( szWeaponName ) );
message_begin( iDest, iMsgID_Weaponlist, _, pPlayer );
write_string( szWeaponName );
write_byte( GetWeaponAmmoType( pItem ) );
write_byte( rg_get_iteminfo( pItem, ItemInfo_iMaxAmmo1 ) );
write_byte( get_member( pItem, m_Weapon_iSecondaryAmmoType ) );
write_byte( rg_get_iteminfo( pItem, ItemInfo_iMaxAmmo2 ) );
write_byte( rg_get_iteminfo( pItem, ItemInfo_iSlot ) );
write_byte( rg_get_iteminfo( pItem, ItemInfo_iPosition ) );
write_byte( rg_get_iteminfo( pItem, ItemInfo_iId ) );
write_byte( rg_get_iteminfo( pItem, ItemInfo_iFlags ) );
message_end( );
}
stock UTIL_GetWeaponBoxItem( const pWeaponBox ) {
for ( new iSlot, pItem; iSlot < MAX_ITEM_TYPES; iSlot++ ) {
if ( !is_nullent( ( pItem = get_member( pWeaponBox, m_WeaponBox_rgpPlayerItems, iSlot ) ) ) )
return pItem;
}
return NULLENT;
}
stock bool: UTIL_MinigunReload( const pPlayer, const pItem, const iAnimReloadStart, const Float: flReloadStart ) {
new iClip = GetWeaponClip( pItem );
new iAmmoType = GetWeaponAmmoType( pItem );
new iAmmo = GetWeaponAmmo( pPlayer, iAmmoType );
if ( iAmmo <= 0 || iClip == rg_get_iteminfo( pItem, ItemInfo_iMaxClip ) || get_member( pItem, m_Weapon_flNextPrimaryAttack ) > 0.0 )
return false;
rg_set_animation( pPlayer, PLAYER_RELOAD );
UTIL_SendWeaponAnim( MSG_ONE, pPlayer, iAnimReloadStart );
set_member( pItem, m_Weapon_flNextPrimaryAttack, flReloadStart );
set_member( pItem, m_Weapon_flNextSecondaryAttack, flReloadStart );
set_member( pItem, m_Weapon_flTimeWeaponIdle, flReloadStart );
set_member( pPlayer, m_flNextAttack, flReloadStart );
set_member( pItem, m_Weapon_fInReload, 1 );
set_task(4.85, "SetAmmo", pItem );
return true;
}
public SetAmmo( const pItem ) {
if ( !get_member( pItem, m_Weapon_fInReload ) )
return;
new pPlayer = get_member( pItem, m_pPlayer );
new iClip = GetWeaponClip( pItem );
new iAmmoType = GetWeaponAmmoType( pItem );
new iAmmo = GetWeaponAmmo( pPlayer, iAmmoType );
set_member( pItem, m_Weapon_fInReload, 0 );
if( ( iClip + iAmmo ) < rg_get_iteminfo( pItem, ItemInfo_iMaxClip ) ) {
SetWeaponClip( pItem, iClip + iAmmo );
SetWeaponAmmo( pPlayer, iAmmo - ( rg_get_iteminfo( pItem, ItemInfo_iMaxClip ) - iClip ), iAmmoType );
} else {
SetWeaponClip( pItem, rg_get_iteminfo( pItem, ItemInfo_iMaxClip ) );
SetWeaponAmmo( pPlayer, iAmmo - ( rg_get_iteminfo( pItem, ItemInfo_iMaxClip ) - iClip ), iAmmoType );
}
}
stock UTIL_FireBuckshots( const pPlayer, const pItem, const Float: vecSpread[ 3 ] = NULL_VECTOR, const Float: flDistance, const Float: flBaseDamage, const bitsDamageType ) {
new Float: vecOrigin[ 3 ]; get_entvar( pPlayer, var_origin, vecOrigin );
new Float: vecViewOfs[ 3 ]; get_entvar( pPlayer, var_view_ofs, vecViewOfs );
xs_vec_add( vecOrigin, vecViewOfs, vecOrigin );
new Float: vecPunchAngle[ 3 ]; get_entvar( pPlayer, var_punchangle, vecPunchAngle );
new Float: vecViewAngle[ 3 ]; get_entvar( pPlayer, var_v_angle, vecViewAngle );
xs_vec_add( vecViewAngle, vecPunchAngle, vecViewAngle );
new Float: vecForward[ 3 ], Float: vecRight[ 3 ], Float: vecUp[ 3 ];
engfunc( EngFunc_AngleVectors, vecViewAngle, vecForward, vecRight, vecUp );
new Float: flXYZ[ 3 ], Float: vecDirection[ 3 ], Float: vecEndPos[ 3 ], Float: vecPlaneNormal[ 3 ];
new pTrace = create_tr2( ), pHit, Float: flFraction, Float: flDamage;
rg_multidmg_clear( );
do {
flXYZ[ 0 ] = random_float( -0.5, 0.5 ) + random_float( -0.5, 0.5 );
flXYZ[ 1 ] = random_float( -0.5, 0.5 ) + random_float( -0.5, 0.5 );
flXYZ[ 2 ] = flXYZ[ 0 ] * flXYZ[ 0 ] + flXYZ[ 1 ] * flXYZ[ 1 ];
} while ( flXYZ[ 2 ] > 1.0 );
vecDirection[ 0 ] = vecForward[ 0 ] + flXYZ[ 0 ] * vecSpread[ 0 ] * vecRight[ 0 ] + flXYZ[ 1 ] * vecSpread[ 1 ] * vecUp[ 0 ];
vecDirection[ 1 ] = vecForward[ 1 ] + flXYZ[ 0 ] * vecSpread[ 0 ] * vecRight[ 1 ] + flXYZ[ 1 ] * vecSpread[ 1 ] * vecUp[ 1 ];
vecDirection[ 2 ] = vecForward[ 2 ] + flXYZ[ 0 ] * vecSpread[ 0 ] * vecRight[ 2 ] + flXYZ[ 1 ] * vecSpread[ 1 ] * vecUp[ 2 ];
xs_vec_add_scaled( vecOrigin, vecDirection, flDistance, vecEndPos );
engfunc( EngFunc_TraceLine, vecOrigin, vecEndPos, DONT_IGNORE_MONSTERS, pPlayer, pTrace );
get_tr2( pTrace, TR_flFraction, flFraction );
if ( flFraction != 1.0 ) {
pHit = INSTANCE( get_tr2( pTrace, TR_pHit ) );
flDamage = ( ( 1.0 - flFraction ) * flBaseDamage );
ExecuteHamB( Ham_TraceAttack, pHit, pPlayer, flDamage, vecDirection, pTrace, bitsDamageType );
get_tr2( pTrace, TR_vecEndPos, vecEndPos );
if ( engfunc( EngFunc_PointContents, vecEndPos ) != CONTENTS_SKY ) {
get_tr2( pTrace, TR_vecPlaneNormal, vecPlaneNormal );
UTIL_HitWallEffects( pHit, vecEndPos, .vecDirection = vecPlaneNormal );
}
}
free_tr2( pTrace );
rg_multidmg_apply( pItem, pPlayer );
}
stock UTIL_HitWallEffects( const pEntity, const Float: vecOrigin[ 3 ], const bool: bSparks = true, Float: vecDirection[ 3 ], const iColor = 4 ) {
if ( pEntity && is_nullent( pEntity ) || ( get_entvar( pEntity, var_flags ) & FL_KILLME ) || !ExecuteHam( Ham_IsBSPModel, pEntity ) )
return;
new iDecalID = UTIL_DamageDecal( pEntity );
if ( iDecalID == -1 )
return;
message_begin_f( MSG_PAS, SVC_TEMPENTITY, vecOrigin );
UTIL_TE_GUNSHOTDECAL( vecOrigin, pEntity, iDecalID );
if ( bSparks ) {
xs_vec_mul_scalar( vecDirection, random_float( 25.0, 30.0 ), vecDirection );
message_begin_f( MSG_PAS, SVC_TEMPENTITY, vecOrigin );
UTIL_TE_STREAK_SPLASH( vecOrigin, vecDirection, iColor, random_num( 10, 20 ), 3, 64 );
}
}
stock UTIL_DamageDecal( const pEntity ) {
new iRenderMode = get_entvar( pEntity, var_rendermode );
if ( iRenderMode == kRenderTransAlpha )
return -1;
static iGlassDecalID; if ( !iGlassDecalID ) iGlassDecalID = engfunc( EngFunc_DecalIndex, "{bproof1" );
if ( iRenderMode != kRenderNormal )
return iGlassDecalID;
static iShotDecalID; if ( !iShotDecalID ) iShotDecalID = engfunc( EngFunc_DecalIndex, "{shot1" );
return ( iShotDecalID - random_num( 0, 4 ) );
}
stock UTIL_TE_GUNSHOTDECAL( const Float: vecOrigin[ 3 ], const pEntity, const iDecalID ) {
write_byte( TE_GUNSHOTDECAL );
write_coord_f( vecOrigin[ 0 ] );
write_coord_f( vecOrigin[ 1 ] );
write_coord_f( vecOrigin[ 2 ] );
write_short( pEntity );
write_byte( iDecalID );
message_end( );
}
stock UTIL_TE_STREAK_SPLASH( const Float: vecOrigin[ 3 ], const Float: vecDirection[ 3 ], const iColor, const iCount, const iSpeed, const iNoise ) {
write_byte( TE_STREAK_SPLASH );
write_coord_f( vecOrigin[ 0 ] );
write_coord_f( vecOrigin[ 1 ] );
write_coord_f( vecOrigin[ 2 ] );
write_coord_f( vecDirection[ 0 ] );
write_coord_f( vecDirection[ 1 ] );
write_coord_f( vecDirection[ 2 ] );
write_byte( iColor );
write_short( iCount );
write_short( iSpeed );
write_short( iNoise );
message_end( );
}