Jump to content

Activate buff on item craft - possible?


poly

Recommended Posts

Hi all,

I'm trying to create a buff whereby a player has a small chance to get drunk when crafting specific items - e.g. items related to beer brewing 🍻

 

Here's what I am trying, can somebody advise if this is correct, or what a better way to go about it would be?

 

<buff name="RandomDrunk" hidden="true">
			<update_rate value="1"/>
			<stack_type value="ignore"/>
			<effect_group>
			
				<!-- 1 --><passive_effect name="CraftingIngredientCount" operation="base_set" value="@$randomdrunk" tags="randomdrunk"/>
<!-- this needs to be ingredient count/crafting count in order to carry over a specific number to the random roll -->
				
				<!-- 3 --><triggered_effect trigger="onSelfBuffStart" action="AddBuff" buff="buffBeer">
					<!-- 2 --><requirement name="RandomRoll" seed_type="Random" min_max="1,4" operation="Equals" value="@$randomdrunk"/>
				</triggered_effect>
				
			</effect_group>
		</buff>


So the buff has 3 parts... 

Part 1: Player crafts an item with an ingredient count of 1, 2, 3 or 4 (there will be 4 recipes)

Part 2: Buff randomly rolls a number between 1 and 4.
Part 3: If the randomly rolled number is the same as the crafting ingredient count then the drunken buff is added. If the numbers are different no buff is added.

To me, a novice with coding, this makes sense?

However when I craft an item nothing happens - besides the item being crafted. Which leads me to think I'm missing a crucial step somewhere.

Can anyone help? 

Thank you 

Link to comment
Share on other sites

Well first, the CraftingIngredientCount is not a requirement check or a trigger, it's a passive. As in it sets the recipe's ingredient required amount to this number. So it would be used to reduce or increase the ingredient cost of recipes.

I think what would do well in this situation would be something like this:

 


				<triggered_effect trigger="onSelfBuffStart" action="ModifyCVar" cvar="CurrentPlayerLevel" operation="set" value="1"/>
				<triggered_effect trigger="onSelfBuffUpdate" action="AddBuff" buff="buffQuestWorldPlayerLevelUp">
					<requirement name="PlayerLevel" operation="GT" value="@CurrentPlayerLevel"/>
				</triggered_effect>


This is an example of my rpg mod, but you could substitute it with the crafting cvar. But, on entering the game, the player gets this buff. It immediately sets the cvar 'currentplayerlevel' to 1 (since player will be level 1. you'd set to 0 of course)... then, it runs a check every .5 seconds to see if the player level (crafted cvar in your case) is greater than the cvar. if so, it applies the buff . In your case, that buff would be a buff with a randomroll check to give the beer buff, as well as set your cvar to the crafted logged cvar.

The logged cvar can be found in the F3 menu. It's just _craftCount_YourRecipeNameHere. This does mean you'd have to have each recipe you want as it's own separate code from above.

Hope all of that makes sense...

Link to comment
Share on other sites

20 hours ago, Telric said:

Well first, the CraftingIngredientCount is not a requirement check or a trigger, it's a passive. As in it sets the recipe's ingredient required amount to this number. So it would be used to reduce or increase the ingredient cost of recipes.

I think what would do well in this situation would be something like this:

 


				<triggered_effect trigger="onSelfBuffStart" action="ModifyCVar" cvar="CurrentPlayerLevel" operation="set" value="1"/>
				<triggered_effect trigger="onSelfBuffUpdate" action="AddBuff" buff="buffQuestWorldPlayerLevelUp">
					<requirement name="PlayerLevel" operation="GT" value="@CurrentPlayerLevel"/>
				</triggered_effect>


This is an example of my rpg mod, but you could substitute it with the crafting cvar. But, on entering the game, the player gets this buff. It immediately sets the cvar 'currentplayerlevel' to 1 (since player will be level 1. you'd set to 0 of course)... then, it runs a check every .5 seconds to see if the player level (crafted cvar in your case) is greater than the cvar. if so, it applies the buff . In your case, that buff would be a buff with a randomroll check to give the beer buff, as well as set your cvar to the crafted logged cvar.

The logged cvar can be found in the F3 menu. It's just _craftCount_YourRecipeNameHere. This does mean you'd have to have each recipe you want as it's own separate code from above.

Hope all of that makes sense...


Thanks for the suggestion

In this example wouldn't the player permanently change the cvar to a value of 1 for example? If all players enter with a value of 0, then upon crafting an item it has a random chance to activate buff and change the value from 0 to 1... this would mean the buff could only be activated once?, as each successive time the value would still be 1.

Link to comment
Share on other sites

the xml bit i posted works at all times. you start with the cvar to 0, you craft an item and your _craftCount_ variable increases to 1. on the next update, that bit would set your cvar to 1 (cuz _craftCOunt_ is larger than the cvar which was 0 at the time). so now your cvar is 1 and your craft count variable is 1. if you craft another, that _craftCount_ goes to 2. then on the next update, that xml bit increases your cvar to 2

as for the trigger to give the buff, you'd just need a randomroll to give that buff on update, BEFORE your change your cvar to equal _craftcount_. buffs run top down so you want that update tick to randomly give the buff, before your cvars match. after they match the update tick wont do anything untill _craftCount_ is larger than the cvar.

				<triggered_effect trigger="onSelfBuffStart" action="ModifyCVar" cvar="YouCraftedThis" operation="set" value="0"/>

				<triggered_effect trigger="onSelfBuffUpdate" action="AddBuff" buff="buffBeerBuffIdkWhatItsCalled">
					<requirement name="CVarCompare" cvar="_craftCount_YourCraftingObject" operation="GT" value="@YouCraftedThis"/>
				</triggered_effect>

				<triggered_effect trigger="onSelfBuffUpdate" action="ModifyCVar" cvar="YouCraftedThis" operation="add" value="1">
					<requirement name="CVarCompare" cvar="_craftCount_YourCraftingObject" operation="GT" value="@YouCraftedThis"/>
				</triggered_effect>

Here, i did a basic idea of what you'd want.

Link to comment
Share on other sites

I've added the randomroll but can't get it to work properly:

 

<triggered_effect trigger="onSelfBuffStart" action="ModifyCVar" cvar="craft_drunk1" operation="set" value="1"/>
				
					<triggered_effect trigger="onSelfBuffUpdate" action="AddBuff" buff="buffBeer">
						<requirement name="RandomRoll" seed_type="Random" min_max="1,2" operation="Equals" value="@craft_drunk1"/>
						<requirement name="CVarCompare" cvar="_craftCount_beerkeg1" operation="GTE" value="@craft_drunk1"/>
					</triggered_effect>

				<triggered_effect trigger="onSelfBuffUpdate" action="ModifyCVar" cvar="craft_drunk1" operation="add" value="1">
					<requirement name="CVarCompare" cvar="_craftCount_beerkeg1" operation="GT" value="@craft_drunk1"/>
				</triggered_effect>


So the cvar is set to 1 by default,

 

Then the buff is added only if 2 requirements are met: 

1. If the randomroll is equal to the cvar: 1
2. If the _craftCount_beerkeg1 is greater than/equal to the cvar, again which is 1.

 

The _craftCount_beerkeg1 is 0 by default, and changes to 1 upon being crafted. So in theory if these 2 conditions are met, then the buff 'buffBeer' is triggered.
 

It's basically a 50% chance of getting the buff upon crafting the item 'beerkeg1'.

 

However, nothing happens.

 

Am I doing something wrong?

P.S thanks for all your help, its taken me a while to get my head around it 

Edited by poly (see edit history)
Link to comment
Share on other sites

First thing would be to remove the randomroll and make sure all is firing correctly without it. If so, then it could be an issue that i've had before where certain instances of not having a normal 0 to 100 range would cause the randomroll to not fire. I could never find out why this happened, just that having a non standard randomroll would sometimes never fire no matter how many instances i tried. also, i'm assuming you're putting this to the character already.. via the status check buff or some other means, but obviously if this isnt attached to the player in some way, it wont work.

Link to comment
Share on other sites

		<triggered_effect trigger="onSelfBuffStart" action="ModifyCVar" cvar="craft_spellWildGrowth" operation="set" value="1"/>
				
					<triggered_effect trigger="onSelfBuffUpdate" action="AddBuff" buff="buffBeer">
						<requirement name="RandomRoll" seed_type="Random" min_max="0,100" operation="GTE" value="50"/>
						<requirement name="CVarCompare" cvar="_craftCount_spellWildGrowth" operation="GT" value="@craft_spellWildGrowth"/>
					</triggered_effect>

				<triggered_effect trigger="onSelfBuffUpdate" action="ModifyCVar" cvar="craft_spellWildGrowth" operation="add" value="1">
					<requirement name="CVarCompare" cvar="_craftCount_spellWildGrowth" operation="GT" value="@craft_spellWildGrowth"/>
				</triggered_effect>

This worked in my game. I changed stuff to be one of my items. I changed the randomroll to give a 50% chance, and i changed it from GTE to GT. If it was at GTE, it would constantly fire the beer buff trigger, cuz your cvars were equal. Having it greater than makes it so you craft, it does that check once, then does the final trigger to set both cvars to be equal.

Also, you'll need to do something to make buffbeer stay on the player. Vanilla uses a cvar count down to remove the buff, so if your beerduration cvar is LTE 0, it removes the beer buff. Not sure what you're planning, such as making a new buff or what, but that's something to remember. This code works though and will apply the buff, even though its' removed on the next update cuz of no duration cvar.

Link to comment
Share on other sites

11 hours ago, Telric said:
		<triggered_effect trigger="onSelfBuffStart" action="ModifyCVar" cvar="craft_spellWildGrowth" operation="set" value="1"/>
				
					<triggered_effect trigger="onSelfBuffUpdate" action="AddBuff" buff="buffBeer">
						<requirement name="RandomRoll" seed_type="Random" min_max="0,100" operation="GTE" value="50"/>
						<requirement name="CVarCompare" cvar="_craftCount_spellWildGrowth" operation="GT" value="@craft_spellWildGrowth"/>
					</triggered_effect>

				<triggered_effect trigger="onSelfBuffUpdate" action="ModifyCVar" cvar="craft_spellWildGrowth" operation="add" value="1">
					<requirement name="CVarCompare" cvar="_craftCount_spellWildGrowth" operation="GT" value="@craft_spellWildGrowth"/>
				</triggered_effect>

This worked in my game. I changed stuff to be one of my items. I changed the randomroll to give a 50% chance, and i changed it from GTE to GT. If it was at GTE, it would constantly fire the beer buff trigger, cuz your cvars were equal. Having it greater than makes it so you craft, it does that check once, then does the final trigger to set both cvars to be equal.

Also, you'll need to do something to make buffbeer stay on the player. Vanilla uses a cvar count down to remove the buff, so if your beerduration cvar is LTE 0, it removes the beer buff. Not sure what you're planning, such as making a new buff or what, but that's something to remember. This code works though and will apply the buff, even though its' removed on the next update cuz of no duration cvar.


Just tried this and it works in my game with my custom variables - thanks!

Although I'd like to understand why the original randomroll didn't work. Like you said, if not a normal 0-100 range could that affect it?

Link to comment
Share on other sites

well, one issue was it was using the equals operation, so if your cvar was equal to the crafted cvar, it would fire on update. another issue was you were using the cvar as a number. with a value of 1 to 2, once your cvar got past 2, it would never fire again.
 

min_max="1,2" operation="Equals" value="@craft_drunk1"


so if craft_drunk1 was 1 or 2, it would fire. but if it was 3 or more, it would never fire.

Link to comment
Share on other sites

2 hours ago, Telric said:

well, one issue was it was using the equals operation, so if your cvar was equal to the crafted cvar, it would fire on update. another issue was you were using the cvar as a number. with a value of 1 to 2, once your cvar got past 2, it would never fire again.
 

min_max="1,2" operation="Equals" value="@craft_drunk1"


so if craft_drunk1 was 1 or 2, it would fire. but if it was 3 or more, it would never fire.


So all of the probability is worked out in the random roll this way, and the _craftCount is merely a conduit to enable the buff activated upon the item craft?

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...