Request Help With Debugging Reloading Magazine System

I don't know how much 'debugging' it will need, in fact the whole thing may need be rewritten, although I would hope my coding abilities wouldn't be that lax.
The concept was when a player goes to a large, or deployable, inventory station that they would receive a certain number of clips(according to the armor they purchase). When they fire, it checks if they have fired an ammo based weapon and if you have any magazines left it would then add your max amount of ammo for that weapon(basically reload it to full) and minus a magazine.
Code...
Projectiles.cs
$Clip[0] = PlasmaClip;
$Clip[1] = ChaingunClip;
$Clip[2] = DiscClip;
$Clip[3] = GrenadeLauncherClip;
$Clip[4] = MortarClip;
$Clip[5] = MissileLauncherClip;
$Clip[6] = MMinigunClip;
$numClips = 7;
ShapeBaseImageData
   if(%data.usesEnergy)
   {
      if(%data.useMountEnergy)
      {
         %useEnergyObj = %obj.getObjectMount();
         if(!%useEnergyObj)
            %useEnergyObj = %obj;
         %energy = %useEnergyObj.getEnergyLevel();
         %vehicle = %useEnergyObj;
      }
      else
         %energy = %obj.getEnergyLevel();
      
      if(%data.useCapacitor && %data.usesEnergy)
      {   
         if( %useEnergyObj.turretObject.getCapacitorLevel() < %data.minEnergy )
         {   
            return;
         }
      }
      else if(%energy < %data.minEnergy)
         return;
   }
   ////////////////////////////////////////////Began Editing
   else if(%data.ammo == 0)
   {
        for(%c = 0; %c < $numClips; %c++)
        {
            %clip = $Clip[%c];
            if(%obj.getInventory(%clip) != 0)
            {
               reloadweapon(%obj, %data);
               %clip--;
            }
            else
            {

            }
        }
   }
   ////////////////////////////////////////ended//Used top to show location
New Function Created Directly Below ShapeBaseImageData
///////////////////////////
function reloadweapon(%obj, %data)
{
      %obj.setInventory(%data.ammo, %obj.getDataBlock().max[%data.ammo]);
}
///////////////////////////
Inventoryhud.cs>buyFavorites(%client);>At End Of Function
////////////////////
      %cpclip = %client.player;
   if(%curArmor $= "light")
   {
      %cpclip.PlasmaClip = 2;
      %cpclip.ChaingunClip = 3;
      %cpclip.DiscClip = 2;
      %cpclip.GrenadeLauncherClip = 2;
//      %client.player.MortarClip = 2;
//      %client.player.MissileLauncherClip = 2;
//      %client.player.MMinigunClip = 2;
   }
   else if(%curArmor $= "medium")
   {
      %cpclip.PlasmaClip = 3;
      %cpclip.ChaingunClip = 4;
      %cpclip.DiscClip = 2;
      %cpclip.GrenadeLauncherClip = 3;
//      %client.player.MortarClip = 2;
      %cpclip.MissileLauncherClip = 2;
//      %client.player.MMinigunClip = 2;
   }
   else if(%curArmor $= "heavy")
   {
      %cpclip.PlasmaClip = 4;
      %cpclip.ChaingunClip = 4;
      %cpclip.DiscClip = 3;
      %cpclip.GrenadeLauncherClip = 2;
      %cpclip.MortarClip = 1;
      %cpclip.MissileLauncherClip = 3;
      %cpclip.MMinigunClip = 2;
   }
////////////////////////
Inventoryhud.cs>buyDeployableFavorites(%client)>End Of Function
   ////////////////////
      %curArmor = %client.player.getDatablock();
      %cpclip = %client.player;
   if(%curArmor $= "light")
   {
      %cpclip.PlasmaClip = 1;
      %cpclip.ChaingunClip = 2;
      %cpclip.DiscClip = 1;
      %cpclip.GrenadeLauncherClip = 1;
//      %cpclip.MortarClip = 2;
//      %cpclip.MissileLauncherClip = 2;
//      %cpclip.MMinigunClip = 2;
   }
   if(%curArmor $= "medium")
   {
      %cpclip.PlasmaClip = 2;
      %cpclip.ChaingunClip = 2;
      %cpclip.DiscClip = 1;
      %cpclip.GrenadeLauncherClip = 2;
//      %client.player.MortarClip = 2;
      %cpclip.MissileLauncherClip = 1;
//      %client.player.MMinigunClip = 2;
   }
   if(%curArmor $= "heavy")
   {
      %cpclip.PlasmaClip = 2;
      %cpclip.ChaingunClip = 2;
      %cpclip.DiscClip = 2;
      %cpclip.GrenadeLauncherClip = 1;
      %cpclip.MortarClip = 1;
      %cpclip.MissileLauncherClip = 2;
      %cpclip.MMinigunClip = 1;
   }
////////////////////////Basically the same :P

Please don't judge me for my lack of experience, I'm just here to learn(actually, mostly to actually get this working, learning how to do it and like things is a bonus :D). No syntax errors found for either files, nothing has changed in the game basically, firing is the same, invs, everything I can think of. Again, it may be all wrong or just part, help would be appreciated, thanks to all in advance.

Comments

  • what functions were each of these in? You did not mention them for some of your code.
  • Each bold term is where the code below it is, so the first is at the top of projectiles.cs, second is in ShapeBaseImageData::onFire, guess I forgot the onFire, its below the check for if it uses energy(in segment of code). Third is directly below onFire, the fourth and fifth are both at the very end of buyFavorites and buyDeployableFavorites respectively.
  • The word clip makes me cringe.
  • I can kind of see an error. where is the relation between %CPClip and $Clip?
  • $Clip[%c] indicates which clip you are using, such as PlasmaClip, and %CPClip = %client.player. Again, I haven't a real clue as in how to fix this.
  • else if(%data.ammo == 0)
    
    %data (the datablock) does not store current ammo, you'd instead need to do something like
    %ammo = %obj.getInventory(x);
    
    where x = ammo name

    This is what I saw first glance, I haven't checked anything else but that might be the majority of your problem.
Sign In or Register to comment.