PDA

View Full Version : Weapon Jams


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;
}

diamond-optic
07-24-2007, 11:18 PM
whats this pdata entry do??

ive got a weapon jamming plugin thats been done for some time now (just wayyyy to lazy to get around to posting it) and i basically use just iuser values of the weapon entity to set whether its jammed or not (or permanently jammed)

i was planning on releasing it any day now (everyday i tell myself im gonna post it lol) but if this is a better method that i could incorporate into it, i'd rather wait and do that...

what i have seems to work really good for the month or two ive been running it.. (running it this long before posting it also helped me get rid of a couple nasty bugs)

only real problem im having (isnt really *much* of a problem) is the way im blocking the animations when its jammed also blocks the animation for using a melee (bayo/butt) on a jammed weapon.. well it will show the animation.. but takes a second to 'know' that it is allowed to so the begginning or the 1st stab/swing gets cut off or not shown at all...


*edit*

alright i just tried the pdata thing.. so it blocks the weapon from shooting.. thats cool lol.. except using secondary attack (be it a bayonet or deploying an mg) lets you fire again.. same with dropping it and picking it back up.. but i didnt try your whole code so idk if u have anything else there for those problems..