Well I'll get to the point, since I'm a programming noob, I come to ask you masters of programming for a little help
I made a filthy copy paste of the mp5 code and modified it to look like the Sniper from Crack life
The problem is the animations which do not come out when they should
The deploy animation appears when it is recharging and the firing animation when the weapon is taken out and I don't know what the hell I'm doing wrong
Here is the Sniper Code if you are interested in helping me
Or right, I almost forgot
Merry Christmas to all :)
snipars.cpp
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "player.h"
#include "soundent.h"
#include "gamerules.h"
#include "snipars.h"
LINK_ENTITY_TO_CLASS( weapon_snipars, CSniper );
LINK_ENTITY_TO_CLASS( ammo_snipars, CSniperAmmoClip );
enum sniper_e
{
SNIPER_IDLE_SIL = 0,
SNIPER_FIRE1,
SNIPER_DEPLOY,
SNIPER_RELOAD,
};
void CSniper::Spawn( )
{
pev->classname = MAKE_STRING("weapon_snipars"); // hack to allow for old names
Precache( );
SET_MODEL(ENT(pev), SNIPER_MODEL_WORLD);
m_iId = WEAPON_SNIPER;
m_iDefaultAmmo = SNIPER_DEFAULT_AMMO;
FallInit();// get ready to fall down.
}
void CSniper::Precache( void )
{
PRECACHE_MODEL(SNIPER_MODEL_1STPERSON);
PRECACHE_MODEL(SNIPER_MODEL_3RDPERSON);
PRECACHE_MODEL(SNIPER_MODEL_WORLD);
m_iShell = PRECACHE_MODEL ("models/shell.mdl");// brass shell
PRECACHE_SOUND (SNIPER_SOUND_FIRE1);
PRECACHE_SOUND (SNIPER_SOUND_FIRE2);
PRECACHE_SOUND (SNIPER_SOUND_FIRE3);
PRECACHE_SOUND (SNIPER_SOUND_FIRE4);
PRECACHE_SOUND (SNIPER_SOUND_FIRE5);
m_event = PRECACHE_EVENT( 1, "events/sniper.sc" );
m_event_z = PRECACHE_EVENT( 1, "events/sniperz.sc" );
}
int CSniper::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
p->pszAmmo1 = "ammo_snipars"; // The type of ammo it uses
p->iMaxAmmo1 = SNIPER_MAX_AMMO; // Max ammo the player can carry
p->pszAmmo2 = NULL; // No secondary ammo
p->iMaxAmmo2 = -1;
p->iMaxClip = SNIPER_MAX_CLIP; // The clip size
p->iSlot = SNIPER_SLOT - 1; // The number in the HUD
p->iPosition = SNIPER_POSITION; // The position in a HUD slot
p->iFlags = ITEM_FLAG_NOAUTOSWITCHEMPTY | ITEM_FLAG_SELECTONEMPTY;
p->iId = m_iId = WEAPON_SNIPER; // The weapon id
p->iWeight = SNIPER_WEIGHT; // for autoswitching
return 1;
}
int CSniper::AddToPlayer( CBasePlayer *pPlayer )
{
if ( CBasePlayerWeapon::AddToPlayer( pPlayer ) )
{
MESSAGE_BEGIN( MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev );
WRITE_BYTE( m_iId );
MESSAGE_END();
return TRUE;
}
return FALSE;
}
BOOL CSniper::Deploy( )
{
return DefaultDeploy( SNIPER_MODEL_1STPERSON, SNIPER_MODEL_3RDPERSON, SNIPER_DEPLOY, "mp5" );
}
void CSniper::PrimaryAttack()
{
// This weapon is single shot when zoomed in, auto otherwise
if (!(m_pPlayer->m_afButtonPressed & IN_ATTACK) && InZoom())
return;
// don't fire underwater
if (m_pPlayer->pev->waterlevel == 3)
{
PlayEmptySound( );
m_flNextPrimaryAttack = 1.0;
return;
}
// don't fire if empty
if (m_iClip <= 0)
{
PlayEmptySound();
m_flNextPrimaryAttack = 1.0;
return;
}
// Weapon sound
m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
// one less round in the clip
m_iClip--;
// add a muzzle flash
m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH;
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
// fire off a round
Vector vecSrc(m_pPlayer->GetGunPosition());
Vector vecAim(m_pPlayer->GetAutoaimVector(AUTOAIM_2DEGREES));
// Accuracy of the weapon in degrees, zoomed in is way more accurate
Vector vecAcc(InZoom() ? VECTOR_CONE_1DEGREES : VECTOR_CONE_3DEGREES);
Vector vecDir(m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAim, vecAcc, 8192, BULLET_PLAYER_SNIPER, 0, 0, m_pPlayer->pev, m_pPlayer->random_seed ));
// Fire off the client side event
PLAYBACK_EVENT_FULL( FEV_NOTHOST, m_pPlayer->edict(), (m_InZoom ? m_event_z :m_event), 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, (m_iClip ? 0 : 1), 0 );
// Add a delay before the player can fire the next shot
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + SNIPER_FIRE_DELAY;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat(m_pPlayer->random_seed, SNIPER_FIRE_DELAY + 1, SNIPER_FIRE_DELAY + 2);
}
// Zoom in/out
void CSniper::SecondaryAttack( void )
{
if ( m_pPlayer->pev->fov != 0 )
{
m_pPlayer->pev->fov = m_pPlayer->m_iFOV = 0; // 0 means reset to default fov
}
else if ( m_pPlayer->pev->fov != 20 )
{
m_pPlayer->pev->fov = m_pPlayer->m_iFOV = 20;
}
pev->nextthink = UTIL_WeaponTimeBase() + 0.1;
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.5;
}
void CSniper::Reload( void )
{
DefaultReload( SNIPER_DEFAULT_AMMO, SNIPER_RELOAD, SNIPER_RELOAD_TIME );
}
void CSniper::WeaponIdle( void )
{
ResetEmptySound( );
m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase())
return;
SendWeaponAnim( SNIPER_IDLE_SIL );
m_flTimeWeaponIdle = UTIL_SharedRandomFloat(m_pPlayer->random_seed, 10, 15);
}
void CSniperAmmoClip::Spawn( void )
{
Precache( );
SET_MODEL(ENT(pev), "models/w_9mmARclip.mdl");
CBasePlayerAmmo::Spawn( );
}
void CSniperAmmoClip::Precache( void )
{
PRECACHE_MODEL ("models/w_9mmARclip.mdl");
PRECACHE_SOUND("items/9mmclip1.wav");
}
BOOL CSniperAmmoClip::AddAmmo( CBaseEntity *pOther )
{
int bResult = (pOther->GiveAmmo(SNIPER_DEFAULT_AMMO, "ammo_snipars",
SNIPER_MAX_AMMO) != -1);
if (bResult)
{
EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM);
}
return bResult;
}
snipars.h
#ifndef TOD_SNIPER_H
#define TOD_SNIPER_H
class CSniper : public CBasePlayerWeapon
{
public:
virtual void Spawn( void );
virtual void Precache( void );
virtual int iItemSlot( void ) { return SNIPER_SLOT; }
virtual int GetItemInfo(ItemInfo *p);
virtual int AddToPlayer( CBasePlayer *pPlayer );
virtual void PrimaryAttack( void );
virtual void SecondaryAttack( void ); // switch between scope and iron sights
virtual BOOL Deploy( void );
virtual void Reload( void );
virtual void WeaponIdle( void );
virtual BOOL UseDecrement( void ) { return TRUE; }
private:
int m_iShell;
BOOL InZoom() { return m_pPlayer->pev->fov != 0; }
BOOL m_InZoom() { return m_pPlayer->pev->fov != 0; }
unsigned short m_event;
unsigned short m_event_z;
};
class CSniperAmmoClip : public CBasePlayerAmmo
{
virtual void Spawn( void );
virtual void Precache( void );
virtual BOOL AddAmmo( CBaseEntity *pOther ) ;
};
#endif
sniper bullet simulation matrixes and the boxes of sdk code.
oh shoot, thats what I need to think about, your case, just add the ACT animation tables, should be good to go as, long as player/weapon viewmodel has the MP_HL2mp anims for it,.
:WEAPON_M16_H:
#ifndef WEAPON_M16_H
#define WEAPON_M16_H
#ifdef _WIN32
#pragma once
#endif
// #include "weapon_hl2mpbasehlmpcombatweapon.h"
#include "weapon_sdkbase.h"
#ifdef CLIENT_DLL
#include "iviewrender_beams.h"
#endif
#ifndef CLIENT_DLL
#include "Sprite.h"
#include "npcevent.h"
#include "beam_shared.h"
#endif
//modify this to alter the rate of fire
#define ROF 0.075f //RPS, 60 Sec / 800 Rounds = 0.075f
//The gun will fire up to this number of bullets while you hold the fire button.
//If you set it to 1 the gun will be semi auto. If you set it to 3 the gun will fire three round bursts
#define BURST 500
//PrecacheModel( PHYSCANNON_BEAM_SPRITE );
//-----------------------------------------------------------------------------
// CWeaponM16
//-----------------------------------------------------------------------------
#ifdef CLIENT_DLL
#define CWeaponM16 C_WeaponM16
#endif
class CWeaponM16 : public CWeaponSDKBase
{
public:
DECLARE_CLASS(CWeaponM16, CWeaponSDKBase);
CWeaponM16(void);
virtual SDKWeaponID GetWeaponID(void) const { return SDK_WEAPON_M16; }
DECLARE_NETWORKCLASS();
DECLARE_PREDICTABLE();
DECLARE_ACTTABLE();
void Precache(void);
void Spawn(void);
void ItemPostFrame(void);
void ItemPreFrame(void);
void ItemBusyFrame(void);
void PrimaryAttack(void);
void AddViewKick(void);
bool m_bPulsed;// == false
float m_flCreationTime;
//beam code from grenade_tripmine
Vector m_vecDir;
// end laser beam code
//new npc_sniper beam code
Vector GetBulletOrigin(void);
void GetPaintAim(const Vector &vecStart;, const Vector &vecGoal;, float flParameter, Vector *pProgress);
void PaintTarget(const Vector &vecTarget;, float flPaintTime);
Vector m_vecPaintCursor;
// virtual void Simulate( void );
CBeam *m_pBeam;
#if defined( CLIENT_DLL )
//#ifdef CLIENT_DLL
virtual void OnDataChanged(DataUpdateType_t updateType);
virtual const char *GetTrailParticleName(void);
// virtual int DrawModel( int flags );
virtual void Simulate(void);
//#else
#else
void FireNPCPrimaryAttack(CBaseCombatCharacter *pOperator, bool bUseWeaponAngles);
void FireNPCSecondaryAttack(CBaseCombatCharacter *pOperator, bool bUseWeaponAngles);
void Operator_ForceNPCFire(CBaseCombatCharacter *pOperator, bool bSecondary);
void Operator_HandleAnimEvent(animevent_t *pEvent, CBaseCombatCharacter *pOperator);
CEnvLaser *pLaserEnv;
// CInfoTarget *pLaserTarget;
// CBaseEntity *pSemaphore = CreateEntityByName( "info_target" );
// pSemaphore->SetName( MAKE_STRING(COMMENTARY_SPAWNED_SEMAPHORE) );
//beam code from grenade_tripmine
void MakeBeam(void);
void KillBeam(void);
void BeamBreakThink(void);
private:
float m_flBeamLength;
Vector m_vecEnd;
EHANDLE m_hOwner;
// end laser beam code
Vector vecTmpEnd;
#endif
public:
void DryFire(void);
void GetStance(void);
bool Holster(CBaseCombatWeapon *pSwitchingTo = NULL); // Required so that you un-zoom when switching weapons
Activity GetPrimaryAttackActivity(void);
virtual bool Reload(void);
int GetMinBurst() { return 2; }
int GetMaxBurst() { return 5; }
float GetFireRate(void) { return ROF; }
enum stances
{
E_STAND = 0,
E_DUCK = 1,
E_MOVE = 2,
E_RUN = 3,
E_INJURED = 4,
E_JUMP = 5,
E_DYING = 6,
};
//modify this part to control the general accuracy of the gun
Vector cone;
virtual const Vector& GetBulletSpread(void)
{ c
// if you don't need stance and health dependent accuracy, you can just remove this.
if (m_iStance == E_DUCK)
{ c
}
if (m_iStance == E_STAND)
{ c
}
if (m_iStance == E_MOVE)
{ c
}
if (m_iStance == E_RUN)
{ c
}
if (m_iStance == E_INJURED)
{ c
}
if (m_iStance == E_JUMP)
{ c
}
if (m_iStance == E_DYING)
{ c
}
//This part simlates recoil. Each successive shot will have increased spread.
if (m_iBurst != BURST)
{
for (int i = m_iBurst; i < BURST; i++)
{
cone += VECTOR_CONE_1DEGREES;
}
}
//This part is the zoom modifier. If in zoom, lower the bullet spread.
if (m_bInZoom)
{
cone -= VECTOR_CONE_1DEGREES;
}
return cone;
}
void ToggleZoom(void);
void CheckZoomToggle(void);
//void CWeaponM16::DrawBeam( const Vector &startPos;, const Vector &endPos;, float width )
void DrawBeam(const Vector &startPos;, const Vector &endPos;, float width);
CBeam *pBeam;
//CSpriteTrail *CSpriteTrail::SpriteTrailCreate( const char *pSpriteName, const Vector &origin;, bool animate )
CSpriteTrail *pLaserSpriteTrailBeam;
// DECLARE_ACTTABLE();
private:
CNetworkVar(int, m_iBurst);
CNetworkVar(bool, m_bInZoom);
CNetworkVar(float, m_flAttackEnds);
CNetworkVar(int, m_iStance);
private:
CWeaponM16(const CWeaponM16 &);
};
#endif // WEAPON_M16_H
Thank you very much for answering :) and it is not to despise your great help but that code does not seem to be from goldsource, it looks more like source code
Hi i dont speak english but i wanted to ask you how the project is going?