Wilson [29th ID]
07-24-2007, 10:33 PM
This is a plugin that makes the MG jam at a random time based on variables (highs and lows). It is not complete, but the foundation is there, and it is very easy upon which to expand.
I have no desire to complete this; perhaps someone else will. I did the research, found the pdata offsets etc. And just lost interest.
#include <amxmodx>
#include <amxmisc>
#include <dodx>
#include <fakemeta>
#pragma semicolon 1
#define PLUGIN "Asst. Gunner"
#define VERSION "1.0"
#define AUTHOR "29th ID"
#define JAM_LOW 40
#define JAM_HIGH 80
#define ROF_PRIMARY 103
new g_cvarEnabled, g_cvarDisabledROF;
new g_msgCurWeapon;
new g_StoredAmmo[33];
public plugin_init() {
register_plugin( PLUGIN, VERSION, AUTHOR );
// CVARs
g_cvarEnabled = register_cvar( "dod_asstgunner", "1" );
g_cvarDisabledROF = register_cvar( "rof", "100.0" );
// Register Messages
g_msgCurWeapon = get_user_msgid( "CurWeapon" );
register_message( g_msgCurWeapon, "hook_CurWeapon" );
}
public hook_CurWeapon( msgid, msgDest, msgEnt ) {
if( !get_pcvar_num( g_cvarEnabled ) || !is_user_alive( msgEnt ) ) return PLUGIN_CONTINUE;
new m_iWpn = get_msg_arg_int( 2 );
new m_iAmmo = get_msg_arg_int( 3 );
if( is_mg( m_iWpn ) && ( g_StoredAmmo[msgEnt] != m_iAmmo ) )
{
new m_iWpnEnt = detect_weapon_id( msgEnt );
new m_iuser1 = pev( m_iWpnEnt, pev_iuser1 );
new m_iuser2 = pev( m_iWpnEnt, pev_iuser2 );
new m_iuser1new = m_iuser1 + 1;
// If random # is empty, set it
if( !m_iuser2 )
{
set_pev( m_iWpnEnt, pev_iuser2, random_num( JAM_LOW, JAM_HIGH ) );
}
set_pev( m_iWpnEnt, pev_iuser1, m_iuser1new );
console_print( msgEnt, "iuser1: %i iuser2: %i", m_iuser1new, m_iuser2 );
if( m_iuser1new == m_iuser2 )
{
client_print( msgEnt, print_center, "Your Weapon Has Jammed! Reload to Fix the Jam!" );
set_pev( m_iWpnEnt, pev_iuser1, 0 );
set_pev( m_iWpnEnt, pev_iuser2, 0 );
set_pdata_float( m_iWpnEnt, ROF_PRIMARY, get_pcvar_float( g_cvarDisabledROF ) );
}
g_StoredAmmo[msgEnt] = m_iAmmo;
}
return PLUGIN_CONTINUE;
}
// Detects if weapon is a machine gun
is_mg( m_iWpn ) {
if( m_iWpn == DODW_30_CAL || m_iWpn == DODW_MG34 || m_iWpn == DODW_MG42 )
return 1;
return 0;
}
// Detects weapon entity number
stock detect_weapon_id( id ) {
new m_iCurEnt = -1, m_iWpnEnt = 0, m_szWpn[32];
// Get User Weapon and WpnName
new clip, ammo, m_iWpn = get_user_weapon(id,clip,ammo);
xmod_get_wpnlogname( m_iWpn, m_szWpn, 31 ); // Requires DoDX Module
format( m_szWpn, 31, "weapon_%s", m_szWpn );
// Get User Origin
new Float:m_flOrigin[3];
pev( id, pev_origin, m_flOrigin );
// Find Dummy Weapon
while( ( m_iCurEnt = engfunc( EngFunc_FindEntityInSphere, m_iCurEnt, m_flOrigin, Float:1.0 ) ) != 0 ) {
new m_szClassname[32];
pev( m_iCurEnt, pev_classname, m_szClassname, 31 );
if( equal( m_szClassname, m_szWpn ) )
m_iWpnEnt = m_iCurEnt;
}
return m_iWpnEnt;
}
I have no desire to complete this; perhaps someone else will. I did the research, found the pdata offsets etc. And just lost interest.
#include <amxmodx>
#include <amxmisc>
#include <dodx>
#include <fakemeta>
#pragma semicolon 1
#define PLUGIN "Asst. Gunner"
#define VERSION "1.0"
#define AUTHOR "29th ID"
#define JAM_LOW 40
#define JAM_HIGH 80
#define ROF_PRIMARY 103
new g_cvarEnabled, g_cvarDisabledROF;
new g_msgCurWeapon;
new g_StoredAmmo[33];
public plugin_init() {
register_plugin( PLUGIN, VERSION, AUTHOR );
// CVARs
g_cvarEnabled = register_cvar( "dod_asstgunner", "1" );
g_cvarDisabledROF = register_cvar( "rof", "100.0" );
// Register Messages
g_msgCurWeapon = get_user_msgid( "CurWeapon" );
register_message( g_msgCurWeapon, "hook_CurWeapon" );
}
public hook_CurWeapon( msgid, msgDest, msgEnt ) {
if( !get_pcvar_num( g_cvarEnabled ) || !is_user_alive( msgEnt ) ) return PLUGIN_CONTINUE;
new m_iWpn = get_msg_arg_int( 2 );
new m_iAmmo = get_msg_arg_int( 3 );
if( is_mg( m_iWpn ) && ( g_StoredAmmo[msgEnt] != m_iAmmo ) )
{
new m_iWpnEnt = detect_weapon_id( msgEnt );
new m_iuser1 = pev( m_iWpnEnt, pev_iuser1 );
new m_iuser2 = pev( m_iWpnEnt, pev_iuser2 );
new m_iuser1new = m_iuser1 + 1;
// If random # is empty, set it
if( !m_iuser2 )
{
set_pev( m_iWpnEnt, pev_iuser2, random_num( JAM_LOW, JAM_HIGH ) );
}
set_pev( m_iWpnEnt, pev_iuser1, m_iuser1new );
console_print( msgEnt, "iuser1: %i iuser2: %i", m_iuser1new, m_iuser2 );
if( m_iuser1new == m_iuser2 )
{
client_print( msgEnt, print_center, "Your Weapon Has Jammed! Reload to Fix the Jam!" );
set_pev( m_iWpnEnt, pev_iuser1, 0 );
set_pev( m_iWpnEnt, pev_iuser2, 0 );
set_pdata_float( m_iWpnEnt, ROF_PRIMARY, get_pcvar_float( g_cvarDisabledROF ) );
}
g_StoredAmmo[msgEnt] = m_iAmmo;
}
return PLUGIN_CONTINUE;
}
// Detects if weapon is a machine gun
is_mg( m_iWpn ) {
if( m_iWpn == DODW_30_CAL || m_iWpn == DODW_MG34 || m_iWpn == DODW_MG42 )
return 1;
return 0;
}
// Detects weapon entity number
stock detect_weapon_id( id ) {
new m_iCurEnt = -1, m_iWpnEnt = 0, m_szWpn[32];
// Get User Weapon and WpnName
new clip, ammo, m_iWpn = get_user_weapon(id,clip,ammo);
xmod_get_wpnlogname( m_iWpn, m_szWpn, 31 ); // Requires DoDX Module
format( m_szWpn, 31, "weapon_%s", m_szWpn );
// Get User Origin
new Float:m_flOrigin[3];
pev( id, pev_origin, m_flOrigin );
// Find Dummy Weapon
while( ( m_iCurEnt = engfunc( EngFunc_FindEntityInSphere, m_iCurEnt, m_flOrigin, Float:1.0 ) ) != 0 ) {
new m_szClassname[32];
pev( m_iCurEnt, pev_classname, m_szClassname, 31 );
if( equal( m_szClassname, m_szWpn ) )
m_iWpnEnt = m_iCurEnt;
}
return m_iWpnEnt;
}