View Single Post
thacursedpie
Member
Join Date: May 2008
Old 06-20-2009 , 14:16   Re: [TF2] Changing ammo in clip
Reply With Quote #4

@Petsin.
Well, my debug-screen is literally filled with tag mismatches. (even before I added this into my plugin). So I didn't notice the new ones .

I'm still new to SourcePawn (and programming in general)

@Petsin & paegus
Will try out your suggestions now.

Thanks!

EDIT:
Paegus' suggestion isn't working. Testing Petsin's now.
Ok, found the problem!

You already saw the piece of code that didn't work. But this one does:
Code:
//Top of code:
new Handle:ammoOffset;
new Handle:clipOffset;

//OnPluginStart:
ammoOffset = FindSendPropInfo("CTFPlayer", "m_iAmmo");
clipOffset = FindSendPropInfo("CTFWeaponBase", "m_iClip1");

//Setting the reserve ammo to 0: (working)
for (new n = 1; n < 4; n++)
{
     if (IsValidEdict(n)) {
            SetEntData(i, ammoOffset + (n * 4), 0);
            PrintToConsole(i, "[HNS]- Setting secondary ammo to 0!")
            PrintToServer("[HNS]- Setting secondary ammo to 0!");
                        
        new iWeapon = GetEntDataEnt2(i, FindSendPropInfo("CTFPlayer", "m_hActiveWeapon"));
        //IsValidEntity(iWeapon);
         while (!IsValidEntity(iWeapon)) {
          iWeapon = GetEntDataEnt2(i, FindSendPropInfo("CTFPlayer", "m_hActiveWeapon"));
          }
          PrintToConsole(i, "[HNS]- Setting primary ammo to 0!");
          PrintToServer("[HNS]- Setting primary ammo to 0!");
          SetEntProp(iWeapon, Prop_Send, "m_iClip1", 1);
     }
}
I started with adding the IsValidEntity(iWeapon) loop. It surprised me that it didn't crash the server. Then I added in the Prints and well, my guess is this was the issue:

Code:
//Snip

for (new n = 0; n < 3; n++)
{
 //blah blah
}

Last edited by thacursedpie; 06-20-2009 at 15:49.
thacursedpie is offline