RimWorld

RimWorld

Drop Loot When Destroyed Framework
 This topic has been pinned, so it's probably important
Romyashi  [developer] 5 Aug, 2023 @ 8:02am
Instructions for implementing
Currently there are two ways of implementing the framework -- one with comps and one for filth.
Note: Remove the comments that start with "<=" from your XML files if you copy text from here, they are made for the instructions only and will crash your game.

Comp:
<comps> <li Class="DLWDFramework.DLWDThingCompProps"> <DropOnlyOne>true</DropOnlyOne> <= Optional. When set to true will ensure that if one loot thing has dropped no other loot from the list will drop. <GuaranteeOne>true</GuaranteeOne> <= Optional. When set to true will ensure that at least one loot thing from the list will drop. Do not use on filth that generates naturally a lot, like rock rubble, otherwise the game will not load any new map. Do not use on a plant that has both vanilla harvestAfterGrowth tag and this mod's HasToBeHarvestable tag. <LootConfigs> <li> <LootThingDef>Steel</LootThingDef> <= The defName of the desired ThingDef to be dropped. <LootChance>0.6</LootChance> <= The chance for the thing to drop, ranging from 0.00 to 1.00. <LootAmountMin>5</LootAmountMin> <= Minimum and maximum amount of loot to drop. The code will randomize the amount between these two numbers. <LootAmountMax>10</LootAmountMax> <HasToBeHarvestable>true</HasToBeHarvestable> <= Only for plants. Specifies if the plant has to be harvestable for the loot to drop. If set to false or not set at all the loot will drop at any growth stage. <ForbiddenWhenDropped>false</ForbiddenWhenDropped> <= Optional. Specifies if the loot will be forbidden when dropped outside of home area. If not set to false will default to true. <HasToBeDestroyedIntentionally>true</HasToBeDestroyedIntentionally> <= Optional. Makes it so the loot drops only when the parent is destroyed by harvesting, cutting, mining or deconstructing. Ignores ForbiddenWhenDropped flag, makes the loot not forbidden. </li> <li> <= This way you can add as many loot drops as you want. <LootThingDef>WoodLog</LootThingDef> <LootChance>0.6</LootChance> <LootAmountMin>5</LootAmountMin> <LootAmountMax>10</LootAmountMax> </li> </LootConfigs> </li> </comps>

Filth is pretty much exactly the same except that the properties are set in the mod extensions.
Filth:
<thingClass>DLWDFramework.DLWDFilth</thingClass> <= This class contains code necessary for drops to work. Filth cannot have comps, so it is done with a class and a mod extension. <modExtensions> <li Class="DLWDFramework.FilthLootExtension"> <DropOnlyOne>true</DropOnlyOne> <GuaranteeOne>true</GuaranteeOne> <LootConfigs> <li> <LootThingDef>Steel</LootThingDef> <LootChance>0.6</LootChance> <LootAmountMin>5</LootAmountMin> <LootAmountMax>10</LootAmountMax> </li> </LootConfigs> </li> </modExtensions>

There is also a comp that allows for item to self destruct when it is used. There is one in vanilla as well, but it crashes with this framework, so use this one instead:
<comps> <li Class="CompProperties_Usable"> <= Vanilla comp to allow using of items. <useJob>UseItem</useJob> <useLabel>Use {0_label}</useLabel> </li> <li Class="DLWDFramework.DLWDDestroySelfComp" /> <= Use only with CompProperties_Usable. Makes it so that when the item is used it gets destroyed. <comps>
Last edited by Romyashi; 3 May, 2024 @ 7:51am
< >
Showing 1-15 of 25 comments
tanyfilina 12 Aug, 2023 @ 10:22am 
Hello!
I've tried to make a patch for another mod with this instruction, but it had broken my game. The code is following:
<Patch> <Operation Class="PatchOperationSequence"> <success>Always</success> <operations> <li Class="PatchOperationTest"> <xpath>/Defs/ThingDef[defName = "RC2_PlantOrangeTree"]/comps</xpath> <success>Invert</success> </li> <li Class="PatchOperationAdd"> <xpath>/Defs/ThingDef[defName = "RC2_PlantOrangeTree"]</xpath> <value> <comps/> </value> </li> </operations> </Operation> <Operation Class="PatchOperationSequence"> <success>Always</success> <operations> <li Class="PatchOperationTest"> <xpath>/Defs/ThingDef[defName = "RC2_PlantOrangeTree"]/comps/li[@Class="DLWDFramework.DLWDThingCompProps"]</xpath> <success>Invert</success> </li> <li Class="PatchOperationAdd"> <xpath>/Defs/ThingDef[defName = "RC2_PlantOrangeTree"]/comps</xpath> <value> <li Class="DLWDFramework.DLWDThingCompProps"> <LootConfigs> <li> <LootThingDef>WoodLog</LootThingDef> <= The defName of the desired ThingDef to be dropped. <LootChance>1.0</LootChance> <= The chance for the thing to drop, ranging from 0.00 to 1.00. <LootAmountMin>15</LootAmountMin> <= Minimum and maximum amount of loot to drop. The code will randomize the amount between these two numbers. <LootAmountMax>25</LootAmountMax> <HasToBeHarvestable>true</HasToBeHarvestable> <= Only for plants. Specifies if the plant has to be harvestable for the loot to drop. If set to false or not set at all the loot will drop at any growth stage. </li> </LootConfigs> </li> </value> </li> </operations> </Operation> </Patch>
Romyashi  [developer] 12 Aug, 2023 @ 10:36am 
@tanyfilina Do you have the error itself? Is it generated at all? Or the game just closes?
tanyfilina 12 Aug, 2023 @ 11:03am 
Black screen and all mods removed from mod-list after reload.
Last edited by tanyfilina; 12 Aug, 2023 @ 11:10am
tanyfilina 12 Aug, 2023 @ 11:08am 
I've found this in the player.log:

Exception reading DestroyedLootPatch.xml as XML: System.Xml.XmlException: Name cannot begin with the '=' character, hexadecimal value 0x3D. Line 35, position 44.
Romyashi  [developer] 12 Aug, 2023 @ 11:11am 
@tanyfilina Oh, right, makes sense. Remove the comments that start with "<=" from the patch, I made them for the instructions, they should not be in your XMLs. Added this info to the main post.
Last edited by Romyashi; 12 Aug, 2023 @ 11:53am
Romyashi  [developer] 12 Aug, 2023 @ 11:35pm 
@tanyfilina Can you confirm that the framework is enabled and loaded before your patch mod?
Last edited by Romyashi; 12 Aug, 2023 @ 11:47pm
tanyfilina 12 Aug, 2023 @ 11:55pm 
Lol, I'm idiot ))
I'l delete error logs here to clean space )
tanyfilina 13 Aug, 2023 @ 12:26am 
Now there are no errors, but the tree I've patched drops no wood when cut.
Romyashi  [developer] 13 Aug, 2023 @ 12:43am 
@tanyfilina Seems like cutting calls for other code than regular destruction. I will take a look at what I can do to fix this.
Romyashi  [developer] 13 Aug, 2023 @ 4:53am 
@tanyfilina Should be fixed now. The problem was in the harvestAfterGrowth tag. Now, if the plant has this tag, you have to include <tickerType>Normal</tickerType> somewhere in the def and everything should work. Make sure you have the latest version of the framework.
Last edited by Romyashi; 13 Aug, 2023 @ 4:57am
tanyfilina 13 Aug, 2023 @ 5:40am 
In this mod all plants are derived from the base plant that has <tickerType>Long</tickerType>. If I change it to Normal, won't it break something?
Romyashi  [developer] 13 Aug, 2023 @ 5:43am 
@tanyfilina This is RimCuisine 2, correct? I tested it on it to make sure it's not a problem with that mod specifically and no, nothing breaks when you add a tickerType that is different from it's base. At least I did not see if anything was broken, haha.
Last edited by Romyashi; 13 Aug, 2023 @ 5:43am
tanyfilina 13 Aug, 2023 @ 5:43am 
Yes ) Thank you!
tanyfilina 13 Aug, 2023 @ 6:19am 
Now everything works (although it works only with each tree separately, I've tried to modify the whole class - RC2_DeciduousTreeBase - didn't work). The only little problem left is that the new dropped loot is forbidden.
Romyashi  [developer] 13 Aug, 2023 @ 6:30am 
@tanyfilina All loot outsife of home area will be forbidden. This is to avoid situations where trees, for example, die on the edges of the map and your colonists will spend half a day hauling stuff from there. I may add another flag for forbidding or unforbidding though, will notify you when I do so.
< >
Showing 1-15 of 25 comments
Per page: 1530 50