• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • ✅ HD Level Design Contest #1 POLL is now OPEN! Check out the stunning visuals of the final entries. 🔗Click here to cast your vote!

Math formulas in triggers

Status
Not open for further replies.
Level 28
Joined
Jan 26, 2007
Messages
4,789
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.
Top