Little problem with addin - gold.

Ritmas

New Member
Reaction score
0
So basicly what I want to do is aaahm... I don't know how to explain. I'll give an example.

I have a unit [citizen] and he has a spell, when he activates he runs to townhall and gets replaced with Worker. But to cast the spell you pay 20g.
So everything works when only one citizen is selected, but when 2citizen are selected and cast it cost me not 40gold but 60gold, and if 3citizen it costs 120g or w/e.

I hope you get what I say. ;)
Here is my code:

Trigger:
  • Player - Add ((Number of units in Become_a_worker) x -20) to Player 1 (Red) Current gold


If you need whole trigger, ask. ;)
 

Ritmas

New Member
Reaction score
0
Trigger:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to (==) Become a worker
    • Actions
      • Unit - Change ownership of (Casting unit) to Player 2 (Blue) and Retain color
      • Unit Group - To Become_a_worker add units of player Player 2 (Blue) matching ((Unit-type of (Casting unit)) Equal to (==) Citizen (Male))
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Player 1 (Red) Current gold) Greater than or equal to (>=) ((Number of units in Become_a_worker) x 20)
          • Then - Actions
            • Player - Add ((Number of units in Become_a_worker) x -20) to Player 1 (Red) Current gold
            • Unit Group - Pick every unit in Become_a_worker and do (Actions)
              • Loop - Actions
                • Unit - Turn collision for (Casting unit) Off
                • Unit - Order (Casting unit) to Move To (Position of (First unit of group townhall))
          • Else - Actions
            • Unit - Change ownership of (Casting unit) to Player 1 (Red) and Change color
            • Quest - Display to (All players controlled by a ((Owner of (Casting unit)) controller) player) the Quest Update message: Not enough gold.
            • Sound - Play Error <gen>
            • Unit Group - Remove all units of Become_a_worker from Become_a_worker


second trigger:

Trigger:
  • Untitled Trigger 001 Copy
    • Events
      • Unit - A unit comes within 100.00 of Encampment 0000 <gen>
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to (==) Citizen (Male)
      • (Owner of (Triggering unit)) Equal to (==) Player 2 (Blue)
    • Actions
      • Unit - Replace (Triggering unit) with a Worker using The new unit's max life and mana
      • Unit - Change ownership of (Last replaced unit) to Player 1 (Red) and Change color
      • Unit Group - Remove all units of Become_a_worker from Become_a_worker




It's just for testing, so it could have leaks and look fugly, but nvm.

P.S Any tip for making it better would be grateful. ;)
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
I have no idea... What's the relationship between selecting and casting?
 

Ritmas

New Member
Reaction score
0
I have no idea... What's the relationship between selecting and casting?

I mean I have 2citizens selected and make them cast same spell [like having multiple Footmen to cast defend] and insteed of costing 40g it cost 60g and w/e
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Ah. I know the problem. The spell is actually not casted together, at the same time. What warcraft is actually doing is casting the spell for unit 1, then casting for unit 2. If you look closely, the values are simple.

1 unit = 1unit gold
2 unit = 1 unit + 2 unit gold
3 unit = 1 unit + 2 unit + 3 unit gold

In other words, while the trigger is running for the first unit, 20 gold is already deducted, but before it is removed from the unit group, the spell cast from the other unit already deducted 40 gold, because there were 2 units in the unit group.


Edit: Okay, after further analysing, I'm wrong. The problem is, you're doing this ONLY in the else part, you're supposed to also do this in the then part.

Trigger:
  • Unit Group - Remove all units of Become_a_worker from Become_a_worker


Which means the trigger ran twice, first unit deducted, but first unit was not removed from the unit group, and trigger ran for the second time, counting 2 units, thus 60 gold.
 

Ritmas

New Member
Reaction score
0
Thanks for quick replies.
But where to put that action?
Anyway your suggestion doesn't work with my logic, but I can't explain it.
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Okay I posted a whole lot of useless junk there. Now what you're doing is:

Adding the unit to a unit group, removing the unit only if you have not enough money. If you have enough money, do not remove the unit from the unit group.

So the solution would be to remove the units from the unit group even if you have the money.

Now this line, it removes the units from the unit group, am I right?
Trigger:
  • Unit Group - Remove all units of Become_a_worker from Become_a_worker


Put this in the "If/Then/Else" part of trigger, so that when you ahve the gold, your unit is also remvoed from the unit group.

The final trigger should be this:

Trigger:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to (==) Become a worker
    • Actions
      • Unit - Change ownership of (Casting unit) to Player 2 (Blue) and Retain color
      • Unit Group - To Become_a_worker add units of player Player 2 (Blue) matching ((Unit-type of (Casting unit)) Equal to (==) Citizen (Male))
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Player 1 (Red) Current gold) Greater than or equal to (>=) ((Number of units in Become_a_worker) x 20)
          • Then - Actions
            • Player - Add ((Number of units in Become_a_worker) x -20) to Player 1 (Red) Current gold
            • Unit Group - Pick every unit in Become_a_worker and do (Actions)
              • Loop - Actions
                • Unit - Turn collision for (Casting unit) Off
                • Unit - Order (Casting unit) to Move To (Position of (First unit of group townhall))
            • Unit Group - Remove all units of Become_a_worker from Become_a_worker
          • Else - Actions
            • Unit - Change ownership of (Casting unit) to Player 1 (Red) and Change color
            • Quest - Display to (All players controlled by a ((Owner of (Casting unit)) controller) player) the Quest Update message: Not enough gold.
            • Sound - Play Error <gen>
            • Unit Group - Remove all units of Become_a_worker from Become_a_worker
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
If you don't mind, could you upload your map? Though you can try removing casting unit from the unit group instead, first.
 

Ayanami

칼리
Reaction score
288
Firstly, you could use "Starts the effect of an ability" rather than "Beings casting an ability". From what I understand, you basically want the ability to cost 20 gold on-use. And if there is insufficient gold, you won't be able to cast it. Then, just use this:

Trigger:
  • Become Worker
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Become a worker
    • 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 20
        • Then - Actions
          • Player - Set (Owner of (Triggering unit)) Current gold to (((Owner of (Triggering unit)) Current gold) - 20)
          • Unit - Change ownership of (Triggering unit) to Player 2 (Blue) and Retain color
          • Unit - Turn collision for (Triggering unit) Off
          • Set TempPoint = (Position of (First unit of group townhall))
          • Unit - Order (Triggering unit) to Move To TempPoint
          • Custom script: call RemoveLocation(udg_TempPoint)
        • Else - Actions
          • Player Group - Add (Owner of (Triggering unit)) to TempForce
          • Quest - Display to TempForce the Quest Update message: Not enough gold.
          • Sound - Play Error <gen>
          • Player Group - Remove (Owner of (Triggering unit)) from TempForce


Although an ability is cast at the same time, the trigger runs separately for both units. So if you were to put a message "Hi" in the trigger, you would see that the message "Hi" is displayed twice even though you seemingly cast the ability for 2 units simultaneously.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top