• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Code Mutator - CheckReplacement Functionality

Toilet Duckie

Active member
May 18, 2009
25
1
I know this was posted in another thread, but I'm hoping to call more attention to the issue and simultaneously avoid derailing the other thread further.

Brief summary of the issue: I've tried, and failed, to replace the 9MM hand gun a player spawns with using a mutator and the CheckReplacement function. I believe the problem isn't CheckReplacement so much as it is the ReplaceWith function it calls. I know this because I can alter the true/false return in CheckReplacement and see that it's executing the ReplaceWith function call, meaning that it sees the weapon and is attempting to replace it.

I'm hoping someone out there (experienced modder, dev, etc.) can explain CheckReplacement \ ReplaceWith's proper usage and functionality to me.

Longer explanation:

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.

Results: return false is definitely a "jobs done!" switch. The problem is in ReplaceWith, not CheckReplacement. I know this because a 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.

I've tried replacing KF stock weapons with other stock weapons, my weapons with my weapons, and a mixture of the two. Nothing seems to get past ReplaceWith. I can't see anything in ReplaceWith that would cause this problem, either.
 
Last edited:
had the same prob long ago, only replaces wep if u toss it. this 1 works tho, just remem to add the knife/syringe/welder if u want

Code:
function bool CheckReplacement( Actor Other, out byte bSuperRelevant )
 {
  if (Other.isA('xPawn'))
    {

     xPawn(Other).RequiredEquipment[0] = "MutBullpup.NewBullpup";
     xPawn(Other).RequiredEquipment[1] = "NONE";
     xPawn(Other).RequiredEquipment[2] = "NONE";
     xPawn(Other).RequiredEquipment[3] = "NONE";
     xPawn(Other).RequiredEquipment[4] = "NONE";
     xPawn(Other).RequiredEquipment[5] = "NONE";
}
 
Upvote 0
Tossing the weapon seems like an odd requirement. I would assume that the replacement would occur as soon as the game initiates, especially if you replace the pickup and the weapon itself (leaving no way for the weapon to make it into the game without being "checked").

Still, your way should work. I'm not sure about players always spawning with a given weapon or if doing things this way will allow them to even toss the weapon on the ground/sell it, though. Guess I'll tinker with it a bit later.
 
Upvote 0