• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

A couple problems.

Status
Not open for further replies.
Level 5
Joined
May 27, 2007
Messages
162
So, first of all, hello. I (according to my profile) joined this community in May 2007... So here I am almost 3 years later, warming up my worldEdit hands in eager anticipation for Starcraft II and the Galaxy Editor...

Anyways,

First, I want a building (Factory) to cast Select User (called Shop Sharing in the abilities>object editor), on itself as the map initializes. I can't get this to work.

The ability is the one that chooses which unit/hero gets the items you buy from that shop.

The trigger I'm trying to use is

on Map initialization
pick every unit equal to type "Factory"
order Picked Unit to 'order string' Picked Unit.

I've tried every imaginable 'order string', adjusting the ability accordingly and can't get this to work...

Secondly, is there a neat way to 'pick nearest building equal to this type'.

What I'm trying to do is make a unit collect a resource (which is an item), which he acquires upon attacking a certain other unit type...

So,

Unit is attacked,
Attacked unit = wreckage
attacking unit = scavenger

if attacking units inventory = full then
order attacking unit to move to nearest factory (HOW DO I DO THIS?)
else
create 1 'scrap metal' and give it to Attacking Unit.

I've sort of worked around the inventory idea, by just making a destructible called Wreckage, and he just acts like a Peon and cuts it down.. But I really want the inventory way to work.

thanks for your time.
 
1) The order string is "neutralinteract" or "852566"
So, either use
  • Custom script: call IssueTargetOrder (GetEnumUnit(), "neutralinteract", GetEnumUnit())
or
  • Custom script: call IssueTargetOrderById (GetEnumUnit(), 852566, GetEnumUnit())
Notice, in order to target itself, the building must have an inventory! Go to your building and add the "Inventory (Human)" ability.
 
Level 5
Joined
May 27, 2007
Messages
162
Yeah, I've got the unit to have an inventory :p...

Now, what do I do with this?

"Custom script: call IssueTargetOrderById (GetEnumUnit(), 852566, GetEnumUnit())"

I have no JASS knowledge or experience, but I understand that this is calling a function which returns a unit, to do '852566' which is the ability I want to use, on another function which returns a unit. Presumably the functions return the picked unit, and the syntax ,######, just states what Subject DOES to Object?

How do I put this into my triggers? Sorry I'm noob :)
 
They actually return a boolean, which is a true or a false statement.
GetEnumUnit() is the "Picked unit" from GUI. The call is the "Unit - Order unit targeting a unit", but, through the custom script, we are more free of using various orders, which GUI limits us from.
To use the action I just described, go to Actions, scroll to "Custom script" and type "call Issue..." (the function I told you about).
 
Level 5
Joined
May 27, 2007
Messages
162
Cool thanks, +rep...

What about my second problem? Pick all units, and calculate the nearest one, then order a unit to go there?

I'll try work on it now!

Thx again
 
Level 13
Joined
Sep 14, 2008
Messages
1,407
Easiest way to get the nearest building is this:

TempUnit = random unit in playable map area of type X (the one you are looking for)

Pick every unit of type X in playable map area and do actions:

If(Distance between YourUnit and PickedUnit < Distance between YourUnit and TempUnit)
Then: Set TempUnit = PickedUnit
 
Level 5
Joined
May 27, 2007
Messages
162
Haha... Want to see what I was trying to do? Man I got myself so confused...

  • Untitled Trigger 002
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacked unit)) Equal to Wreckage
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item carried by (Attacking unit) in slot 6)) Equal to Cheese
        • Then - Actions
          • Unit - Set life of (Attacked unit) to ((Life of (Attacked unit)) + 5.00)
          • Set factoryCount = 0
          • Set distanceCalc = 1000
          • Unit Group - Pick every unit in (Units in (Playable map area) matching (((Unit-type of (Picked unit)) Equal to Factory) and ((Owner of (Picked unit)) Equal to (Owner of (Attacking unit))))) and do (Actions)
            • Loop - Actions
              • Set factoryCount = (factoryCount + 1)
              • Set currentFactArray[factoryCount] = (Picked unit)
          • For each (Integer B) from 1 to 20, do (Actions)
            • Loop - Actions
              • Set distanceCalc = (distanceCalc + 1500)
              • For each (Integer A) from 1 to factoryCount, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Integer((Distance between (Position of (Attacking unit)) and ((Position of currentFactArray[(Integer A)]) offset by (0.00, 0.00))))) Less than or equal to distanceCalc
                    • Then - Actions
                      • Unit - Order (Attacking unit) to Move To ((Position of currentFactArray[(Integer A)]) offset by (0.00, 0.00))
                    • Else - Actions
                      • Do nothing
        • Else - Actions
          • Hero - Create Cheese and give it to (Attacking unit)

Edit: thx fixed
 
Last edited:
  • Unit Group - Pick every unit in (Units in (Playable map area) matching (((Unit-type of (Picked unit)) Equal to Factory) and ((Owner of (Picked unit)) Equal to (Owner of (Attacking unit))))) and do (Actions)
When you use "Matching", the unit you compare should be "Matching unit". "Picked unit" is only used after you pick the units. So, the trigger above should be:
  • Unit Group - Pick every unit in (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Equal to Factory) and ((Owner of (Matching unit)) Equal to (Owner of (Attacking unit))))) and do (Actions)
For the GetClosestUnit() function you want, you can either get this:
http://www.hiveworkshop.com/forums/jass-functions-413/getclosestunit-s-59254/

Or make a comparison if the Distance between attacking unit and the other unit is less than or equal to 99999.00.

To use GUI tags, simply add [ trigger ] [ / trigger] in the beginning and in the end of your trigger respectively (without the spaces).
 
Level 13
Joined
Sep 14, 2008
Messages
1,407
In the advanced editor is a trigger script.

[ TRIGGER][/ TRIGGER] (without spaces)

Edit:

In your code is an error. When using "matching" condition you don't use "picked unit" but "matching unit".

Something like this:

Yours:
Unit Group - Pick every unit in (Units in (Playable map area) matching (((Unit-type of (Picked unit)) Equal to Factory) and ((Owner of (Picked unit)) Equal to (Owner of (Attacking unit))))) and do (Actions)

Correct:
Unit Group - Pick every unit in (Units in (Playable map area) matching (((Unit-type of (matching unit)) Equal to Factory) and ((Owner of (Matching unit)) Equal to (Owner of (Attacking unit))))) and do (Actions)
 
Level 5
Joined
May 27, 2007
Messages
162
Thanks again to you both, trying now with my code fixed. If that still fails, i'll resort to your neater and much easier methods!

+rep x2
 
Level 5
Joined
May 27, 2007
Messages
162
  • Untitled Trigger 002
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacked unit)) Equal to Wreckage
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Item carried by (Attacking unit) in slot 6) is owned) Equal to True
        • Then - Actions
          • Set factoryCount = 0
          • Unit Group - Pick every unit in (Units owned by (Owner of (Attacking unit)) matching ((Unit-type of (Matching unit)) Equal to Factory)) and do (Actions)
            • Loop - Actions
              • Set factoryCount = (factoryCount + 1)
              • Set factoryArray[factoryCount] = (Picked unit)
          • For each (Integer A) from 1 to factoryCount, do (Actions)
            • Loop - Actions
              • Unit Group - Pick every unit in (Units owned by (Owner of (Attacking unit)) matching ((Unit-type of (Matching unit)) Equal to Factory)) and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Integer((Distance between (Position of (Attacking unit)) and (Position of (Picked unit))))) Less than (Integer((Distance between (Position of (Attacking unit)) and (Position of factoryArray[(Integer A)]))))
                    • Then - Actions
                      • Unit - Order (Attacking unit) to Move To (Position of (Picked unit))
                    • Else - Actions
                      • Do nothing
        • Else - Actions
          • Hero - Create Cheese and give it to (Attacking unit)
So this is as far as I've gotten.

Atleast the unit doesn't attack the wreckage when he his inventory is full! Any idea's?

Credits will go to you when this map is finished ;)
 
Level 5
Joined
May 27, 2007
Messages
162
  • Untitled Trigger 003
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Scavenger Tank
    • Actions
      • Set testvar = 512
      • Unit Group - Pick every unit in (Units owned by (Owner of (Attacking unit)) of type Factory) and do (Actions)
        • Loop - Actions
          • Set testvar = (testvar + 1024)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Integer((Distance between (Position of (Attacking unit)) and (Position of (Picked unit))))) Less than or equal to testvar
            • Then - Actions
              • Unit - Order (Attacking unit) to Move To (Position of (Picked unit))
            • Else - Actions
              • Do nothing
Or what is the problem with this? In a test run of the map, my unit goes to attack but before the projectile leaves, he gets a move order (the Move icon is 'green') but he doesnt go anywhere.
 
Level 13
Joined
Sep 14, 2008
Messages
1,407
In the first trigger you have the problem that you don't let the loop run through before giving orders.

See the loop I gave you compares the distance between all units and in the end has the nearest one.

You compare all and give the order every time you find one which is nearer than the other one.

  • Untitled Trigger 002
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacked unit)) Equal to Wreckage
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Item carried by (Attacking unit) in slot 6) is owned) Equal to True
        • Then - Actions
          • Set tempUnit = random unit in (Units owned by (owner of attacking unit) matching (Unit-type of (matching unit)) Equal to Factory)).
          • Unit Group - Pick every unit in (Units owned by (Owner of (Attacking unit)) matching ((Unit-type of (Matching unit)) Equal to Factory)) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Integer((Distance between (Position of (Attacking unit)) and (Position of (Picked unit))))) Less than (Integer((Distance between (Position of (Attacking unit)) and (Position of TempUnit))))
                • Then - Actions
                  • Set tempUnit = Picked unit
                • Else - Actions
                  • Do nothing
              • Order - attacking unit to attack tempUnit
        • Else - Actions
          • Hero - Create Cheese and give it to (Attacking unit)
 
Status
Not open for further replies.
Top