Results 1 to 6 of 6

Threaded View

  1. #1
    supercarz1991's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    6,285
    Reputation
    435
    Thanks
    3,715
    My Mood
    Doh

    Some stuff with ammo...

    this is only to help the section and to help you guys better understand how this game engine works. This has lots of explanations in it about all sorts of info on ammo and what it does

    Code:
    void CClientWeapon::ChangeAmmoWithReload( uint8 nNewAmmoId, bool bForce /*=false*/ )
    {
    	// Update the player's stats...
    	if ( ( W_RELOADING == GetState() ) && !bForce )
    	{
    		return;
    	}
    
    	if ( CanChangeToAmmo( nNewAmmoId ) && ( nNewAmmoId != m_nAmmoId ) )
    	{
    		ASSERT( 0 != g_pWeaponMgr );
    		m_nAmmoId   = nNewAmmoId;
    		m_pAmmo     = g_pWeaponMgr->GetAmmo( m_nAmmoId );
    
    		// Make sure we reset the anis (the ammo may override the 
    		// weapon animations)...
    		InitAnimations( true );
    
    		if ( m_pAmmo->pAniOverrides )
    		{
    			// If we're not using the defaults play the new select ani...
    			Select();
    		}
    		else
    		{
    			// Do normal reload...
    			ReloadClip( true, -1, true, true );
    
    			// Add a message so the user knows he switched ammo (sometimes it
    			// isn't that obvious)...
    
    			if (strlen(m_pAmmo->szShortName))
    			{
    				char szMsg[128];
    				FormatString(IDS_CHANGING_AMMO, szMsg, sizeof(szMsg), m_pAmmo->szShortName);
    				std::string icon = m_pAmmo->GetNormalIcon();
    				g_pPickupMsgs->AddMessage(szMsg, icon.c_str());
    			}
    		}
    	}
    }
    
    
    // ----------------------------------------------------------------------- //
    //
    //	ROUTINE:	CClientWeapon::ChangeAmmoImmediate()
    //
    //	PURPOSE:	Change to the specified ammo type
    //
    // ----------------------------------------------------------------------- //
    
    void CClientWeapon::ChangeAmmoImmediate( uint8 nNewAmmoId, int nAmmoAmount /*=-1*/, bool bForce /*=false*/ )
    {
    	// Update the player's stats...
    	if ( ( W_RELOADING == GetState() ) && !bForce )
    	{
    		return;
    	}
    
    	if ( CanChangeToAmmo( nNewAmmoId ) && ( nNewAmmoId != m_nAmmoId ) )
    	{
    		ASSERT( 0 != g_pWeaponMgr );
    		m_nAmmoId   = nNewAmmoId;
    		m_pAmmo     = g_pWeaponMgr->GetAmmo( m_nAmmoId );
    
    		// Make sure we reset the anis (the ammo may override the 
    		// weapon animations)...
    		InitAnimations( true );
    
    		if ( m_pAmmo->pAniOverrides )
    		{
    			// If we're not using the defaults play the new select ani...
    			Select();
    		}
    		else
    		{
    			// Do normal reload...
    			ReloadClip( false, nAmmoAmount /*-1*/, true, true );
    		}
    		}
    	else
    	{
    		// Update the hud to reflect the new ammo amount...
    		g_pPlayerStats->UpdateAmmo( m_nWeaponId, m_nAmmoId, nAmmoAmount );
    		g_pPlayerStats->UpdatePlayerWeapon( m_nWeaponId, m_nAmmoId );
    	}
    }
    
    
    // ----------------------------------------------------------------------- //
    //
    //	ROUTINE:	CWeapon::ReloadClip
    //
    //	PURPOSE:	Fill the clip
    //
    // ----------------------------------------------------------------------- //
    
    void CClientWeapon::ReloadClip( bool bPlayReload /*=true*/,
                                    int nNewAmmo /*=-1*/,
                                    bool bForce /*=false*/,
    								bool bNotifyServer /*=false*/)
    {
    	// Can't reload clip while deselecting the weapon...
    
    	if ( W_DESELECT == GetState() ) return;
    
    	// get all the ammo the player possesses
    	int nAmmoCount = g_pPlayerStats->GetAmmoCount( m_nAmmoId );
    
    	// Get an intermediate amount of ammo.  If the nNewAmmo has
    	// been specified, use that value.  Otherwise use the total
    	// amount of ammo on the player.
    	int nAmmo = nNewAmmo >= 0 ? nNewAmmo : nAmmoCount;
    
    	// Get how many shots are in a clip.
    	int nShotsPerClip = m_pWeapon->nShotsPerClip;
    
    	// Update the player's stats...
    	// note: the ammo amount we pass may be too much but
    	// these functions figure out what the max really is,
    	// and then we do the same thing later
    
    	// UpdateAmmo does a lot of stuff, one of those is passing in
    	// how much ammo you have.  If you specify an amount that is
    	// more or less, it will consider this the new amount of
    	// ammo that you have on you and adjust things accordingly.
    	g_pPlayerStats->UpdateAmmo( m_nWeaponId, m_nAmmoId, nAmmo );
    
    
    	// This will set the player stats to the specified weapon and 
    	// ammo id.  In this case, use the current ones.
    	g_pPlayerStats->UpdatePlayerWeapon( m_nWeaponId, m_nAmmoId );
    
    	// Make sure we can reload the clip...
    	if ( !bForce )
    	{
    		// Already reloading...
    		if ( m_hObject && ( W_RELOADING == GetState() ) )
    		{
    			return;
    		}
    
    		// Clip is full...
    		if ( ( m_nAmmoInClip == nShotsPerClip ) || ( m_nAmmoInClip == nAmmoCount ) )
    		{
    			return;
    		}
    	}
    
    	if ( ( nAmmo > 0 ) && ( nShotsPerClip > 0 ) )
    	{
    		// The amount of ammo we give the player due
    		// of the reload is tracked with m_nNewAmmoInClip.
    		// Set the new ammo to the lesser vaule of
    		// either the max clip size of the amount of ammo
    		// on the player.
    		if ( nAmmo < nShotsPerClip )
    		{
    			m_nNewAmmoInClip = nAmmo;
    		}
    		else
    		{
    			m_nNewAmmoInClip = nShotsPerClip;
    		}
    		
    		if( bNotifyServer )
    		{
    			// Let the server know we are reloading the clip...
    
    			CAutoMessage cMsg;
    			cMsg.Writeuint8( MID_WEAPON_RELOAD );
    			cMsg.Writeuint8( m_nAmmoId ); // We maybe switching ammo
    			g_pLTClient->SendToServer( cMsg.Read(), MESSAGE_GUARANTEED );
    		}
    		
    
    		// check for a valid reload animation
    		if ( bPlayReload && ( INVALID_ANI != GetReloadAni() ) )
    		{
    			// setting the state will "queue" the animation to
    			// start playing on the next update
    			SetState( W_RELOADING );
    			return;
    		}
    		else
    		{
    			// there is no reload animation, so just put
    			// the right amount in the clip directly
    			m_nAmmoInClip = m_nNewAmmoInClip;
    		}
    	}
    }
    
    
    // ----------------------------------------------------------------------- //
    //
    //	ROUTINE:	CClientWeapon::DecrementAmmo
    //
    //	PURPOSE:	Decrement the weapon's ammo count
    //
    // ----------------------------------------------------------------------- //
    
    void CClientWeapon::DecrementAmmo()
    {
    	// Hide the necessary pieces...
    	SpecialShowPieces(false);
    
    	int nAmmo;
    	bool bInfiniteAmmo = ( g_bInfiniteAmmo || ( !!( m_pWeapon->bInfiniteAmmo ) ) );
    	if ( bInfiniteAmmo )
    	{
    		nAmmo = INFINITE_AMMO_AMOUNT;
    	}
    	else
    	{
    		nAmmo = g_pPlayerStats->GetAmmoCount( m_nAmmoId );
    	}
    
    	int nShotsPerClip = m_pWeapon->nShotsPerClip;
    
    	if ( 0 < m_nAmmoInClip )
    	{
    		if ( 0 < nShotsPerClip )
    		{
    			// decrease the ammo in the clip only if the clip
    			// is non-zero
    			--m_nAmmoInClip;
    		}
    
    		if ( !bInfiniteAmmo )
    		{
    			// we are not using infinite ammo, update the current amount
    			--nAmmo;
    
    			// Update our stats.  This will ensure that our stats are always
    			// accurate (even in multiplayer)...
    			g_pPlayerStats->UpdateAmmo( m_nWeaponId, m_nAmmoId, nAmmo, LTFALSE, LTFALSE );
    		}
    	}
    
    	// Check to see if we need to reload...
    	if ( 0 < nShotsPerClip )
    	{
    		if ( 0 >= m_nAmmoInClip )
    		{
    			ReloadClip( true, nAmmo );
    		}
    	}
    }

    This is from the NOLF2 source, yes i know you can't just throw it in CA and it works... but maybe it will help some one here out. I've found lots of weird features this way before just by taking bits n pieces and throwing em in a CA hack

    commando: You're probably the best non-coder coder I know LOL


  2. The Following 2 Users Say Thank You to supercarz1991 For This Useful Post:

    p2ssword (01-04-2013),pDevice (01-04-2013)

Similar Threads

  1. me messing around with some stuff
    By -ParallaX in forum Showroom
    Replies: 2
    Last Post: 08-04-2009, 05:29 PM
  2. need some help with domains.
    By fastbullet in forum WarRock - International Hacks
    Replies: 1
    Last Post: 04-26-2007, 08:44 AM
  3. this is how i solve stuff with my teachers
    By EleMentX in forum Spammers Corner
    Replies: 3
    Last Post: 12-09-2006, 04:20 PM
  4. need some help with client exe.
    By barney in forum Hack Requests
    Replies: 2
    Last Post: 11-03-2006, 10:05 PM
  5. Need help with ammo hack
    By AthlaS in forum WarRock - International Hacks
    Replies: 4
    Last Post: 01-19-2006, 01:50 PM