# Math formulas in triggers

Status
Not open for further replies.

#### lmjai

Level 2
I want to make an action to look like this:
Player - Add 5((n^2-n)/2) to (Triggering player) Gold

n = (Charges remaining in (Sold Item))

How can I make it?

#### ap0calypse

Level 28
To make things easier, first create an integer variable (I called it "tempInt") and set it to "(Charges remaining in (Sold Item))", so you don't have to use the function the entire time.

You will have to use the "arithmetic" function a few times.
Click the standard "1000" (the value to add), then go to Function -> Arithmetic.
Now you'll see something like "Value + 1".

To begin, you will have to see which functions come first. The first one you see is the "5", so you add that in the "value" section. You will have to change the "+" into a "x" (multiply).
The "1" will become all the rest of the equation.

Now press the "1" and, again, select "arithmetic".
This time, the value has to hold "(n^2 - 1)". To do this, directly go to Arithmetic again, and once again after that.
Here you will type "n x n" (where the first "n" is the Value and the second one is the "1").
Press "OK" a few times until you see "(n x n) + 1"
Change the "+" to a "-" and change the "1" to an "n".
Now you've got "(n x n) - n", or "n^2 - n".

Go down one step and change that "+" to a "/" (divide), change the "1" to a "2" and you're done!

• Player - Add (5 x (((tempInt x tempInt) + 1) / 2)) to (Triggering Player) Current gold

ALTERNATIVELY:

JASS:
``call SetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD) + 5 * ((udg_tempInt*udg_tempInt-udg_tempInt)/2))``

Turning this into GUI would look like:
• Custom script: call SetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD) + 5 * ((udg_tempInt*udg_tempInt-udg_tempInt)/2))
As you can see, the actual addition is: `5 * ((udg_tempInt*udg_tempInt-udg_tempInt)/2)`
Far easier than the GUI alternative...

Status
Not open for further replies.

Replies
1
Views
729
Replies
2
Views
626
Replies
6
Views
155
Replies
0
Views
310
Replies
6
Views
953