• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Need help making an Event

Status
Not open for further replies.
Level 2
Joined
Jul 20, 2004
Messages
27
I need an event that goes something like this.

Unit enters range of unit type X



This can't be done with GUI since it only alloweds specific units to be used for such an event and not a unit type.

Also it would be nice if I could get some help with the condition and action. I need it do something like this


If no other units owned by the owner of the approached unit is within distance (same range as the range on the event), then transfer ownership of approached unit to the owner of the approaching unit.


Thanks in advance
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
JASS:
function UnitFilter takes nothing returns boolean
    return GetUnitTypeId() == <Your Rawcode Here>
endfunction
function UnitFilter2 takes nothing returns boolean
    return not (GetUnitTypeId() == <The Same RawCode>)
endfunction
function Periodic takes nothing returns nothing
    local group g = CreateGroup()
    local unit u = null
    call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, Filter(function UnitFilter))
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        call GroupEnumUnitsInRange(udg_TempGroup, GetUnitX(u), GetUnitY(u), <range>, Filter(function UnitFilter2))
        call TriggerExecute(gg_trg_UnitsInRangeTrigger)
        call DestroyGroup(udg_TempGroup)
        call GroupRemoveUnit(g,u)
    endloop
    set g = null
    set u = null
endfunction
function InitTrig_UnitsInRangeJass takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEvent(t, 0.5, true)
    call TriggerAddAction(t, function Periodic)
    set t = null
endfunction

Make 1 trigger called 'UnitsInRangeJass' and put this script in it.
(Convert to JASS first by: 'Edit > Convert to custom script')
Make another trigger called 'UnitsInRangeTrigger' and put the actions you like in it.
Make one Group variable called 'TempGroup'

In the trigger 'UnitsInRangeTrigger' you put the actions you want. The units which are in range are in the group 'TempGroup'

There are 3 things you need to change:
1) In my JASS script i put '<Your Rawcode Here>' , change this to the Rawcode of you Unit Type
2) Once more, i put '<The Same RawCode>' in the script, change it to the same Rawcode.
3) in the script i have put '<range>' , change it to the desired range

Hope this works out.
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
For the first requirement try picking units within the range you want and check the distance between your unit and the picked units that match your matching type.

For the second requirement, plz give some time to think about it.

<<EDIT>>

Oohh ... forget everything I wrote Yixx told you, use it if you are familiar with JASS.
 
Level 2
Joined
Jul 20, 2004
Messages
27
Okay I have no idea if the above will help me, so I'll explain what I need it for.

I need it to be a universe trigger for a RISK game. So that when someone enters the circle (the approached unit), and there is none of the owners units in it, then it will switch ownership to the entering units owner.

Now the reason I want to use the in range instead of regions, is that i don't see how you can make a universe trigger that way.

Will the trigger made above be useful for this purpose?

Thanks for the effort tho mate :) I just haven't a clue about what it actually does, as my JASS is very poor, thats why I ask here


EDIT: I'm getting a "Not enough arguments passed to function" on line 2 and 5
 
Last edited:
Level 2
Joined
Jul 20, 2004
Messages
27
I hope this works; its a bit vauge

  • RISK
    • Events
      • Unit - A unit enters RISK Circle <gen>
    • Conditions
      • (RISK Circle <gen> contains No unit) Equal to True
    • Actions
      • Unit - Change ownership of Circle of Power (large) 0000 <gen> to (Owner of (Entering unit)) and Change color

Problem with that is that when something like that, I'd have to make one, for every territory in the map, which could be bordering in 150-200. Thats alot of triggers :p
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
Array variables?

Yes, indexed variable.

Example:

You have 5 regions.

Create a variabale (lets say "Region")and select the array check box. Then in the action set the following:

Set Region[1] = Area 001 <gen>
Set Region[2] = Area 002 <gen>
Set Region[3] = Area 003 <gen>
Set Region[4] = Area 004 <gen>
Set Region[5] = Area 005 <gen>

if you now create a loop lets say its index is A, that loop is cycling through 1 to 5.

if you say

Move UNIT to Region[A], at the moment A = 1 then the unit will move to Region[1] (which is equal to Area 001 <gen>) and when the index A = 2 then Region[A] is now Region[2] (which is equal to Area 002 <gen>) and so on till index A = 5.
 
Level 2
Joined
Jul 20, 2004
Messages
27
Yes, indexed variable.

Example:

You have 5 regions.

Create a variabale (lets say "Region")and select the array check box. Then in the action set the following:

Set Region[1] = Area 001 <gen>
Set Region[2] = Area 002 <gen>
Set Region[3] = Area 003 <gen>
Set Region[4] = Area 004 <gen>
Set Region[5] = Area 005 <gen>

if you now create a loop lets say its index is A, that loop is cycling through 1 to 5.

if you say

Move UNIT to Region[A], at the moment A = 1 then the unit will move to Region[1] (which is equal to Area 001 <gen>) and when the index A = 2 then Region[A] is now Region[2] (which is equal to Area 002 <gen>) and so on till index A = 5.

Alright, I have done that now, however still can't pick the variable in the Event "unit enter region". Am I misunderstanding something?

And what do you mean by loop? do you mean like having an action lowest in the trigger, ordering it run itself again, until some condition is met?
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
Alright, I have done that now, however still can't pick the variable in the Event "unit enter region". Am I misunderstanding something?

Yes, you are probably right; I forget about that

And what do you mean by loop? do you mean like having an action lowest in the trigger, ordering it run itself again, until some condition is met?

Not exactly.

In GUI
loop is a cycling through integers: For every A = 1 to n do some actions this means that when the trigger event is registered and the conditions are true the actions inside the loop is reapeated n times and the loop will exit when A = n

In JASS
loops will exit when a ceratain conditions are true which is better because in GUI you are limited to the integers and at a ceratian time you will reach that integer but in JASS you could make a condition that will never be true causing the actions in the loop to run infinite times.

More precise example about loop:

You have 2 triggers:
  • Trigger A
    • Events
      • A unit enters a region
    • Conditions
      • Entering unit == YOUR_UNIT
  • Actions
    • For each (Integer A) from 1 to 10, do (Actions)
      • Loop - Actions
        • Trigger - Run Trigger <gen> (checking conditions)
This will cause Trigger B to run 10 times

I think your request can be done using a timer that will run a loop checking all you circle then pick every unit inside the region and see if they all are of the same owner.
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
So what do I do now?

You will need a timer lets say every 0.5 sec, this will be the event.

In the actions, you create a loop from 1 to (Number of Cricles) and inside the loop action create conditions and actions as if you have a single circle but note that the variable will be array and its index will be the same index of the loop (if the loop index is A then a the variable must be VARIABLE[A]) but avoid waits inside a loop; you actions must be instant.
 
Status
Not open for further replies.
Top