Things are getting stranger and stranger.
I remembered seeing a "SAS Throwing Knives" mod in the General section, so I grabbed it to see how that person got things working. They did so through ModifyPlayer(), simply gifting the player the new weapon when they spawn.
I tried adding this code to my mutator code. Surprisingly, it failed to work. Needless to say, I was pissed. So, in the spirit of troubleshooting, I've been going step-by-step and working towards my original intent. Here's what I've discovered:
1) ModifyPlayer works. If I completely toss out all of the CheckRelevance and InventoryOverride code and only try to give the player my gun, it works. Peachy. You can even give two guns at once, or a KF official weapon and my own. Works perfectly for what it is.
2) CheckReplacement appears to be "trying" to work but fails to do so and, in the process, completely invalidates the mutator. I've learned this by adding a small CheckReplacement back into my code, as follows:
Code:
function bool CheckReplacement(Actor Other, out byte bSuperRelevant )
{
if( Weapon(Other) != None )
{
if (string(Other.Class) ~= "TDMods.BOOMPistol")
{
ReplaceWith(Other, "KFMod.Chainsaw");
return false;
}
}
return true;
}
The most important line here is "return false". Since I know for certain that the player is being given the BOOMPistol (through ModifyPlayer), it stands to reason that CheckReplacement should function. But wait! If I have return false in the code, my character spawns with stock equipment. If I comment it out, i.e. allowing the return true to occur, my character will spawn with the BOOMPistol as if CheckReplacement never ran.
It's quite perplexing. I can only thing of two things that could be happening. Either A)return false is the "jobs done!" state and ReplaceWith is somehow failing to replace the BOOMPistol, hence removing it entirely from my inventory and leaving me with what appears to be absolutely stock weaponry, or B)return true is "jobs done!" and ReplaceWith just isn't doing its job.
I'm going to test A) right now by giving the player another weapon that CheckReplacement doesn't touch at all. Results momentarily.
Results: return false is definitely a "jobs done!" switch. The problem is in ReplaceWith, not CheckReplacement. I know this because the Machete I gave myself in ModifyPlayer remained in my inventory while the BOOMPistol simply vanished. So, the mutator code is absolutely correct but ReplaceWith isn't replacing the weapon as intended. Hmph.