• 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 Buy modified weapon

Kaini

Member
Jun 21, 2009
16
0
I have modified the FlameThrower class by subclassing (FlameThrowerMZ).
But I am not able to buy the modified version at the trader. When I try to buy it, I can hear the "buy sound" but no money is spent and no FlameThrower is in my inventory.

Here is my CheckReplacement:
Code:
function bool CheckReplacement(Actor Other, out byte bSuperRelevant)
{
    bSuperRelevant = 0;

    if (Other.Class == Class'FlameThrower')
    {
        ReplaceWith(Other, String(Class'FlameThrowerMZ'));
        return false;
    }
    return true;
}
If I add a Log call in the if I can see it in the KillingFloor.log when I buy the weapon.
Code:
class FlameThrowerMZ extends FlameThrower;

exec function ReloadMeNow()
{
    // ...
}

defaultproperties
{
}
What am I doing wrong?
Thanks.:)
 
Thank you very much! Now I am able to buy the new weapon. (I did not change the KFLevelRules in the Map, but changed the ItemForSale array in the CheckReplacement method)
Code:
KFLevelRules(Other).ItemForSale[i] = ...;
But there is another issue: All ammo (for all weapons) cost 0. Does anyone know why?
 
Upvote 0
Thank you very much! Now I am able to buy the new weapon. (I did not change the KFLevelRules in the Map, but changed the ItemForSale array in the CheckReplacement method)
Code:
KFLevelRules(Other).ItemForSale[i] = ...;
But there is another issue: All ammo (for all weapons) cost 0. Does anyone know why?

Its a minor issue, just click the ammo fill button beside a weapon instead of all ammo.
 
Upvote 0
Sorry if I didn't describe the problem exactly enough.
I didn't mean the "All Ammo"-Button but all "Ammo Buttons". I have attached a screenshot to clarify the problem.

I am not able to buy a Combat Armor, but I am able to fill the ammo of my weapons (including the 9mm and grenades) for free.
 

Attachments

  • bug__in_my_mutator.jpg
    bug__in_my_mutator.jpg
    79.6 KB · Views: 0
Upvote 0
Code:
KFLevelRules(Other).ItemForSale[i] = ...;

What was the exact line you used that worked? I've fooled around with this a while and I can tell via log messages that the weapon I'm trying to replace is being replaced...

Code:
ScriptLog: Replacing...
ScriptLog: KFmod.LAWPickup
ScriptLog: SuperLAWMut.SuperLAWPickup
...but I'm then getting this message in my log...

Code:
KFBuyMenuInvList Package.KFBuyMenuInvList (Function KFGUI.KFBuyMenuInvList.UpdateMyBuyables:029E) Accessed None 'KFLR'

...and the trader has nothing for sale.

Here's how I'm trying to do this; what am I doing wrong here?
Code:
function bool CheckReplacement( Actor Other, out byte bSuperRelevant )
{
    bSuperRelevant = 0;

        if ( KFLevelRules(Other) != None )
    {
                Log ("Replacing...");
        Log (string(KFLevelRules(Other).ItemForSale[3]));
        KFLevelRules(Other).ItemForSale[3]=Class'SuperLAWMut.SuperLAWPickup';
        Log (string(KFLevelRules(Other).ItemForSale[3]));
        return false;
    }

    return true;
}
 
Last edited:
Upvote 0
The everything costing 0 money bug, right?

Augh! Saving a map with modified LevelInfo has gotten my custom pickups into the trader shop (and everything costs money like it should), but friends joining the server can't see the customized trader list- only I can. Sidenote: they have all the same relevant files that I have; my mutator's .u/.ucl files, the .rom map file, and the .int map file.

To clarify: they see the normal trader list (no custom stuff), while I see my modified trader list. :confused:

Also...what type are you declaring your To array as?

Update----------

I found a...way to kinda make this work. A little gimpy since I haven't yet figured out how to get the **** trader to just show me my custom items in her list.

in CheckReplacement, replace only the Pickup classes of the weapons you intend to replace, for example...
Code:
    if ( Other.Class == Class'KFMod.ChainsawPickup' )
    {
        ReplaceWith( Other, "UltraMut.uChainsawPickup" );
        return false;
    }
The trader will show the usual list (sadly), but as soon as a weapon that has a custom replacement is dropped, it'll be replaced by the custom pickup, and hence the customized item will get into the players inventory.

This is not ideal: it flat out sucks, in fact, but it does seem to work on any map. The only upside is that it doesn't screw up the trader prices. I haven't tried this with a friend joining...hopefully it works for them too.

Unrelated question: what does setting bSuperRelevant to 0, for example, inside CheckReplacement, actually do?
 
Last edited:
Upvote 0
The everything costing 0 money bug, right?
Right.
Also...what type are you declaring your To array as?
It is a Class-Array because I save some other things there too. That's why I have to cast it to a Class<Pickup>. (Ugly but "works")
in CheckReplacement, replace only the Pickup classes of the weapons you intend to replace, for example...
I'll try that out today. (10am here :p)
Unrelated question: what does setting bSuperRelevant to 0, for example, inside CheckReplacement, actually do?
I have no idea. I think it has something to do with the replace priority if more than one mutator is active.
 
Upvote 0
So, I think I figured something out at least.

Code:
ScriptLog: ########## KFLevelRules: [KF-WestLondon.KFLevelRules0]
ScriptLog: @@@@@@@@@@ Replacing: [KFmod.MP7MPickup] With: [UltraMut.uMP7MPickup]
ScriptLog: ^^^^^^^^^^ ItemForSale[0] is now: [UltraMut.uMP7MPickup]
.
. (stuff omitted here for brevity, just more of the above 2 lines)
.
ScriptLog: ########## KFLevelRules AFTER Setting: [KF-WestLondon.KFLevelRules0]
I am getting the right KFLevelRules object before and after setting the info I want, and the info gets assigned correctly.

However, later on in the logs...
Code:
ScriptLog: START MATCH
Warning: KFGameType KF-WestLondon.KFGameType (Function KFmod.KFGameType.MatchInProgress.CalcNextSquadSpawnTime:0029) Accessed None 'KFLRules'
.
.
.
Warning: KFBuyMenuInvList Package.KFBuyMenuInvList (Function KFGUI.KFBuyMenuInvList.UpdateMyBuyables:029E) Accessed None 'KFLR'
...AHA! So, somehow, KFLR ends up pointing off into nothingness, whereas before it is pointing at [KF-WestLondon.KFLevelRules0]. It's fine, then I change the ItemForSaleArray, then KFLR breaks for some reason.

I'm going to fiddle around some more.

Additional:

VICTORY! I AM AWESOME!
*ahem*...please excuse me for that- it's been a very long night...

I get my customized item list in the trader window, and everything costs the proper amount of dosh. Here's how it works- I 99% guarantee you'll feel like a tool after you see it, and I feel pretty SMERT for not figuring this out sooner.

Here's the first chunk out of my mutator file that handles customizing the trader list:
Code:
function bool CheckReplacement( Actor Other, out byte bSuperRelevant )
{
    bSuperRelevant = 0;

    if ( Other == None )
        return true;

    if ( KFLevelRules(Other) != None )
    {
        Log ( "########## KFLevelRules: [" $ String(KFLevelRules(Other)) $ "]");
        for ( i=0; i < 24; i++)
        {
            Log ( "@@@@@@@@@@ Replacing: [" $ String(KFLevelRules(Other).ItemForSale[i]) $ "] With: [" $ String(replacements[i]) $ "]" );
            KFLevelRules(Other).ItemForSale[i] = replacements[i];
            Log ( "^^^^^^^^^^ ItemForSale[" $ String(i) $ "] is now: [" $ String(KFLevelRules(Other).ItemForSale[i]) $ "]" );
        }
        Log ( "########## KFLevelRules AFTER Setting: [" $ String(KFLevelRules(Other)) $ "]");
        [U][B]return true[/B][/U];
    }
The reason this is now working, whereas before it was not, is bold/underlined in the above code-block. I had "return false;" there, but that is incorrect- because the mutator is NOT replacing one thing with another thing (in rough terms, I still don't completely understand it); this chunk of code is modifying an existing object: a subtle, but very important difference (apparently).

For anyone that is interested, I'm attaching the current entire code of the mutator file. There's still things it does not do:


  • Account for players spawning with weapons because of Perks (oh PerkReplacementMod, you're the bomb) and replace that default equipment with the customized stuff.
  • I tested this all by my lonesome by launching a listen server. No idea if it works for a different machine/player joining the game. I will find out...I pray it does.
  • Sadly, Perk price discounts are not being applied even though my customized items are extending the classes that do get discounts. That one's going to be tricky...
  • Another thing that strikes me as somewhat unfortunate is that the NUMBER of items available for sale (AKA: size of the ItemForSale array) is probably not available for me to alter from within a mutator, so I'm stuck with that number of slots available to put things in.
  • Lastly, grenades. They aren't showing up in the trader and I have no idea how to replace the stock ones with my custom ones. That doesn't work either, currently.

I need to figure out how to know if a weapon is being carried around by a player-controlled pawn, and get access to that pawn object's inventory so that I can use the inventory functions to replace the old equipment with my custom equipment- and I need to do all this from within CheckReplacement inside my Mutator :eek:
 
Last edited:
Upvote 0
I have played around a bit, but I am not able to get it working. In the log files I have lots of these:
Warning: KFTab_BuyMenu Package.KFTab_BuyMenu (Function KFGUI.KFTab_BuyMenu.ShowPanel:0090) Accessed None 'MyBuyables'
Error: KFBuyMenuInvList Package.KFBuyMenuInvList (Function KFGUI.KFBuyMenuInvList.UpdateMyBuyables:0810) Accessed null class context 'ClientVeteranSkill'
Error: KFHumanPawn KF-WestLondon.KFHumanPawn (Function KFmod.KFPawn.ServerBuyAmmo:0200) Accessed null class context 'ClientVeteranSkill'
Weapons cost as normal, but Ammo is for free. There is my code:
Code:
    // replacing in trader
    if (Other.isA('KFLevelRules'))
    {
        Log("XXXX: KFLevelRules: [[" $ String(KFLevelRules(Other)) $ "]]");
        for (i = 0; i < KFLevelRules(Other).MAX_BUYITEMS; ++i)
        {
            for (j = 0; j < MAX_REPLACE; ++j)
            {
                if (KFLevelRules(Other).ItemForSale[i] == From[j])
                {
                    Log("XXXX: Replacing [[" $ String(KFLevelRules(Other).ItemForSale[i]) $
                         "]] which matched [[" $ String(From[j]) $
                         "]] with [[" $ String(Class<Pickup>(To[j])) $ "]]");
                    KFLevelRules(Other).ItemForSale[i] = Class<Pickup>(To[j]);
                    Log("XXXX: It is now [[" $ String(KFLevelRules(Other).ItemForSale[i]) $ "]]");
                }
            }
        }
        Log("XXXX: KFLevelRules: [[" $ String(KFLevelRules(Other)) $ "]]");
        return true;
    }


Account for players spawning with weapons because of Perks (oh PerkReplacementMod, you're the bomb) and replace that default equipment with the customized stuff.
I use this code, which works... at least seams to work
Code:
    if (Other.isA('xPawn'))
    {
        Log("XXXX: xPawn: [[" $ String(xPawn(Other)) $ "]]");
        for (i = 0; i < MAX_REQUIRED_EQUIPMENT; ++i)
        {
            for (j = 0; j < MAX_REPLACE; ++j)
            {
                if (xPawn(Other).RequiredEquipment[i] ~= String(From[j]))
                {
                    Log("XXXX: Replacing [[" $ xPawn(Other).RequiredEquipment[i] $
                        "]] which matched [[" $ String(From[j]) $
                        "]] with [[" $ String(To[j]) $ "]]");
                    xPawn(Other).RequiredEquipment[i] = String(To[j]);
                    Log("XXXX: It is now [[" $ xPawn(Other).RequiredEquipment[i] $ "]]");
                }
            }
        }
        Log("XXXX: xPawn: [[" $ String(xPawn(Other)) $ "]]");
        return true;
    }
Sadly, Perk price discounts are not being applied even though my customized items are extending the classes that do get discounts. That one's going to be tricky...
I guess because your mutator is not whitelisted.
 
Last edited:
Upvote 0
ammo is for free
We're poking things differently somehow; with what I have right now, everything costs dosh like it should, including ammo.

I uploaded the complete source code of what I have right now here: http://www.fileden.com/files/2010/2/18/2766190//UltraMut.zip

Thanks for the snippet on replacing the RequiredEquip, I'll certainly try that out.

The next major hurdle is Replication. Lo and behold, the customized trader list shows up for me on the server but the normal trader list shows up for someone who joins. FFFFFFFFFFUUUU hate replication so f-ing much from a coding perspective. I'll look at some existing mutators and try to pull out a magic bunny. It's something to do with the way I'm altering the KFLevelInfo, since CheckReplacement still properly replaces normal equipment with my custom equipment when a player tries to drop it.

I noticed another problem in my mutator as well: the sell-price of my custom weapons is not being diminished properly at the moment a player drops a pickup-class item, and my custom pickup-class item replaces it. You can buy something from the trader, drop it to get the replacement, then sell the newly-gained replacement back to the trader for a non-reduced (as if it hasn't been 'owned' yet) amount of money. However, if you hang on to the newly-gained replacement instead of selling it, the sell price gets properly reduced at some point during the wave I noticed.
 
Last edited:
Upvote 0