so i can make a trigger increasing damage by clicking button or must i make 20 triggers for 20 upgrades?
Not really sure what that monster of a code segment was supposed to do, but there's a simpler solution.
1. Creating the Behaviors in Data
I stay away from data so I'm going to say this briefly: Make the four stackable behaviors in data which modify unit damage by +1, -1, +10, and -10. Call them "Damage +1", "Damage +10", "Damage -1", and "Damage -10".
Now we can modify any unit's respective bonus damage through triggers by applying and removing behaviors.
2. Creating a Custom Definition to Accept an Integer Value to Modify Unit Damage
As the title of this part says, we're going to need a custom definition. I'm assuming you don't know how to work with custom definitions so I'll go through this with you.
Very briefly, custom action definitions are like your very own homemade triggers.
Right click on the left in the field containing your triggers. Go to New, click on New Action Definition.
Let's rename it to "Set Unit Bonus Damage".
Right click on "Parameters" and create a new parameter.
Name it "Unit".
Set it to type Unit.
Create another parameter. Name it "Amount". Set it to type Integer.
So we got our custom action's input slots set up. Time for the actions within our custom action.
Create a new action, Remove Behavior from Unit (this works similar to a normal trigger).
For amount of behaviors, put 10. You'll see why later.
For behavior, put the behavior we made "Damage +10".
Click on where it says "unit" in the action. When it brings up the unit input window, click on Parameter" Then click on the parameter we made, "Unit".
Copy and paste this action three times, for a total of four.
Change the behavior in each so that there's one of each, +1, -1, +10, and -10. (see screen shots attached).
By doing this, we erase all bonus damage from a unit before the rest of the action runs.
We're going to go back up the action really quick and create a new local variable in this action.
Local variable, type string, let's call it "Absolut Amount". (Vodka reference).
Set the value of it to convert integer to string, absolute value, then put in our parameter Amount.
Now we're going to do the rest of the actions. This is still in our custom action.
Create a new action, type If then Else.
Create a condition for the if, type comparison, set it to our parameter Value < 0.
For the then part, create the action "Add Behavior to Unit from Player."
For the amount value, set it to Convert String to Integer > Substring of String. For the string part, set It to our variable "Absolute Amount". Set both of the other to integer values to 1.
For the behavior, set it to Damage -10.
For the player, set it to 0.
Copy and paste this action. Change the two 1s to 2s. Change the behavior to "-1 Damage" instead of -10.
Now we have the functionality to reduce a unit's damage using this action. Time to make it so we can add damage as well.
Copy and paste the two actions under Then to Else. Change the behaviors to the opposite one (Damage -10 to Damage + 10 and Damage -1 to Damage +1)
That functionality has been added and it's time to test this custom action.
3. Testing Our New Custom Action
Open the terrain module. Slap a unit down, let's say, a marine.
Create a new trigger.
For the event, do Map Initialization.
For the action, create our action that we just made, "Set Unit Damage".
For the integer value input, put in any number -99 to 99. For the unit, put the unit we created.
Like they said, you can change weapons of a unit but increasing damage is a bit trickier. If you want to increase the damage done of a unit type then use catalog field set functions. Changing a unit's damage via catalog will change the weapon damage of all units of that type, though. So you can't just increase one unit's damage via catalog.
However, there is a work around. By making about four stackable behaviors, which increase a unit's damage by +1, +10, -1, and -10 then you can make your own functions in triggers to set a unit's bonus damage to whatever you want. I can provide more information if you're interested.
Mapster isn't letting me attach another image to that post.
@Yaksmanofage: Go
@cleanto: Go
Not really sure what that monster of a code segment was supposed to do, but there's a simpler solution.
1. Creating the Behaviors in Data
Now we can modify any unit's respective bonus damage through triggers by applying and removing behaviors.
2. Creating a Custom Definition to Accept an Integer Value to Modify Unit Damage
As the title of this part says, we're going to need a custom definition. I'm assuming you don't know how to work with custom definitions so I'll go through this with you.
So we got our custom action's input slots set up. Time for the actions within our custom action.
By doing this, we erase all bonus damage from a unit before the rest of the action runs.
We're going to go back up the action really quick and create a new local variable in this action.
Now we're going to do the rest of the actions. This is still in our custom action.
Now we have the functionality to reduce a unit's damage using this action. Time to make it so we can add damage as well.
That functionality has been added and it's time to test this custom action.
3. Testing Our New Custom Action
@cleanto: Go
Like they said, you can change weapons of a unit but increasing damage is a bit trickier. If you want to increase the damage done of a unit type then use catalog field set functions. Changing a unit's damage via catalog will change the weapon damage of all units of that type, though. So you can't just increase one unit's damage via catalog.
However, there is a work around. By making about four stackable behaviors, which increase a unit's damage by +1, +10, -1, and -10 then you can make your own functions in triggers to set a unit's bonus damage to whatever you want. I can provide more information if you're interested.