• 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/
  • Weve updated the Tripwire Privacy Notice under our Policies to be clearer about our use of customer information to come in line with the EU General Data Protection Regulation (GDPR) rules that come into force today (25th May 2018). The following are highlights of our changes:


    We've incorporated the relevant concepts from the GDPR including joining the EU and Swiss Privacy Shield framework. We've added explanations for why and how Tripwire processes customer data and the types of data that we process, as well as information about your data protection rights.



    For more information about our privacy practices, please review the new Privacy Policy found here: https://tripwireinteractive.com/#/privacy-notice

Changing/replacing what weapons spawn on the map?

pie1055

Active member
Jul 6, 2011
468
53
28
Bedlam
As part of a game mode I'm working on I'm attempting to modify what weapons spawn on maps but have come to a roadblock of sorts. My main question is how this should be done? Below are what I've tried and why, in case of TL;DR.

Far as I can tell, the weapons and armor chosen to spawn on the map are located in KFGameContent\KFPickupFactory_ItemDefault.uc. At some point this class is used in KFGameInfo's ItemPickups array, although I don't see where in the code that happens. KFGameInfo simply declares it as an array and begins using it in the InitAllPickups() function expecting it to hold valid data.

1st Attempt:
My guess is that the array is populated as part of the map loading process but I have no clue how I would get my hands into that section of code. Due to this I started off modifying the PickupFactories externally. Playing with their PickupIndex and PickupItems I managed to get everything working perfectly... In single player. When testing on a server, the items get the wrong mesh or in most cases no mesh at all. Doing some testing I found that while changes to PickupIndex were being replicated to the clients the changes to PickupItems were not, causing errors inside the KFPickupFactory_Item.SetPickupMesh() function where the vanilla array is being accessed by the modified index. I *think* this is because arrays can't be replicated, not that it matters anyways because I haven't tried replacing the vanilla PickupFactories with custom ones extending the originals. Speaking of...

2nd Attempt:
This time around I wipe out the existing ItemPickups array in KFGameInfo, replacing each member with a copy Spawned using a version that extends the original class. Problem is this causes them all to use the ar-15's mesh and become un-pickupabble (is that even a word?). I'm pretty sure this is the default state of a KFPickupFactory_Item due to it using the ar-15's mesh in the default properties for its appearance and other code being required to activate them for pickup. Despite appearances, a couple dozen `log()s reveal everything is working as intended, even down to the SetPickupMesh() function choosing the correct mesh for me spawning eviscerators, centerfires, flamethrowers, and etc everywhere. Further testing reveals that if you only wipe out the KFGameInfo's ItemPickups array (ItemPickups.length = 0) you get the exact same result- intangible ar-15s everywhere despite those item factories no longer existing. Ditto for the AmmoPickups array (they render as ammo boxes though).

Is there a way I can get Attempt 1 or Attempt 2 to work, or am I missing a completely obviously simpler way of changing what spawns on the map? A PickupFactoryItemClass default property would be lovely. I can post code if needed, I just feel it's unnecessary to post a bunch of code if its entire purpose is off-base.
 
Last edited:

pie1055

Active member
Jul 6, 2011
468
53
28
Bedlam
So after working on this one for a few more days I managed to find a way to get it working and thought I'd post what I did for anyone else interested. Basically I fixed the issue I had in the above noted 1st Attempt by replicating changes made to the PickupItems array to the clients (a "Basically" that spans around 30 combined hours of time to get it working >.<).

Here's a great link for anyone looking into the way unreal 3 does replication; https://docs.unrealengine.com/udk/Th...ationHome.html
And I followed this method from said source to get it working; https://docs.unrealengine.com/udk/Th...ClientRPC.html

As for the details of propagating changes to the PickupItems array, I used the above source to call a function in my extended KFPlayerController(client side) from my extended KFGameinfo_Survival(server side). Searching KF2's code(Just looking at all references of WorldInfo because that's what I do for fun) I came upon a golden little nugget in the form of the iterator WorldInfo.AllNavigationPoints(). Guess what all PickupFactories eventually extend from. That's right, Engine\Classes\NavigationPoint.uc. Tell it to search for KFPickupFactory_Items, clear out the ItemPickups array, and propagate it just like you did server side. BAM. The client knows about your modified array. The only tricky part is that in my implementation the actual modifications to the array- server and client side- are in separate locations so I have to be careful they match. It's still important to do both, otherwise you can get different effects depending on if you're playing on a server or just running it in solo offline mode.

Gameinfo code stuff:
(NoTrader is the name of the game mode, NT is the abbreviation I use for classes and the like- if you see either in this code that means it's referring to extended classes I created for the purposes of the game mode)
Spoiler!

PlayerController code stuff;
Spoiler!
 
Last edited: