HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

help with making an event

02-04-2007, 07:52 AM#1
Akuda
Hi i was wondering if anyone here could help me with a trigger. I'm trying to make one that makes it so whenever a unit type comes within a range of building type it activates the trigger but i can't seem to figure out how to do an event like that
02-04-2007, 09:22 AM#2
Pyrogasm
I'd assume you'll have to do it by dynamically creating regions whenever a building of your unit-type enters the map area. How you'd go about doing that, however, is beyond me, since I don't understand the difference between a region and a rect (which is what you'd be dynamically creating).

For this, you're going to need a real JASS-er.

Alternatively, I suppose you could run a constant check around each of these units to simulate the event... let me think about that.
02-04-2007, 09:53 AM#3
Akuda
Ok thanks man
02-04-2007, 10:38 AM#4
Pyrogasm
Try this on for size; an example for when a Footman comes within 200.00 of a Guard tower:
Trigger:
Untitled Trigger 001
Collapse Events
Time - Every 0.25 seconds of game time
Conditions
Collapse Actions
Set Check_Group[2] = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Guard Tower))
Collapse Unit Group - Pick every unit in Check_Group[2] and do (Actions)
Collapse Loop - Actions
Set Check_Point[1] = (Position of (Picked unit))
Set Check_Group[3] = (Units within 200.00 of Check_Point[1] matching ((Unit-type of (Matching unit)) Equal to Footman))
Unit - Set the custom value of (Picked unit) to (Number of units in Check_Group[3])
If ((Custom value of (Picked unit)) Equal to 0) then do (Unit Group - Remove (Picked unit) from Near_Group) else do (Do nothing)
Custom script: call RemoveLocation( udg_Check_Point[1] )
Custom script: call DestroyGroup( udg_Check_Group[3] )
Custom script: call DestroyGroup( udg_Check_Group[2] )
Set Check_Group[2] = (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Equal to Guard Tower) and (((Custom value of (Matching unit)) Greater than 0) and (((Matching unit) is in Near_Group) Equal to False))))
Collapse Unit Group - Pick every unit in Check_Group[2] and do (Actions)
Collapse Loop - Actions
Unit Group - Add (Picked unit) to Near_Group
Collapse For each (Integer A) from 1 to (Custom value of (Picked unit)), do (Actions)
Collapse Loop - Actions
Unit Group - Add (Picked unit) to Near_Group
-------- Your actions here --------
Game - Display to (All players) the text: Entering!
Custom script: call DestroyGroup( udg_Check_Group[2] )
The only downside to it is that once a Footman comes near a guard tower, the trigger no longer fires for any more footman coming near that tower until all footman near it move away.

My first attempt

This is what I'd originally tried, though it leaks 2 x (Number of footmen on map) regions. Ouch. That, and it doesn't work completely properly.
Trigger:
Untitled Trigger 001 Copy
Collapse Events
Time - Every 0.25 seconds of game time
Conditions
Collapse Actions
Set Check_Group[1] = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Footman))
Set Check_Group[2] = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Guard Tower))
Collapse Unit Group - Pick every unit in Check_Group[2] and do (Actions)
Collapse Loop - Actions
Set Check_Integer = (Check_Integer + 1)
Set Check_Point[Check_Integer] = (Position of (Picked unit))
Set Check_Unit[Check_Integer] = (Picked unit)
Set Check_Integer = 0
Collapse Unit Group - Pick every unit in Check_Group[1] and do (Actions)
Collapse Loop - Actions
Collapse For each (Integer A) from 1 to (Number of units in Check_Group[2]), do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
((Region centered at Check_Point[(Integer A)] with size (400.00, 400.00)) contains (Picked unit)) Equal to False
Collapse Then - Actions
Unit Group - Remove Check_Unit[(Integer A)] from Near_Group
Else - Actions
Collapse For each (Integer A) from 1 to (Number of units in Check_Group[2]), do (Actions)
Collapse Loop - Actions
Custom script: call RemoveLocation( udg_Check_Point[GetForLoopIndexA()] )
Custom script: set udg_Check_Unit[GetForLoopIndexA()] = null
Custom script: call DestroyGroup( udg_Check_Group[1] )
Custom script: call DestroyGroup( udg_Check_Group[2] )
-------- The above part removes units from "Near_Group"; these two sections are not the same --------
Set Check_Group[1] = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Footman))
Set Check_Group[2] = (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Equal to Guard Tower) and (((Matching unit) is in Near_Group) Equal to False)))
Collapse Unit Group - Pick every unit in Check_Group[2] and do (Actions)
Collapse Loop - Actions
Set Check_Integer = (Check_Integer + 1)
Set Check_Point[Check_Integer] = (Position of (Picked unit))
Set Check_Unit[Check_Integer] = (Picked unit)
Set Check_Integer = 0
Collapse Unit Group - Pick every unit in Check_Group[1] and do (Actions)
Collapse Loop - Actions
Collapse For each (Integer A) from 1 to (Number of units in Check_Group[2]), do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
((Region centered at Check_Point[(Integer A)] with size (400.00, 400.00)) contains (Picked unit)) Equal to True
Collapse Then - Actions
Unit Group - Add Check_Unit[(Integer A)] to Near_Group
-------- Do your actions here --------
Game - Display to (All players) the text: Entering!
Else - Actions
Collapse For each (Integer A) from 1 to (Number of units in Check_Group[2]), do (Actions)
Collapse Loop - Actions
Custom script: call RemoveLocation( udg_Check_Point[GetForLoopIndexA()] )
Custom script: set udg_Check_Unit[GetForLoopIndexA()] = null
Custom script: call DestroyGroup( udg_Check_Group[1] )
Custom script: call DestroyGroup( udg_Check_Group[2] )

02-04-2007, 01:31 PM#5
Akuda
Ok thanks, i'll try that
02-05-2007, 04:50 AM#6
Mythic Fr0st
>>Pyrogasm

Would you not just use the event

"A unit comes within range of x of Your_Unit"

Example

Trigger:
Collapse Event
- A unit finishes construction
Conditions unit type of triggering unit equal to "Building"
Collapse Actions
- add to Activate Trig the event A unit comes within range of 400 of triggering unit

Trigger:
Activate Trig
Collapse Event
- (Added from above)
Collapse Conditions
- Unit type of triggering unit equal to "Building Activator"
Collapse Actions
- Run Your_Trigger checking conditions

That should work...

I interpreted what he wrote as "I need a trigger to run when a unit comes near it" I'm quite sure if that's what he meant or not though
02-05-2007, 05:11 AM#7
Pyrogasm
You could make events for the trigger to fire, but only if the units were pre-placed . If the units can be created in-game, then there's no way to add an event to the trigger this.

Even this does not work, because you can't select "Triggering Unit" for the unit to add the action for:
Trigger:
Collapse Events
Unit - A unit enters (Playable Map Area)
Collapse Conditions
Unit-type of (Triggering unit) equal to Guard Tower
Collapse Actions
Trigger - Add to (Your Trigger <gen>) the event (Unit - A unit comes within 200 of (Triggering unit)
02-06-2007, 02:21 AM#8
wantok
Can't you use Entering Unit?

Trigger:
Collapse Events
Unit - A unit enters (Playable map area)
Conditions
Collapse Actions
Trigger - Add to (YourTrigger) the event (Unit - A unit comes within x of (Entering unit))
02-06-2007, 02:30 AM#9
Mythic Fr0st
Trigger:
Collapse Event
Unit - A unit enters (Playable Map Area)
Collapse Conditions
Unit-type of (Triggering unit) equal to Guard Tower
Collapse Actions
Trigger - Add to (Your Trigger <gen>) the event (Unit - A unit comes within 200 of (Triggering unit)

Does actually work

As I use it in my ORPG

Adding the event
Say the unit's name was Rock 001
When you actually add the event, it adds a unit comes within 200 of (Rock 001 <gen>)

To Any trigger, it does work because I use it in my ORPG to "display" the damage delt, each attack, in which it works perfectly

Quote:
You could make events for the trigger to fire, but only if the units were pre-placed . If the units can be created in-game, then there's no way to add an event to the trigger this.

Not so, cause this will work

Trigger:
Collapse Events
Map initilization
Conditions
Collapse Actions
Unit - Create 1 footman at center of playable map area for player 1 red facing 270.00 degrees
Trigger - Add to (TheTrig <gen>) the event (Unit - A unit comes within 200 of (Last created unit)

TheTrig
Trigger:
Event
Conditions
Collapse Actions
Unit - Kill triggering unit

The trigger "TheTrig" would kill any unit that came near the footman, originally created in the trigger above "TheTrig", test it if you dont belive me ^_^
02-07-2007, 12:07 AM#10
Pyrogasm
I really don't believe you, but I suppose I should take your word for it. The reason I'm saying it won't work is because the "A Unit comes within range of Unit" event requires a unit variable (The 'pick a unit' button) to work.

GetLastCreatedUnit() (Otherwise known as "last created Unit") is not a variable, it is a function.
02-07-2007, 02:11 AM#11
Ammorth
It does work. The event requires a unit. GetLastCtraedUnit() returns a unit. Everything is kosher. But that being said, it only takes a single unit. That means if GetLastCreatedUnit() starts returning a different unit, the event won't update. It will still reference the unit set to the event.

The problem that appears is that many events (1 for each unit that appears in your map) will be on the same trigger. And events take up memory.
02-07-2007, 02:12 AM#12
Mythic Fr0st
Yes, but thats only when manually selecting the event

When you "add" from a trigger it works

I have done this millions of times, in maps such as Mythical Fr0st Maker, Even my ORPG which is fully working, and many other maps...


Trigger:
Collapse Event
Unit - A unit comes within range of 75 of Froglord
Collapse Conditions
Unit type of triggering unit equal to frogman
Collapse Actions
Trigger - Add to KillFrogman the event A unit comes within range of triggering unit

Which is basically saying, A unit comes within range of (That specific frogman)

Test it, it works 100%, preferably not that trigger... lol

Thats how escape maker works, when a unit is trained, it adds trigger, that a unit comes within X of that unit...
02-07-2007, 02:15 AM#13
Pyrogasm
Sue me and my pessimism. Here's what it breaks down to:
  • Mythic Fr0st is a smart man.
  • I am a dumb man.
02-07-2007, 04:44 AM#14
Mythic Fr0st
Quote:
Sue me and my pessimism. Here's what it breaks down to:

* Mythic Fr0st is a smart man.

* I am a dumb man.

Naa your not dumb

* << not a man yet

lol