Unit Gives Uniy Gold Gives Player Gold

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
It's perfectly possible to put a "pick every unit" loop inside another "pick every unit" loop.
But, obviously, the "Picked unit" in the inner loop will be different from the "Picked unit" in the outer loop.


"Set <whatever>Group = units of type" isn't needed.
You already have two triggers that fill in those groups as the units are created.


The "player" loop is not needed.
Simply remember the position and the owner of the "picked unit" in the first loop,
and compare that player to the owner of the "picked unit" in the second loop.
If both are the same and the distances are "close enough" or not, then ... do something.
 
I

IKilledKEnny

Guest
AceHart, would this work:

Code:
Untitled Trigger 004
    Events
        Time - Every 1.00 seconds of game time
    Conditions
    Actions
        Unit Group - Pick every unit in GathererGroup and do (Actions)
            Loop - Actions
                Set GathererPoint = (Position of (Picked unit))
                Set GoldPlayer = (Owner of (Picked unit))
                Unit Group - Pick every unit in ResourcesWagonGroup and do (Actions)
                    Loop - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                (Owner of (Picked unit)) Equal to GoldPlayer
                            Then - Actions
                                Set ResourcesWagonPoint = (Position of (Picked unit))
                                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    If - Conditions
                                        (Distance between GathererPoint and ResourcesWagonPoint) Less than or equal to 70.00
                                    Then - Actions
                                        Game - Display to (All players) the text: done
                                        Player - Add -10 to GoldPlayer Current gold
                                    Else - Actions
                            Else - Actions

Edit: Just tested it, doesn't work, WHY? :(
 
S

Sunny_D

Guest
i made a trigger that works:

CarrierUnitGroup: You add all trained carriers into this unit group
GoldUnitGroup: You add all trained Gold Gatherers into this unit group
TempUnit and TempUnit2: are unit variables
TempPoint and TempPoint2: are point variables
Custom Values: when a gatherer has gold, then set its custom value to 50

Code:
check range
    Events
        Time - Every 0.50 seconds of game time
    Conditions
    Actions
        Unit Group - Pick every unit in CarrierUnitGroup and do (Actions)
            Loop - Actions
                Set TempUnit = (Picked unit)
                Set TempPoint = (Position of TempUnit)
                Unit Group - Pick every unit in GoldUnitGroup and do (Actions)
                    Loop - Actions
                        Set TempUnit2 = (Picked unit)
                        Set TempPoint2 = (Position of (Picked unit))
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                (Distance between TempPoint and TempPoint2) Less than or equal to 256.00
                                (Custom value of TempUnit2) Equal to 50
                            Then - Actions
                                ----- Your actions: Give Gold, maybe Floating Text above unit, whatever -----
                                Unit - Set the custom value of TempUnit2 to 100
                            Else - Actions
                        Custom script: call RemoveLocation (udg_TempPoint2)
                Custom script: call RemoveLocation (udg_TempPoint)

yea, think that one should work now! ;)
 
I

IKilledKEnny

Guest
Just a quick question before trying that Trigger.

Why did you do this condition:

Code:
(Custom value of TempUnit2) Equal to 50

And why this action:

Code:
Unit - Set the custom value of TempUnit2 to 100
 
S

Sunny_D

Guest
look in the description above:

every time a peasant would have gathered gold, then you set its custom value to 50 (or whatever other number, 50 was random)

if he delievered the gold, you set its custom value to any other number but 50 (i have choosen 100 because its the editor-standart) so you get gold only once. you can set the custom value to 50 again, if he gathered gold again. :)

note: in the sample map i made it - for testing issues - that you can set the custom value by a chat command ;)

oh forgot to enter the condition that its the same player... (just enter "Owner of TempUnit = Owner of TempUnit2" as condition right below (custom value equal to....) in the inner if-then-else ;)
 
I

IKilledKEnny

Guest
Ok I did a little testing and found out that the bolded line doesn't work.

Code:
Untitled Trigger 001
    Events
        [B]Unit - A unit Begins casting an ability[/B]
    Conditions
        (Ability being cast) Equal to Mine (Stone & Gold) 
    Actions
        Unit Group - Add (Triggering unit) to GathererGroup
        Game - Display to (All players) the text: done num1

The ability is just like harvest gold and lumber I just changed the name, what's wrong?
 
S

Sunny_D

Guest
well, as far as i know the gathering button triggers an order not an ability ;)

so i think you would need a trigger with issue-order... so... something like that below... but im not 100% sure though...


Code:
    Events
        Unit - A unit Is issued an order targeting an object
    Conditions
        (Issued order) Equal to Harvest
    Actions

and btw: in case you want use that with my previous trigger... add the units to the unit group "Gatherer Group" when they are trained... and change the custom value to 50 when they have gold. :)
 
I

IKilledKEnny

Guest
Yup. :)

Now just to be sure 100% that I didn't manage to destroy everything again here is the new Trigger, tell me if it's good/bad :D

Code:
Untitled Trigger 001
    Events
        Unit - A unit Is issued an order targeting an object
    Conditions
        (Ability being cast) Equal to Mine (Stone & Gold) 
    Actions
        Unit Group - Add (Triggering unit) to GathererGroup
        Game - Display to (All players) the text: done num1

lol it took 4 pages to get the answer ^^.
 
I

IKilledKEnny

Guest
Never mind, I'm stupid, it's not right, I can't find
Code:
(Issued order) Equal to Harvest
Is it in boleen or where?
 
I

IKilledKEnny

Guest
Oh ok thanks, but I guess this theard is going to be a little longer becuase, how do I define harvest? Didn't find anything about abilities there. So sorry about my being so 'newb'.
 
I

IKilledKEnny

Guest
Wow, just, WOW it still doesn't work!!

Code:
Untitled Trigger 001
    Events
        Unit - A unit Is issued an order targeting an object
    Conditions
        (Unit-type of (Triggering unit)) Equal to Gatherer
    Actions
        Unit Group - Add (Triggering unit) to GathererGroup
        Unit - Set the custom value of (Triggering unit) to 1
        Game - Display to (All players) the text: done num1

Code:
Untitled Trigger 002
    Events
        Unit - A unit Finishes training a unit
    Conditions
        (Unit-type of (Trained unit)) Equal to Resources Wagon
    Actions
        Unit Group - Add (Trained unit) to ResourcesWagonGroup
        Game - Display to (All players) the text: done num2

Code:
Untitled Trigger 004
    Events
        Time - Every 2.00 seconds of game time
    Conditions
    Actions
        Unit Group - Pick every unit in GathererGroup and do (Actions)
            Loop - Actions
                Set GoldUnit = (Picked unit)
                Set GathererPoint = (Position of GoldUnit)
                Unit Group - Pick every unit in ResourcesWagonGroup and do (Actions)
                    Loop - Actions
                        Set GoldUnit2 = (Picked unit)
                        Set ResourcesWagonPoint = (Position of GoldUnit2)
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                (Distance between GathererPoint and ResourcesWagonPoint) Less than or equal to 75.00
                                (Custom value of GoldUnit) Equal to 1
                            Then - Actions
                                Game - Display to (All players) the text: done num3
                                Unit - Set the custom value of GoldUnit to 2
                                Custom script:   call RemoveLocation (udg_ResourcesWagonPoint)
                                Custom script:   call RemoveLocation (udg_GathererPoint)
                            Else - Actions

I give up.... Unless someone can tell me why it doesn't work....
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> Custom script: call RemoveLocation (udg_GathererPoint)

This comes way too early.
It should happen once the inner loop is done.

And, what's the point of that custom value?
It's always 1 anyway.


Add an extra variable, of type player.
Set GoldPlayer = Owner of (Picked unit)
to be put near "Set GoldUnit =".

And replace the custom value test with
Owner of (GoldUnit2) equal to GoldPlayer


> Unit - A unit Is issued an order targeting an object

Are you actually giving it an order?
I thought it should happen just from walking nearby?

Also, 75 is not much of a distance...
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top