Jump to content

How can you create an item when a player upgrades something?


Recommended Posts

I'm writing a farming mod in which players can take action to upgrade plant blocks.  For those unfamiliar with farming, I imagine this should be very similar to using a hammer to upgrade a frame shape, and the same solution should apply.

 

I have a watering can item that players can use to water their plants.  This consumes a murky water:

      <item name="AesF_wateringCan">
         <property name="CustomIcon" value="bucketRiverWater" />
         <property name="CustomIconTint" value="99CCFF" />
         <property name="DescriptionKey" value="AesF_wateringCanDesc" />
         <property name="Tags" value="tool,wateringCan" />
         <property name="Group" value="Tools/Traps" />
         <property name="HoldType" value="34" />
         <property name="Meshfile" value="#Other/Items?Crafting/Metal/IronBucketWaterPrefab.prefab" />
         <property name="DropMeshfile" value="Items/Misc/sack_droppedPrefab" />
         <property name="Material" value="Mmetal" />
         <property name="RepairTools" value="resourceScrapIron" />
         <property name="DegradationBreaksAfter" value="false" />
         <property name="SoundJammed" value="ItemNeedsRepair" />
         <property name="ShowQuality" value="false" />
         <property name="RepairExpMultiplier" value="5.5" />
         <property name="SellableToTrader" value="false" />
         <property class="Action0">
            <property name="Class" value="Repair" />
            <property name="Delay" value="1.0" />
            <property name="Repair_amount" value="100" />
            <property name="Upgrade_hit_offset" value="-1" />
            <property name="Upgrade_action_sound" value="bucketbail_water" />
            <property name="Allowed_upgrade_items" value="AesF_wateringCan,drinkJarRiverWater" />
            <property name="UsePowerAttackAnimation" value="false" />
         </property>
         <property class="Action1">
            <property name="Class" value="Repair" />
            <property name="Delay" value="1.0" />
            <property name="Repair_amount" value="100" />
            <property name="Upgrade_hit_offset" value="0" />
            <property name="Upgrade_action_sound" value="bucketbail_water" />
            <property name="Allowed_upgrade_items" value="AesF_wateringCan,drinkJarRiverWater" />
            <property name="UsePowerAttackAnimation" value="false" />
         </property>
      </item>

 

(Still a WIP)

 

I would like this to create an empty water jar in the player's inventory.  First I tried adding a create item line within the actions, which I copied from the existing items.xml file:

	<property class="Action0">
		<property name="Class" value="Repair" />
		<property name="Delay" value="1.0" />
		<property name="Repair_amount" value="100" />
		<property name="Upgrade_hit_offset" value="-1" />
		<property name="Upgrade_action_sound" value="bucketbail_water" />
		<property name="Allowed_upgrade_items" value="AesF_wateringCan,drinkJarRiverWater" />
		<property name="UsePowerAttackAnimation" value="false" />
		<property name="Create_item" value="drinkJarEmpty"/>
		<property name="Create_item_count" value="1"/>
	</property>

 

However, nothing happens when I use this item to upgrade.  I copied it from I believe the boiled water item, which does give back an empty jar when used.

 

So then I went to the plant block itself, and tried adding it to the upgrade property:

		<property class="UpgradeBlock">
			<property name="ToBlock"				value="AesF_FarmingYuccaGrowing" />
			<property name="Item" 					value="drinkJarRiverWater" />
			<property name="ItemCount" 				value="1" />
			<property name="UpgradeHitCount" 		value="1" />
			<property name="Create_item" 			value="drinkJarEmpty"/>
		</property>

 

Again, nothing happens.  No errors in either case; I just didn't get an empty jar.  I suspect because that create_item command is meant to occur during a "use" or "eat" event, and not an "upgrade" event.

 

I also took a shot in the dark hoping there was such a thing as an "upgrade" event:

	<drop event="Upgrade" name="drinkJarEmpty" count="1" />

 

But 7DTD yelled at me that this was an invalid event type (I got an error in the console).

 

How do I get this jar into the player's inventory when they consume the murky water to upgrade a block?

Edited by Aesirkin
Cleaned up code (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...