Math Formula - Item Cost

garion992

TH.net Regular
Reaction score
17
I need a formula for purchasing Items:

Copper Cost of Item = (Item Level x 9) x Health of Item
In my map there are 3 kinds of Valuta:
- Copper (originaly gold. 100 Copper = 1 Silver)
- Silver (originaly lumber. 100 Silver = 1 gold)
- Gold (originaly food)

So if my item is Level 10 and has 3 Health, the Copper Cost will be 270. I can't buy an item with a copper value of 270 cause my copper will never be above 100 (100 copper = 1 silver).
So i need to set the value to 70 copper and 2 silver.
I can't set Silver just to the value "Copper / 100" cause then it wil be 3 Silver (i think), and then the copper still has a value of 270

Question: How can i set the variable copper (in this case) to 70 and the variable silver to 2?
 

garion992

TH.net Regular
Reaction score
17
it's an integer, so that solves everything!
Thx!

I will post if trigger won't work.

but why this don't work if i buy the item: (TempMoneyValue[1] = copper, TempMoneyValue[2] = Silver
Code:
Item Cost Off Hand
    Events
        Unit - A unit Sells an item (from shop)
    Conditions
        (Item-class of (Item being manipulated)) Equal to Permanent
    Actions
        Game - Display to (All players) the text: Boom!
        Set TempInt = (((Item level of (Item being manipulated)) x 6) x (Integer((Current life of (Item being manipulated)))))
        Set TempMoneyValue[2] = (TempInt / 100)
        Set TempMoneyValue[1] = (TempInt - (TempMoneyValue[2] x 100))
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (((Owner of (Triggering unit)) Current gold) Less than TempMoneyValue[1]) and (((Owner of (Triggering unit)) Current lumber) Greater than TempMoneyValue[2])
            Then - Actions
                Game - Display to (All players) the text: Enough money -> cov...
                Player - Add 100 to (Owner of (Triggering unit)) Current gold
                Player - Add -1 to (Owner of (Triggering unit)) Current lumber
                Player - Add (-1 x TempMoneyValue[1]) to (Owner of (Triggering unit)) Current gold
                Player - Add (-1 x TempMoneyValue[2]) to (Owner of (Triggering unit)) Current lumber
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (((Owner of (Triggering unit)) Current gold) Greater than or equal to TempMoneyValue[1]) and (((Owner of (Triggering unit)) Current lumber) Equal to TempMoneyValue[2])
            Then - Actions
                Game - Display to (All players) the text: Enough money
                Player - Add (-1 x TempMoneyValue[1]) to (Owner of (Triggering unit)) Current gold
                Player - Add (-1 x TempMoneyValue[2]) to (Owner of (Triggering unit)) Current lumber
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (((Owner of (Triggering unit)) Current gold) Less than TempMoneyValue[1]) and (((Owner of (Triggering unit)) Current lumber) Less than TempMoneyValue[2])
            Then - Actions
                Hero - Drop (Item being manipulated) from (Triggering unit)
                Item - Remove (Item being manipulated)
                Game - Display to (All players) the text: You don't have enou...
            Else - Actions
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
Second condition,
Code:
(((Owner of (Triggering unit)) Current gold) Greater than or equal to TempMoneyValue[1]) and (((Owner of (Triggering unit)) Current lumber) [B]Equal to[/B] TempMoneyValue[2])
The bold part should be Greater than or equal to.
 

garion992

TH.net Regular
Reaction score
17
ahh ok, i changed that and it still didn't worked. I changed the event to a unit aquires an item and this trigger worked:
Code:
Item Cost Off Hand
    Events
        Unit - A unit Acquires an item
    Conditions
        ((Triggering unit) is A Hero) Equal to True
        (Item-class of (Item being manipulated)) Equal to Permanent
    Actions
        Set TempInt = (((Item level of (Item being manipulated)) x 6) x (Integer((Current life of (Item being manipulated)))))
        Set TempMoneyValue[2] = (TempInt / 100)
        Set TempMoneyValue[1] = (TempInt - (TempMoneyValue[2] x 100))
        Game - Display to (Player group((Owner of (Triggering unit)))) the text: (Copper Cost:  + (String(TempMoneyValue[1])))
        Game - Display to (Player group((Owner of (Triggering unit)))) the text: (Silver Cost:  + (String(TempMoneyValue[2])))
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (((Owner of (Triggering unit)) Current gold) Less than TempMoneyValue[1]) and (((Owner of (Triggering unit)) Current lumber) Less than or equal to TempMoneyValue[2])
            Then - Actions
                Game - Display to (All players) the text: You don't have enou...
                Hero - Drop (Item being manipulated) from (Triggering unit)
                Item - Remove (Item being manipulated)
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (((Owner of (Triggering unit)) Current gold) Greater than or equal to TempMoneyValue[1]) and (((Owner of (Triggering unit)) Current lumber) Greater than or equal to TempMoneyValue[2])
            Then - Actions
                Game - Display to (All players) the text: Enough money
                Player - Add (-1 x TempMoneyValue[1]) to (Owner of (Triggering unit)) Current gold
                Player - Add (-1 x TempMoneyValue[2]) to (Owner of (Triggering unit)) Current lumber
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (((Owner of (Triggering unit)) Current gold) Less than TempMoneyValue[1]) and (((Owner of (Triggering unit)) Current lumber) Greater than TempMoneyValue[2])
            Then - Actions
                Game - Display to (All players) the text: Enough money -> con...
                Player - Add 100 to (Owner of (Triggering unit)) Current gold
                Player - Add -1 to (Owner of (Triggering unit)) Current lumber
                Player - Add (-1 x TempMoneyValue[1]) to (Owner of (Triggering unit)) Current gold
                Player - Add (-1 x TempMoneyValue[2]) to (Owner of (Triggering unit)) Current lumber
            Else - Actions

so thx, but now if i pick up every item the trigger will fire, wich event do i need to use for if a unit buys an item from shop? unit sell an item (from shop) didnt worked for me...
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top