• 🏆 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!

[JASS] Difficult Problem (this is not like the other i posted, it is the next level in J

Status
Not open for further replies.
Guys, i have a problem with my reward system...
To explain the reward system in my map rewards the players that train more units.
So every time a player trains 1 unit, i add that unit to a group.
Ex: An Unit owned by Player 1 finishes training a unit > add trained unit yo 'P1_Units_Trained'.

When 'P1_units_trained' reaches 20 (this means that Player 1 trained 20 units), my reward system will be activated and the player will summon a dwarf army in his aid.

Here is the trigger:

JASS:
function army_conds takes nothing returns boolean
     return CountUnitsInGroup(udg_TrainedUnits_P1) == 20  
endfunction
//============================================================================
function army_acts takes nothing returns nothing
        local location m = gg_rct_Region_033
        local location p = gg_rct_p1_workers_start 
        local unit gate = CreateNUnitsAtLoc( 1, 'hprt', Player(0), GetRectCenter(m), bj_UNIT_FACING )
        local effect ef = AddSpecialEffectLoc("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", m)
        local unit m1 = CreateUnitAtLoc(Player(5), 'h014', GetRectCenter(m), 90.00)
        local unit m2 = CreateUnitAtLoc(Player(5), 'h014', GetRectCenter(m), 90.00)
        local unit m3 = CreateUnitAtLoc(Player(5), 'h014', GetRectCenter(m), 90.00)
        local unit m4 = CreateUnitAtLoc(Player(5), 'h014', GetRectCenter(m), 90.00)
        local unit r1 = CreateUnitAtLoc(Player(5), 'hrif', GetRectCenter(m), 90.00)
        local unit r2 = CreateUnitAtLoc(Player(5), 'hrif', GetRectCenter(m), 90.00)
        local unit r3 = CreateUnitAtLoc(Player(5), 'hrif', GetRectCenter(m), 90.00)
        local unit r4 = CreateUnitAtLoc(Player(5), 'hrif', GetRectCenter(m), 90.00)
        local unit h1 = CreateUnitAtLoc(Player(5), 'H015', GetRectCenter(m), 90.00)  
        call TriggerExecute( gg_trg_Army1_text ) 
        call CameraSetTargetNoiseEx(10, 5*Pow(10, 5), true)
        call CameraSetSourceNoiseEx(10, 5*Pow(10, 5), true)
        call GroupPointOrder(GetUnitsInRectAll(m), "move", GetRectCenter(p)) 
        call DestroyEffect(ef)
        call KillUnit( gate )
        call TriggerSleepAction(4.00)
        call SetUnitOwner(m1, Player(0), true)
        call SetUnitOwner(m2, Player(0), true)
        call SetUnitOwner(m3, Player(0), true)
        call SetUnitOwner(m4, Player(0), true)
        call SetUnitOwner(r1, Player(0), true)
        call SetUnitOwner(r2, Player(0), true)
        call SetUnitOwner(r3, Player(0), true)
        call SetUnitOwner(r4, Player(0), true)
        call SetUnitOwner(h1, Player(0), true)
        call CameraSetTargetNoiseEx(0, 0*Pow(0, 0), true)
        call CameraSetSourceNoiseEx(0, 0*Pow(0, 0), true)
        call RemoveLocation(m)
        call RemoveLocation(p)
        set gate = null
        set ef = null
        set m = null
        set p = null
        set m1 = null
        set m2 = null
        set m3 = null
        set m4 = null
        set r1 = null
        set r2 = null
        set r3 = null
        set r4 = null
        set h1 = null
        call DisableTrigger( GetTriggeringTrigger() )
endfunction
//===========================================================================
function Army_P1 takes nothing returns nothing
    local trigger army = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH )
    call TriggerAddCondition(army, Condition(function army_conds))
    call TriggerAddAction( army, function army_acts )
endfunction


I will explain, to start i have to regions: m and p.
1- The number is reached, the camera starts shacking and a text is displayed
2- Create a portal in region m
3- Create the special Town Portal Effect in region m
4- create 9 units in region m for Player 6
5- order those units to move to region p
6- Once the units reach the region, their ownership goes to Player 1
7- Stop shacking the camera


However i have several problems with BJ's and even more problems with the dam locations .... i just don't know how to use them .... yet ..

So what i ask here is if some1 who understands my script to plz help me improve it and, more important, please help me make it work (ya, because it doesn't work).

This is my next level of JASS learning ... as you can see i tried to dismount the Cam BJ's and i think i did it ... Anyway help please ?

Also if you have a better system to keep track of trained units, instead of creating a single UnitGroup for each player, plz share that method with me.
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
JASS:
local location p = gg_rct_p1_workers_start
local location m = gg_rct_Region_033


Wtf??? Isn't gg_rct supposed to be a region/rect?

USE COORDINATES, NOT LOCATIONS!

Instead of calling Player(some integer) 10 times in a row, just do something like:

local player P = Player(0)

And then use that variable instead of calling the same function over and over again.

call TriggerRegisterPlayerUnitEventSimple( army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH)

becomes:

call TriggerRegisterPlayerUnitEvent(army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH, null)

How did you manage to do this:

JASS:
function Army_P1 takes nothing returns nothing  local trigger army = CreateTrigger( )  call TriggerRegisterPlayerUnitEventSimple( army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH )  call TriggerAddCondition(army, Condition(function army_conds))  call TriggerAddAction( army, function army_acts ) endfunction
?


A normal WE would return a sintax error on this one, because it has to have InitTrig_ before it.

Anyways, I think it's pointless to make a local trigger if there's already a global variable for it (gg_trg_something) plus it disables the usage of EnableTrigger/DisableTrigger from other triggers. Because, if using your way, that trigger is unreachable.

Instead of doing:

call GroupPointOrder(GetUnitsInRectAll(m), "move", GetRectCenter(p))

you can do this:

JASS:
local rect m = gg_rct_Region_033
local group g = CreateGroup()
local unit u
call GroupEnumUnitsInRect(g, m, null)
loop
    set u = FirstOfGroup(g)
    exitwhen u == null
    call GroupRemoveUnit(g, u)
    call IssuePointOrder(u, "move", GetRectCenterX(m), GetRectCenterY(m))
endloop
call DestroyGroup(g)


This way you get read of BJs and big leaks. Plus, you set a rect to gg_rct, not location! :)

local unit m1 = CreateUnitAtLoc(Player(5), 'h014', GetRectCenter(m), 90.00)

Becomes:

local unit m1 = CreateUnit(Player(5), 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)

And what kind of indentation is that?

I don't see where you use udg_TrainedUnits_P1 so I can't help you with that.

It seems like this script hasn't passed the sintax checker yet :p

You're lucky I like optimizing........I think this has been my longest reply yet
 
Ya thx for your reply Silvernon, and no, this trigger did not passed the syntax checker.

1. gg_rct = yes it is a region. I would like to remove this regions and use other method that doesn't need them, but i don't know of any.
2. How do i use coordinates ?? never did it before ...
3. About indenting, i know my indenting is horrible, but i don't know hoe to indent correctly ... I am still new at JASS and i am doing my best to learn it, can you please give some advice about indenting ?

About udg_TrainedUnit_P1, i will post the code. As you will see, these two triggers are connected.

Script Code Improvement:

JASS:
function army_conds takes nothing returns boolean
     return CountUnitsInGroup(udg_TrainedUnits_P1) == 20  
endfunction
//============================================================================
function army_acts takes nothing returns nothing
        local unit t = GetTrainedUnit()
        call GroupAddUnit(udg_TrainedUnits_P1, t)
        set t = null
        if army_conds = true then 
        local rect m = gg_rct_Region_033
        local group g = CreateGroup()
        local unit f
        local location p = gg_rct_p1_workers_start
        local player pg = Player(5)
        local player pr = Player(0) 
        local unit gate = CreateNUnitsAtLoc( 1, 'hprt', Player(0), GetRectCenter(m), bj_UNIT_FACING )
        local effect ef = AddSpecialEffectLoc("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", m)
        local unit m1 = CreateUnitAtLoc(pg, 'h014', GetRectCenterX(m), GetRectCenterY(y), 90.00)
        local unit m2 = CreateUnitAtLoc(pg, 'h014', GetRectCenterX(m), GetRectCenterY(y), 90.00)
        local unit m3 = CreateUnitAtLoc(pg, 'h014', GetRectCenterX(m), GetRectCenterY(y), 90.00)
        local unit m4 = CreateUnitAtLoc(pg, 'h014', GetRectCenterX(m), GetRectCenterY(y), 90.00)
        local unit r1 = CreateUnitAtLoc(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)
        local unit r2 = CreateUnitAtLoc(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)
        local unit r3 = CreateUnitAtLoc(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)
        local unit r4 = CreateUnitAtLoc(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)
        local unit h1 = CreateUnitAtLoc(pg, 'H015', GetRectCenterX(m), GetRectCenterY(m), 90.00)  
        call DisplayTextToForce( GetPlayersAll(), ( "The First Northrend Army arrived to aid " + ( udg_Player_Colors[GetConvertedPlayerId(GetOwningPlayer(GetTrainedUnit()))] + ( GetPlayerName(GetOwningPlayer(GetTrainedUnit())) + "|r and his alliance !!!!! " ) ) ) )
        call CameraSetTargetNoiseEx(10, 5*Pow(10, 5), true)
        call CameraSetSourceNoiseEx(10, 5*Pow(10, 5), true)
        call GroupEnumUnitsInRect(g, m, null)
             loop
             set f = FirstOfGroup(g)
             exitwhen f == null
             call IssuePointOrder(f, "move", GetRectCenterX(m), GetRectCenterY(m))
             call GroupRemoveUnit(g, f)
             endloop
        call DestroyGroup(g)
        call DestroyEffect(ef)
        call KillUnit( gate )
        call TriggerSleepAction(4.00)
        call SetUnitOwner(m1, pr, true)
        call SetUnitOwner(m2, pr, true)
        call SetUnitOwner(m3, pr, true)
        call SetUnitOwner(m4, pr, true)
        call SetUnitOwner(r1, pr, true)
        call SetUnitOwner(r2, pr, true)
        call SetUnitOwner(r3, pr, true)
        call SetUnitOwner(r4, pr, true)
        call SetUnitOwner(h1, pr, true)
        call CameraSetTargetNoiseEx(0, 0*Pow(0, 0), true)
        call CameraSetSourceNoiseEx(0, 0*Pow(0, 0), true)
        call RemoveLocation(m)
        call RemoveLocation(p)
        set gate = null
        set ef = null
        set m = null
        set p = null
        set m1 = null
        set m2 = null
        set m3 = null
        set m4 = null
        set r1 = null
        set r2 = null
        set r3 = null
        set r4 = null
        set h1 = null
        set pg = null
        set pr = null
        set g = null
        call DisableTrigger( GetTriggeringTrigger() )
        endif
endfunction
//===========================================================================
function InitTrig_Army_P1 takes nothing returns nothing
    local trigger army = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEvent( army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH, null )
    call TriggerAddAction( army, function army_acts )
endfunction


Explaining:

Well, every time player 1 (Player(0)) trains an unit, that unit is added to the udg_TrainedUnits_P1 (unit group).
If the udg_TrainedUnits_P1 has 20 units, it will activate the reward system.
The rewards system will than shake the camera using:
JASS:
call CameraSetTargetNoiseEx(10, 5*Pow(10, 5), true)
        call CameraSetSourceNoiseEx(10, 5*Pow(10, 5), true)
and will display the following text using:
JASS:
call DisplayTextToForce( GetPlayersAll(), ( "The First Northrend Army arrived to aid " + ( udg_Player_Colors[GetConvertedPlayerId(GetOwningPlayer(GetTrainedUnit()))] + ( GetPlayerName(GetOwningPlayer(GetTrainedUnit())) + "|r and his alliance !!!!! " ) ) ) )
After that it will create the gate, the units, order them to move and give the units to player 1 after 4 seconds (which i will change soon, i want them to change player when they reach the location, and not after 4 seconds).
After that the camera stops shaking and everything goes back to normal.

I am trying to do this MUI, it means that i would like to make this trigger work for all player, instead of work for only player 1 (i am forced to do 8 equal triggers for my map, plus 8 equal global vars ..)

Silvernon thx for your reply, you were the only 1 who helped me in this huge trigger ... I guess there aren't many people who want to help me reaching the next level of JASS .... i guess i am lucky you are not one of those.

I have done everything you asked me to do ... now i just have to wait for more replies. Btw, if i manage to do this trigger MUI, i will give credit in my map.

Another thing, is you knockback spell Mui and leak free ?? Does it destroys destructibles(like trees) and creates a nice smooth effect when a unit is knocked back ? because i am searching for a knockback spell...
 
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
Aight, here we go...

A) you have to declare locals before anything else, including before you use If-statements

B) You use CreateUnitAtLoc with the CreateUnit parameters. (Just switch 100% to CreateUnit ;), avoids syntax errors + is better)

C) You said if army_conds = true then instead of if army_conds() == true then. However, since the if-statement checks for a true and not necessarily a condition (as does anything else with booleans), ==true can be dropped for this. Also, inlining the army_conds function is preferrable - if CountUnitsInGroup(udg_TrainedUnits_P1) == 20 then is the best.

D) You can replace GetPlayersAll() with the variable bj_FORCE_ALL_PLAYERS

E) Using Pow is a bad idea unless unavoidable, especially when you can just precalculate the result. 10^5 = 100000

F) You seem to be trying to use rects in the place of locs and vice-versa. GetRectCenter(someRect) returns a location, and GetRectCenterX(someRect)+GetRectCenterY(someRect) return the coordinates of the rect's center respectively, for when you need those instead of a rect. You also attempt to put a rect into location p at one point.

Update your code and I'll see if I can catch anything else ;)
 
PurplePoot, the moderator that is always saving my ass in the most complicated scrips =P thx for your reply i really appreciate it.
I read your post i did did all i could ... i think i understood everything. Anyway, here is the reward system:

System improvement:
JASS:
function army_acts takes nothing returns nothing
    local unit t = GetTrainedUnit()
    local rect m = gg_rct_Region_033
    local group g = CreateGroup()
    local unit f
    local location p = gg_rct_p1_workers_start
    local player pg = Player(5)
    local player pr = Player(0) 
    local unit gate = CreateNUnitsAtLoc( 1, 'hprt', Player(0), GetRectCenter(m), bj_UNIT_FACING )
    local effect ef = AddSpecialEffectLoc("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", m)
    local unit m1 = CreateUnitAtLoc(pg, 'h014', GetRectCenterX(m), GetRectCenterY(y), 90.00)
    local unit m2 = CreateUnitAtLoc(pg, 'h014', GetRectCenterX(m), GetRectCenterY(y), 90.00)
    local unit m3 = CreateUnitAtLoc(pg, 'h014', GetRectCenterX(m), GetRectCenterY(y), 90.00)
    local unit m4 = CreateUnitAtLoc(pg, 'h014', GetRectCenterX(m), GetRectCenterY(y), 90.00)
    local unit r1 = CreateUnitAtLoc(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)
    local unit r2 = CreateUnitAtLoc(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)
    local unit r3 = CreateUnitAtLoc(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)
    local unit r4 = CreateUnitAtLoc(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)
    local unit h1 = CreateUnitAtLoc(pg, 'H015', GetRectCenterX(m), GetRectCenterY(m), 90.00)  
        call GroupAddUnit(udg_TrainedUnits_P1, t)
             set t = null
    if CountUnitsInGroup(udg_TrainedUnits_P1) == 20 then 
        call DisplayTextToForce( bj_FORCE_ALL_PLAYERS, ( "The First Northrend Army arrived to aid " + ( udg_Player_Colors[GetConvertedPlayerId(GetOwningPlayer(GetTrainedUnit()))] + ( GetPlayerName(GetOwningPlayer(GetTrainedUnit())) + "|r and his alliance !!!!! " ) ) ) )
        call CameraSetTargetNoiseEx(10, 500000, true)
        call CameraSetSourceNoiseEx(10, 500000, true)
        call GroupEnumUnitsInRect(g, m, null)
    loop
             set f = FirstOfGroup(g)
    exitwhen f == null
        call IssuePointOrder(f, "move", GetRectCenterX(m), GetRectCenterY(m))
        call GroupRemoveUnit(g, f)
    endloop
        call DestroyGroup(g)
        call DestroyEffect(ef)
        call KillUnit( gate )
        call TriggerSleepAction(4.00)
        call SetUnitOwner(m1, pr, true)
        call SetUnitOwner(m2, pr, true)
        call SetUnitOwner(m3, pr, true)
        call SetUnitOwner(m4, pr, true)
        call SetUnitOwner(r1, pr, true)
        call SetUnitOwner(r2, pr, true)
        call SetUnitOwner(r3, pr, true)
        call SetUnitOwner(r4, pr, true)
        call SetUnitOwner(h1, pr, true)
        call CameraSetTargetNoiseEx(0, 0, true)
        call CameraSetSourceNoiseEx(0, 0, true)
        call RemoveLocation(m)
        call RemoveLocation(p)
             set gate = null
             set ef = null
             set m = null
             set p = null
             set m1 = null
             set m2 = null
             set m3 = null
             set m4 = null
             set r1 = null
             set r2 = null
             set r3 = null
             set r4 = null
             set h1 = null
             set pg = null
             set pr = null
             set g = null
        call DisableTrigger( GetTriggeringTrigger() )
    endif
endfunction
//===========================================================================
function InitTrig_Army_P1 takes nothing returns nothing
    local trigger army = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEvent( army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH, null )
    call TriggerAddAction( army, function army_acts )
endfunction


As you can see i tried to improve the indenting ... i don't know if it is correct but, if you don't understand something just tell me and i improve it ...
If you also don't understand the system or what it does, please, read my other posts, as they explain exactly what this system does.
I did all the changes you asked me to do.... i don't mind changing all the system and go back to zero again, as long as it works... Do you think you can help me make this system MUI ??? plz ?
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
First of all, all locals must be declared before anything else, so every local declaration after this:

call GroupAddUnit(udg_TrainedUnits_P1, t)

won't work.

2. How do i use coordinates ?? never did it before ...

A location consists of two coordinates, x and y.

3. About indenting, i know my indenting is horrible, but i don't know hoe to indent correctly ... I am still new at JASS and i am doing my best to learn it, can you please give some advice about indenting ?

There are programs that indent for you, JassCraft would be a good choice. Btw if you don't want to use any programs, indentation is 4 spaces, but I doubt anyone would want to indent every line like that.

local location p = gg_rct_p1_workers_start

Khmm......no.

JASS:
local player pr = Player(0)
local unit gate = CreateNUnitsAtLoc( 1, 'hprt', Player(0), GetRectCenter(m), bj_UNIT_FACING )


No need for calling Player(0) in the second line if you already put it in a variable, just use:

local unit gate = CreateNUnitsAtLoc( 1, 'hprt', pr, GetRectCenter(m), bj_UNIT_FACING )

Now, coordinates. It's actually very easy to use them, plus there are no leaks. For example, that GetRectCenter(m) is a leak because it's not destroyed. If you used coordinates, you wouldn't have to worry about that:

local unit gate = CreateUnit(pr, 'hprt', GetRectCenterX(m), GetRectCenterX(m), bj_UNIT_FACING )

You see? GetRectCenterX and GetRectCenterY are coordinates of GetRectCenter, but they don't leak and it's not hard to understand them.

local unit m1 = CreateUnitAtLoc(pg, 'h014', GetRectCenterX(m), GetRectCenterY(y), 90.00)

What the hell is this?? First of all, that function takes a location, not coordinates, it should be CreateUnit(....), second, GetRectCenterY(y)?? You probably meant GetRectCenterY(m).

This is a small thing but what the heck:

GetPlayersAll function returns constant bj_FORCE_ALL_PLAYERS. So instead of putting GetPlayersAll() you can put bj_FORCE_ALL_PLAYERS.

JASS:
local unit m1 = CreateUnitAtLoc(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
local unit m2 = CreateUnitAtLoc(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
local unit m3 = CreateUnitAtLoc(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
local unit m4 = CreateUnitAtLoc(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)


If you have same lines like this, just do this (I fixed that GetRectCenterY(y)):

JASS:
local integer i = 1 // this should go before any calls/if then elses
loop
    exitwhen i > 4
    local unit m1 = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
    set i = i + 1
endloop


This is like for each Integer A/B in GUI.

you were the only 1 who helped me in this huge trigger

That's not a huge trigger :). You've never seen a huge trigger, apparently :p

I have done everything you asked me to do ...

Not everything......

Another thing, is you knockback spell Mui and leak free ?? Does it destroys destructibles(like trees) and creates a nice smooth effect when a unit is knocked back ? because i am searching for a knockback spell...

It's MUI, leak free and it creates a nice smooth effect, but it doesn't destroy trees though I can easily implement that. Though you need JassNewGenPack if you want to use that.

EDIT: Shit, PurplePoot beat me to it
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Hehe, I hate it when I write posts like that, spending an hour only to find someone started 15 minutes beforehand >_>

And Flame, Silvenon's 100% right, that trigger is puny compared to some of the weirded out stuff you start doing (the spells I code currently average at least 2x that long)

For Indenting, I suggest 4x statements; IE: Increase indenting by 4 spaces per statement encountered (function,if,elseif,else,loop,globals (plus the vJass ones)) and decrease indenting by 4 spaces for every statement ending encountered (endfunction,endif,endloop,endglobals).

Eg:

JASS:
globals
    real iAmIndented
endglobals
function func takes nothing returns nothing
    local integer indent
    if true then
        //even more indented
        loop
             exitwhen indented
        endloop
    elseif true then
        //indented
    else
        //indented
    endif
    loop
         exitwhen indented
    endloop
endfunction

You get the idea.

------------------------------------------------------

You also forget to replace all those CreateUnitAtLoc s with CreateUnit s. No parameter changes needed, you already have the CreateUnit parameters.

You're also still trying to use rects as locations.
 
Lol, ok this is small but just to make you know i have triggers that occupy my hole screen .... no i am not talking about the code, i am talking about having trigger001 connected to trigger002 unit trigger020 (or more depends).

But anyway, that is not the reason why i am posting now. I am posting because i did several improvements to the code. Thx for your help guys. I did the loop stuff, i think correctly, but still don't know yet, anyway here it goes.
I also improved the indenting like PurplePoot said..


JASS:
function army_acts takes nothing returns nothing
    local unit t = GetTrainedUnit()
    local rect m = gg_rct_Region_033
    local group g = CreateGroup()
    local unit f
    local location p = gg_rct_p1_workers_start
    local player pg = Player(5)
    local player pr = Player(0) 
    local unit gate = CreateUnit( 1, 'hprt', pg, GetRectCenterX(m), GetRectCenterY(m), bj_UNIT_FACING )
    local effect ef = AddSpecialEffectLoc("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", m)
    local integer mi = 1
    local integer ri = 1
    local unit h1 = CreateUnit(pg, 'H015', GetRectCenterX(m), GetRectCenterY(m), 90.00)  
    loop 
            exitwhen mi > 4
            local unit m1 = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
            set mi = mi +1
    endloop
    loop 
            exitwhen  ri > 4
            local unit r1 = CreateUnit(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)    
            set  ri = ri +1
    endloop
    call GroupAddUnit(udg_TrainedUnits_P1, t)
    set t = null
    if CountUnitsInGroup(udg_TrainedUnits_P1) == 20 then 
        call DisplayTextToForce( bj_FORCE_ALL_PLAYERS, ( "The First Northrend Army arrived to aid " + ( udg_Player_Colors[GetConvertedPlayerId(GetOwningPlayer(GetTrainedUnit()))] + ( GetPlayerName(GetOwningPlayer(GetTrainedUnit())) + "|r and his alliance !!!!! " ) ) ) )
        call CameraSetTargetNoiseEx(10, 500000, true)
        call CameraSetSourceNoiseEx(10, 500000, true)
        call GroupEnumUnitsInRect(g, m, null)
    loop
        set f = FirstOfGroup(g)
        exitwhen f == null
        call IssuePointOrder(f, "move", GetRectCenterX(m), GetRectCenterY(m))
        call GroupRemoveUnit(g, f)
    endloop
        call DestroyGroup(g)
        call DestroyEffect(ef)
        call KillUnit( gate )
        call TriggerSleepAction(4.00)
    loop
        exitwhen mi > 4
        call SetUnitOwner(mi, pr, true)
    endloop
    loop 
        exitwhen ri > 4
        call SetUnitOwner(ri, pr, true)
    endloop
        call SetUnitOwner(h1, pr, true)
        call CameraSetTargetNoiseEx(0, 0, true)
        call CameraSetSourceNoiseEx(0, 0, true)
        call RemoveLocation(m)
        call RemoveLocation(p)
        set gate = null
        set ef = null
        set m = null
        set p = null
        set m1 = null
        set r1 = null
        set h1 = null
        set pg = null
        set pr = null
        set g = null
        call DisableTrigger( GetTriggeringTrigger() )
    endif
endfunction
//===========================================================================
function InitTrig_Army_P1 takes nothing returns nothing
    local trigger army = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEvent( army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH, null )
    call TriggerAddAction( army, function army_acts )
endfunction

Here it is. Now Silver about your knockback spell, there are spells like that one that destroy trees and that don't use JassNewPackGen. I am talking about a spell that uses JASS and that is JESP.
I will also post it here so you may evaluate it, as i will probably use it on my map (don't know yet, want to make sure that the spell is MUI and leak free. Anyway i think it may help you improving yours.)

KnockBack spell:
JASS:
// Bloody // Bloody Pile Spell Configuration:

constant function BloodyPile_SpellId takes nothing returns integer
    return 'A000' //Rawcode of the BloodyPile Ability
endfunction   

constant function BloodyPile_SlideDuration takes nothing returns real
    return 0.60 //Defines the slide duration of target
endfunction

constant function BloodyPile_SpellDemage takes integer level returns real
    return level*90.00
    //This formula adds 90 demage per level of the spell
    //Starting from 90
endfunction 

constant function BloodyPile_TargetConditions takes unit Caster, unit Target returns boolean
    return (Target != Caster) and ( IsPlayerEnemy(GetOwningPlayer(Target), GetOwningPlayer(Caster)) ) and not(IsUnitType(Target, UNIT_TYPE_STRUCTURE)) and not(IsUnitType(Target,UNIT_TYPE_DEAD)) and not(IsUnitType(Target, UNIT_TYPE_MAGIC_IMMUNE))
    //Defines the targetable units which will get demage from unit sliding effect
endfunction

// This spell is playing target units death animation while sliding
// This gives a pain effect but if you use units which has no fleshy
// body animation modify this function

constant function BloodyPile_DeathAnimation takes nothing returns boolean
    return true //Make this "false" to disable targets death animation.
endfunction
//===================================================================================================

function BloodyPile_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == BloodyPile_SpellId()
endfunction

//Kills Picked Destructables near target when sliding
function BloodyPile_KillTreesOnTheWay takes nothing returns nothing
    call KillDestructable( GetEnumDestructable() )
endfunction

//Makes target unit slide and demage nearby units and throw them avay from it
function BloodyPile_SlideUnit takes nothing returns nothing    
    local timer Loop = GetExpiredTimer() 
    local unit Target = H2U(GetHandleHandle(Loop, "Target"))
    local unit Caster = H2U(GetHandleHandle(Loop, "Caster"))
    local unit PickedUnit
    local group UnitsInRange
    local real Angle = GetHandleReal(Loop, "Angle")
    local real AngleSmall
    local location TargetPoint = GetUnitLoc(Target)
    local location TargetPointSmall
    local location MovePoint = PolarProjectionBJ(TargetPoint,20.00,Angle)
    local location MovePointSmall
    local effect MiniEffect

    call SetUnitPositionLoc(Target, MovePoint)
    set MiniEffect = AddSpecialEffectTarget("Abilities\\Weapons\\FrostWyrmMissile\\FrostWyrmMissile.mdl",Target,"origin")
    call DestroyEffect(MiniEffect)
    call EnumDestructablesInCircleBJ( 200.00, TargetPoint, function BloodyPile_KillTreesOnTheWay )
    set UnitsInRange = GetUnitsInRangeOfLocAll(250, TargetPoint)
    call GroupRemoveUnit(UnitsInRange,Target)
    set PickedUnit = FirstOfGroup(UnitsInRange)

    loop
        exitwhen PickedUnit==null
        set PickedUnit = FirstOfGroup(UnitsInRange)
        call GroupRemoveUnit(UnitsInRange,PickedUnit)
        if (BloodyPile_TargetConditions(Caster, PickedUnit)) then            
            set TargetPointSmall = GetUnitLoc(PickedUnit)
            set AngleSmall = AngleBetweenPoints(TargetPoint,TargetPointSmall)
            set MovePointSmall = PolarProjectionBJ(TargetPointSmall,80,AngleSmall)
            call SetUnitPositionLoc(PickedUnit, MovePointSmall)
            call UnitDamageTarget(Caster,PickedUnit,25*GetUnitAbilityLevel(Caster, BloodyPile_SpellId()),false,false,null,null,null)

            call RemoveLocation(TargetPointSmall)
            call RemoveLocation(MovePointSmall)
        endif
    endloop      
  
    call RemoveLocation(MovePoint)
    call RemoveLocation(TargetPoint)
    call DestroyGroup(UnitsInRange)    
    set Caster = null
    set Target = null
endfunction

function BloodyPile_Actions takes nothing returns nothing
    local timer Loop = CreateTimer()
    local effect StunEffect
    local unit Target = GetSpellTargetUnit()
    local unit Caster = GetSpellAbilityUnit()
    local location TargetPoint = GetUnitLoc(Target)
    local location CasterPoint = GetUnitLoc(Caster)
    local real Angle = AngleBetweenPoints(CasterPoint, TargetPoint)
    local real Demage = BloodyPile_SpellDemage(GetUnitAbilityLevel(Caster, BloodyPile_SpellId()))
    local real Duration = BloodyPile_SlideDuration()

 
    call SetHandleHandle(Loop, "Target", Target) 
    call SetHandleHandle(Loop, "Caster", Caster)
    call SetHandleReal(Loop, "Angle", Angle)
    call SetUnitFacingToFaceUnitTimed( Target, Caster, 0 )
    call PauseUnit(Target,true)
    
    if (BloodyPile_DeathAnimation()) then
        call SetUnitAnimation( Target, "death" )
    endif
    
    call UnitDamageTarget(Caster,Target,Demage,false,false,null,null,null)
    call TimerStart(Loop, 0.03, true, function BloodyPile_SlideUnit)    
    call TriggerSleepAction( Duration )
    call PauseTimer(Loop) 
    call FlushHandleLocals(Loop)
    call DestroyTimer(Loop) 

    if not (IsUnitType(Target,UNIT_TYPE_DEAD)) then
        set StunEffect = AddSpecialEffectTarget( "Abilities\\Spells\\Human\\Thunderclap\\ThunderclapTarget.mdl", Target, "overhead")        
        call TriggerSleepAction( 1.25 * GetUnitAbilityLevel(Caster, BloodyPile_SpellId()))
        call DestroyEffectBJ( StunEffect )
    endif
    call PauseUnit(Target,false)

    call RemoveLocation(TargetPoint)
    call RemoveLocation(CasterPoint)
    set Caster = null
    set Target = null    
endfunction

// ===========================================================================
function InitTrig_BloodyPile takes nothing returns nothing
    local trigger gg_trg_BloodyPile = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_BloodyPile, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_BloodyPile, Condition( function BloodyPile_Conditions ) )
    call TriggerAddAction( gg_trg_BloodyPile, function BloodyPile_Actions )
endfunction

I hope it helps.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
By the way, using JassNewGen is a good thing. Destroying trees is a preference thing (also destroys stuff like crates, often even bridges -.-)

Otherwise, you forgot to fix those rect/location conficts (again)

Your indenting is nice, but for some reason you put your loop inside the if-statement to 4 spaces when it should be 8, and its contents 8 when they should be 12. It's really a preference thing, though, so if you really like it that way then keep it that way.
 
mmm, ok i don't know what i am doing wrong with the Rect/Loc ... i just don't seem to know where the problem is ... another thing, i fixed the indenting now (finally =p).

About the knockback spell, most maps don't have bridges, have trees, anyway, i would like my knockback ability to knock down trees ... another thing is the fact that you can change the function to not to destroy bridges ... just use an if statement ..

Anyway, here is the spell (nearly euqal but with indents fixed):
JASS:
function army_acts takes nothing returns nothing
    local unit t = GetTrainedUnit()
    local rect m = gg_rct_Region_033
    local group g = CreateGroup()
    local unit f
    local location p = gg_rct_p1_workers_start
    local player pg = Player(5)
    local player pr = Player(0) 
    local unit gate = CreateUnit( 1, 'hprt', pg, GetRectCenterX(m), GetRectCenterY(m), bj_UNIT_FACING )
    local effect ef = AddSpecialEffectLoc("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", m)
    local integer mi = 1
    local integer ri = 1
    local unit h1 = CreateUnit(pg, 'H015', GetRectCenterX(m), GetRectCenterY(m), 90.00)  
    loop 
            exitwhen mi > 4
            local unit m1 = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
            set mi = mi +1
    endloop
    loop 
            exitwhen  ri > 4
            local unit r1 = CreateUnit(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)    
            set  ri = ri +1
    endloop
    call GroupAddUnit(udg_TrainedUnits_P1, t)
    set t = null
    if CountUnitsInGroup(udg_TrainedUnits_P1) == 20 then 
        call DisplayTextToForce( bj_FORCE_ALL_PLAYERS, ( "The First Northrend Army arrived to aid " + ( udg_Player_Colors[GetConvertedPlayerId(GetOwningPlayer(GetTrainedUnit()))] + ( GetPlayerName(GetOwningPlayer(GetTrainedUnit())) + "|r and his alliance !!!!! " ) ) ) )
        call CameraSetTargetNoiseEx(10, 500000, true)
        call CameraSetSourceNoiseEx(10, 500000, true)
        call GroupEnumUnitsInRect(g, m, null)
        loop
            set f = FirstOfGroup(g)
            exitwhen f == null
            call IssuePointOrder(f, "move", GetRectCenterX(m), GetRectCenterY(m))
            call GroupRemoveUnit(g, f)
        endloop
            call DestroyGroup(g)
            call DestroyEffect(ef)
            call KillUnit( gate )
            call TriggerSleepAction(4.00)
        loop
            exitwhen mi > 4
            call SetUnitOwner(mi, pr, true)
        endloop
        loop 
            exitwhen ri > 4
            call SetUnitOwner(ri, pr, true)
        endloop
            call SetUnitOwner(h1, pr, true)
            call CameraSetTargetNoiseEx(0, 0, true)
            call CameraSetSourceNoiseEx(0, 0, true)
            call RemoveLocation(m)
            call RemoveLocation(p)
            set gate = null
            set ef = null
            set m = null
            set p = null
            set m1 = null
            set r1 = null
            set h1 = null
            set pg = null
            set pr = null
            set g = null
            call DisableTrigger( GetTriggeringTrigger() )
        endif
endfunction
//===========================================================================
function InitTrig_Army_P1 takes nothing returns nothing
    local trigger army = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEvent( army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH, null )
    call TriggerAddAction( army, function army_acts )
endfunction


And Silver, if you are reading this post, please jump to the other post i did before this one, because i think you would like to see it.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
local location p = gg_rct_p1_workers_startyou're setting a loc variable to a rect. This could be local location p = Location(GetRectCenterX(gg_rct_p1_workers_start),GetRectCenterY(gg_rct_p1_workers_Start))

local effect ef = AddSpecialEffectLoc("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", m) local integer mi = 1uses a rect where it should have a loc. I suggest fixing this one by local effect ef = AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl",GetRectCenterX(m),GetRectCenterY(m))

Your indenting has some weirdnesses (after the loop, the second half of the if has an extra indent) but in general is way easier to read now. Thanks.
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Pooty,

local location p = Location(GetRectCenterX(gg_rct_p1_workers_start),GetRectCenterY(gg_rct_p1_workers_Start))

is equal to

local location p = GetRectCenter(gg_rct_p1_workers_Start)

It doesn't make any difference converting coordinates to a location if you're using crappy locations anyways. Maybe a slight performance improvement because of the natives.....

I think you put this in your AddSpecialEffectLoc line accidentaly:

local integer mi = 1
 
OK, thx PurplePoot. I've again fixed the problems you told me 2 (including the indenting =P, he he thx now i know how to indent correctly =P)

New script:
JASS:
function army_acts takes nothing returns nothing
    local unit t = GetTrainedUnit()
    local rect m = gg_rct_Region_033
    local group g = CreateGroup()
    local unit f
    local location p = Location(GetRectCenterX(gg_rct_p1_workers_start), GetRectCenterY(gg_rct_p1_workers_start))
    local player pg = Player(5)
    local player pr = Player(0) 
    local unit gate = CreateUnit( 1, 'hprt', pg, GetRectCenterX(m), GetRectCenterY(m), bj_UNIT_FACING )
    local effect ef = AddSpecialEffectLoc("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", GetRectCenterX(m), GetRectCenterY(m)
    local integer mi = 1
    local integer ri = 1
    local unit h1 = CreateUnit(pg, 'H015', GetRectCenterX(m), GetRectCenterY(m), 90.00)  
    loop 
            exitwhen mi > 4
            local unit m1 = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
            set mi = mi +1
    endloop
    loop 
            exitwhen  ri > 4
            local unit r1 = CreateUnit(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)    
            set  ri = ri +1
    endloop
    call GroupAddUnit(udg_TrainedUnits_P1, t)
    set t = null
    if CountUnitsInGroup(udg_TrainedUnits_P1) == 20 then 
        call DisplayTextToForce( bj_FORCE_ALL_PLAYERS, ( "The First Northrend Army arrived to aid " + ( udg_Player_Colors[GetConvertedPlayerId(GetOwningPlayer(GetTrainedUnit()))] + ( GetPlayerName(GetOwningPlayer(GetTrainedUnit())) + "|r and his alliance !!!!! " ) ) ) )
        call CameraSetTargetNoiseEx(10, 500000, true)
        call CameraSetSourceNoiseEx(10, 500000, true)
        call GroupEnumUnitsInRect(g, m, null)
        loop
            set f = FirstOfGroup(g)
            exitwhen f == null
            call IssuePointOrder(f, "move", GetRectCenterX(m), GetRectCenterY(m))
            call GroupRemoveUnit(g, f)
        endloop
            call DestroyGroup(g)
            call DestroyEffect(ef)
            call KillUnit( gate )
            call TriggerSleepAction(4.00)
        loop
            exitwhen mi > 4
            call SetUnitOwner(mi, pr, true)
        endloop
        loop 
            exitwhen ri > 4
            call SetUnitOwner(ri, pr, true)
        endloop
        call SetUnitOwner(h1, pr, true)
        call CameraSetTargetNoiseEx(0, 0, true)
        call CameraSetSourceNoiseEx(0, 0, true)
        call RemoveLocation(m)
        call RemoveLocation(p)
        set gate = null
        set ef = null
        set m = null
        set p = null
        set m1 = null
        set r1 = null
        set h1 = null
        set pg = null
        set pr = null
        set g = null
        call DisableTrigger( GetTriggeringTrigger() )
    endif
endfunction
//===========================================================================
function InitTrig_Army_P1 takes nothing returns nothing
    local trigger army = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEvent( army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH, null )
    call TriggerAddAction( army, function army_acts )
endfunction

And now the errors:
4- Undeclared Variable: gg_rct_Region033
6- Undeclared Variable: gg_rct_p1_workers_start
9- Cannot convert integer to player/cnt convert player to real/too many arguments
10 - Cnt convert real to location/too many arguments
16 - syntax error
21 - syntax error
24 - Undeclared Variable: udg_TrainedUnits_P1
27 - Undeclared Variable: udg_Player_Colors
27 - udg_Player_Colors is not an array
43 and 47 - Cannot convert integer to unit
52 - Cannot convert Rect to location
59 - Undeclared variable m1
60 - Undeclared variable r1

bla bla bla 17 total errors ...

I've tried to fix them but i can't ... Can you plz help me fix them ?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Silvenon, GetRectCenter returns what I posted x.x (it's a bj! noes!)

Anyhow, erm, yeah, you should use locs in general. Apparently, for the most part, flame, btw, you have none of those globals defined.

Ones worth noting:

9- Cannot convert integer to player/cnt convert player to real/too many arguments
10 - Cnt convert real to location/too many arguments
16 - syntax error
21 - syntax error
43 and 47 - Cannot convert integer to unit
52 - Cannot convert Rect to location
59 - Undeclared variable m1
60 - Undeclared variable r1

I'll look into it when I have some spare time
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
K, here we go

local unit gate = CreateUnit( 1, 'hprt', pg, GetRectCenterX(m), GetRectCenterY(m), bj_UNIT_FACING ) The first param should be a player, not an integer (that pg variable). The 1 should not exist.

local effect ef = AddSpecialEffectLoc("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", GetRectCenterX(m), GetRectCenterY(m)) Should be just AddSpecialEffect, you also forgot the closing bracket.

local unit m1 = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00) and local unit r1 = CreateUnit(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00) You have to define locals at the start of the function, remember?

call SetUnitOwner(mi, pr, true) needs a unit, not an integer (first param)

call RemoveLocation(m) That's a rect.

That about sums it up!
 
Ok, i did most of the corrections.
I didn't corrected the "call SetUnitOwner(mi, pr, true)" because it is referring to a loop.
Let me explain. If you have a close look to the scrip you will see that with:
JASS:
loop 
            exitwhen mi > 4
            set m1 = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
            set mi = mi +1
    endloop
i create 4 units for Player(5). After that i try to use:
JASS:
loop
            exitwhen mi > 4
            call SetUnitOwner(mi, pr, true)
        endloop
To give the ownership of those unit to player 1.
So, this way i cannot use other thing but an integer to refer to the unit rit ??
is there any other solution ???

Btw, this spell Not MUI... do you think you can help me make it MUI for all players ? plz


Anyway Spell Improvement:
JASS:
function army_acts takes nothing returns nothing
    local unit t = GetTrainedUnit()
    local rect m = gg_rct_Region_033
    local group gt = CreateGroup()
    local group g = CreateGroup()
    local unit f
    local location p = Location(GetRectCenterX(gg_rct_p1_workers_start), GetRectCenterY(gg_rct_p1_workers_start))
    local player pg = Player(5)
    local player pr = Player(0) 
    local unit gate = CreateUnit( pg, 'hprt', GetRectCenterX(m), GetRectCenterY(m), 270.0)
    local effect ef = AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", GetRectCenterX(m), GetRectCenterY(m))
    local integer mi = 1
    local integer ri = 1
    local unit h1 = CreateUnit(pg, 'H015', GetRectCenterX(m), GetRectCenterY(m), 90.00)
    local unit m1
    local unit r1  
    loop 
        exitwhen mi > 4
        set m1 = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
        set mi = mi +1
    endloop
    loop 
        exitwhen  ri > 4
        set r1 = CreateUnit(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)    
        set  ri = ri +1
    endloop
    call GroupAddUnit(gt, t)
    set t = null
    if CountUnitsInGroup(gt) == 20 then 
        call DisplayTextToForce( bj_FORCE_ALL_PLAYERS, ( "The First Northrend Army arrived to aid " + ( udg_Player_Colors[GetConvertedPlayerId(GetOwningPlayer(GetTrainedUnit()))] + ( GetPlayerName(GetOwningPlayer(GetTrainedUnit())) + "|r and his alliance !!!!! " ) ) ) )
        call CameraSetTargetNoiseEx(10, 500000, true)
        call CameraSetSourceNoiseEx(10, 500000, true)
        call GroupEnumUnitsInRect(g, m, null)
        loop
            set f = FirstOfGroup(g)
            exitwhen f == null
            call IssuePointOrder(f, "move", GetRectCenterX(m), GetRectCenterY(m))
            call GroupRemoveUnit(g, f)
        endloop
            call DestroyGroup(g)
            call DestroyEffect(ef)
            call KillUnit( gate )
            call TriggerSleepAction(4.00)
        loop
            exitwhen mi > 4
            call SetUnitOwner(mi, pr, true)
        endloop
        loop 
            exitwhen ri > 4
            call SetUnitOwner(ri, pr, true)
        endloop
        call SetUnitOwner(h1, pr, true)
        call CameraSetTargetNoiseEx(0, 0, true)
        call CameraSetSourceNoiseEx(0, 0, true)
        call RemoveRect(m)
        call RemoveLocation(p)
        set gate = null
        set ef = null
        set m = null
        set p = null
        set m1 = null
        set r1 = null
        set h1 = null
        set pg = null
        set pr = null
        set g = null
        call DisableTrigger( GetTriggeringTrigger() )
    endif
endfunction
//===========================================================================
function InitTrig_Army_P1 takes nothing returns nothing
    local trigger army = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEvent( army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH, null )
    call TriggerAddAction( army, function army_acts )
    set army = null
endfunction


Improved Indenting (again), also removed the Global Var udg_UnitsTrained_P1 and replaced it by local unitgroup "gt".
Fixed gate and SpecialEffect syntax problems and replaced RemoveLocation by RemoveRect.
Also nullified the local trigger to avoid leaks.

Btw, i know it will be difficult, but is there anyway to keep the track of the trained units a player has ??? like ab array group or something ??
 
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
To give the ownership of those unit to player 1.
So, this way i cannot use other thing but an integer to refer to the unit rit ??
is there any other solution ???
No, you have to use a unit... Integers != units.

Try using a unit array though. Eg.

JASS:
local unit array m1
loop
    exitwhen mi > 4
    set m1[mi] = CreateUnit(...)
    set mi = mi + 1
endloop
//later on
loop
    exitwhen mi > 4
    call SetUnitOwner(m1[mi],pr,true)
    set mi = mi + 1
endloop

Btw, i know it will be difficult, but is there anyway to keep the track of the trained units a player has ??? like ab array group or something ??

Use a unit group array (one group per player)



And that spell would be MUI if it compiled.
 
Well, i have so many things to say that i don't know where to start...
Thx for the array tip on the units, it does make my job a lot easier. However i have several problems with the array group .... i just don't know what i am doing (lol) ... still i tried to do something. I posted most of my problems and question in the system script so that you and other people may evaluate what i did.

System Improvement:
JASS:
function army_acts takes nothing returns nothing
//Here is where i create the group array and the integer    
    local group array gt
    local integer pn = 0
//Here is where it ends and where i create all other locals
    local unit t = GetTrainedUnit()
    local rect m = gg_rct_Region_033
    local group g = CreateGroup()
    local unit f
    local location p = Location(GetRectCenterX(gg_rct_p1_workers_start), GetRectCenterY(gg_rct_p1_workers_start))
    local player pg = Player(5) 
    local unit gate = CreateUnit( pg, 'hprt', GetRectCenterX(m), GetRectCenterY(m), 270.0)
    local effect ef = AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", GetRectCenterX(m), GetRectCenterY(m))
    local integer mi = 1
    local integer ri = 1
    local unit h1 = CreateUnit(pg, 'H015', GetRectCenterX(m), GetRectCenterY(m), 90.00)
    local unit array m1
    local unit array r1 
//Start Problem, i try to craete the group for the players
//Question: Do i have to nullifythe created group after ?
    loop 
        exitwhen pn == 16
        set gt[pn] = CreateGroup()
        set pn = pn +1
    endloop
//End Problem 
//=========================================   
//Another problem to the party (group gt)
//i try add the unit to the group ... but i make no idea what i am doing
    call GroupAddUnit(gt[pn], t)
    set t = null
    if CountUnitsInGroup(gt[pn]) == 20 then 
        call DisplayTextToForce( bj_FORCE_ALL_PLAYERS, ( "The First Northrend Army arrived to aid " + ( udg_Player_Colors[GetConvertedPlayerId(GetOwningPlayer(GetTrainedUnit()))] + ( GetPlayerName(GetOwningPlayer(GetTrainedUnit())) + "|r and his alliance !!!!! " ) ) ) )
        call CameraSetTargetNoiseEx(10, 500000, true)
        call CameraSetSourceNoiseEx(10, 500000, true)
        call GroupEnumUnitsInRect(g, m, null)
//if what is above doesn't work, nothing else will...
// here is when i create the m1 units
        loop 
            exitwhen mi > 4
            set m1[mi] = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
            set mi = mi +1
        endloop
//Now i create the r1 units
        loop 
            exitwhen  ri > 4
            set r1[ri] = CreateUnit(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)    
            set ri = ri +1
        endloop
//After creating the units(m1 and r1), i order them to move to another loc
        loop
            set f = FirstOfGroup(g)
            exitwhen f == null
            call IssuePointOrder(f, "move", GetRectCenterX(m), GetRectCenterY(m))
            call GroupRemoveUnit(g, f)
        endloop
//More 1 problem, i don't know if this "calls" are coorect (the group)
        call DestroyGroup(g)
        call DestroyEffect(ef)
        call KillUnit( gate )
        call TriggerSleepAction(4.00)
//End previous problem
//Here i change the ownership of the units
        loop
            exitwhen mi > 4
            call SetUnitOwner(m1[mi], pn, true)
            set mi = mi +1
        endloop
        loop 
            exitwhen ri > 4
            call SetUnitOwner(r1[ri], pn, true)
            set ri = ri + 1
        endloop
//Here i shut the system down and nullify everyting
        call SetUnitOwner(h1, pn, true)
        call CameraSetTargetNoiseEx(0, 0, true)
        call CameraSetSourceNoiseEx(0, 0, true)
        call RemoveRect(m)
        call RemoveLocation(p)
        set gate = null
        set ef = null
        set m = null
        set p = null
        set m1[mi] = null
        set r1[ri] = null
        set h1 = null
        set pg = null
        set g = null
//Here i make sure i can only use this trigger once
        call DisableTrigger(GetTriggeringTrigger())
    endif
endfunction
//===========================================================================
function InitTrig_Army_P1 takes nothing returns nothing
//Here i avoid the "TriggerRegisterAnyUnitEventBJ" by writing it in an effecient way
    local trigger army = CreateTrigger(  )
    local integer index = 0
    loop
        exitwhen index == 16 //Here i avoid the "bj_MAX_PLAER_SLOTS" by replacing it by its original value(16)
        call TriggerRegisterPlayerUnitEvent(army, Player(index), EVENT_PLAYER_UNIT_TRAIN_FINISH, null)
        set index = index + 1 
    endloop
//Now that the event is done i make the conditions and actions
    call TriggerAddAction( army, function army_acts )
    set army = null
endfunction


Well, to start as you can see i have lots of trouble with the group arrays... think it just overloads my head ... when i start understanding the concepts and what i must do i just get confused ... suddenly i don't know what 2+2 is ... (is 4).
Anyway, that doesn't mean i am not trying my best, and to prove it i replaced some loops and changed them to the correct place (i think). I also did an effort to eliminate the Event Bj's =) i think i did it well. Now my map probably has 0% Bj's (as long as i know, BJ's have bj in their name, and i couldn't find any function with bj in the name).
I also deleted some player locals i no longer needed (pr = Player(0) was deleted). So now i think i posted most of my problems.

Another question, I've been studying some coordinates and stuff like that but i get easily confused ... Anyway the point is can i use 3 coordinates (corX, corY, corZ) to create a unit instead of a locations or a rect ??? If possible how do i do it ?? and is it worthy ??
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Aight.

Let's start... randomly. (Well, they're basically in backwards order)

First: you need to reset mi and ri to 0 before you use them again.

Next: TriggerRegisterAnyUnitEventBJ isn't really a bad BJ, since it does so much for you. It's your choice as to replacing it, though.

Instead of DisableTrigger, I would use DestroyTrigger if I were you (may as well take a little bit off the processor)

The DestroyGroup call is fine.

After creating m1[mi] and r1[ri], you should add them to the group via GroupAddUnit. Currently, they aren't.

As for the problems with gt[pn] in the GroupAddUnit and CountUnitsInGroup, blarg. That'll just do 16 or whatever the group exited at. Inside of those [], instead of pn, put whatever value (integer) you need. What do you want to do, do this for each player?

And you only have to null the groups once you're done with them. However, you don't appear to do much with them.
 
mmm, blarg that is the word that defines my scrip definitely. Anyway, however, what do i do ? well, i will explain the hole system again.
- The idea should be simple: Players train units in games, and when they reach a number (20 units trained per example) they gain a reward (in this case the units). The player must be an ally of Player(5).
I want a system to track all units players train... And when they train a number of units the trigger is activated. Only once. This is what i want ... my problem lies in how to do it ...
I try to do this by creating group arrays (about which i know nothing, but try to learn).
Because it is probable that 2 players finish training unit number 20 at the same time, the spell must be MUI.... and because lag will ruin the whole system it must be leak free. But more important it must work properly ...
I have nothing but critical errors so far and i need help ..
If you know about any other system to track trained units from players that is better that the one i am trying to use, please say so. I don't mind starting from 0 as long as it works.

System Improvement:
JASS:
function army_acts takes nothing returns nothing
//Here is where i create the group array and the integer    
    local group array gt
    local integer pn = 0
//Here is where it ends and where i create all other locals
    local unit t = GetTrainedUnit()
    local rect m = gg_rct_Region_033
    local group g = CreateGroup()
    local unit f
    local location p = Location(GetRectCenterX(gg_rct_p1_workers_start), GetRectCenterY(gg_rct_p1_workers_start))
    local player pg = Player(5) 
    local unit gate = CreateUnit( pg, 'hprt', GetRectCenterX(m), GetRectCenterY(m), 270.0)
    local effect ef = AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", GetRectCenterX(m), GetRectCenterY(m))
    local integer mi = 1
    local integer ri = 1
    local unit h1 = CreateUnit(pg, 'H015', GetRectCenterX(m), GetRectCenterY(m), 90.00)
    local unit array m1
    local unit array r1 
//Start Problem, i try to craete the group for the players
//Question: Do i have to nullifythe created group after ?
    loop 
        exitwhen pn == 16
        set gt[pn] = CreateGroup()
        set pn = pn +1
    endloop
//End Problem 
//=========================================   
//Another problem to the party (group gt)
//i try add the unit to the group ... but i make no idea what i am doing
    call GroupAddUnit(gt[pn], t)
    set t = null
    if CountUnitsInGroup(gt[pn]) == 20 and IsPlayerAlly(pn, pg) then 
        call DisplayTextToForce( bj_FORCE_ALL_PLAYERS, ( "The First Northrend Army arrived to aid " + ( udg_Player_Colors[GetConvertedPlayerId(GetOwningPlayer(GetTrainedUnit()))] + ( GetPlayerName(GetOwningPlayer(GetTrainedUnit())) + "|r and his alliance !!!!! " ) ) ) )
        call CameraSetTargetNoiseEx(10, 500000, true)
        call CameraSetSourceNoiseEx(10, 500000, true)
        call GroupEnumUnitsInRect(g, m, null)
//if what is above doesn't work, nothing else will...
// here is when i create the m1 units
        loop 
            exitwhen mi > 4
            set m1[mi] = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
            set mi = mi +1
        endloop
//Now i create the r1 units
        loop 
            exitwhen  ri > 4
            set r1[ri] = CreateUnit(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)    
            set ri = ri +1
        endloop
//After creating the units(m1 and r1), i order them to move to another loc
        loop
            set f = FirstOfGroup(g)
            exitwhen f == null
            call IssuePointOrder(f, "move", GetRectCenterX(m), GetRectCenterY(m))
            call GroupRemoveUnit(g, f)
        endloop
//More 1 problem, i don't know if this "calls" are coorect (the group)
        call DestroyGroup(g)
        call DestroyEffect(ef)
        call KillUnit( gate )
        call TriggerSleepAction(4.00)
//End previous problem
//Here i change the ownership of the units
        loop
            set mi = 0
            exitwhen mi > 4
            call SetUnitOwner(m1[mi], pn, true)
            set mi = mi +1
        endloop
        loop 
            set ri = 0
            exitwhen ri > 4
            call SetUnitOwner(r1[ri], pn, true)
            set ri = ri + 1
        endloop
//Here i shut the system down and nullify everyting
        call SetUnitOwner(h1, pn, true)
        call CameraSetTargetNoiseEx(0, 0, true)
        call CameraSetSourceNoiseEx(0, 0, true)
        call RemoveRect(m)
        call RemoveLocation(p)
        set gate = null
        set ef = null
        set m = null
        set p = null
        set m1[mi] = null
        set r1[ri] = null
        set h1 = null
        set pg = null
        set g = null
//Here i make sure i can only use this trigger once
        call DestroyTrigger(GetTriggeringTrigger())
    endif
endfunction
//===========================================================================
function InitTrig_Army_P1 takes nothing returns nothing
//Here i avoid the "TriggerRegisterAnyUnitEventBJ" by writing it in an effecient way
    local trigger army = CreateTrigger(  )
    local integer index = 0
    loop
        exitwhen index == 16 //Here i avoid the "bj_MAX_PLAER_SLOTS" by replacing it by its original value(16)
        call TriggerRegisterPlayerUnitEvent(army, Player(index), EVENT_PLAYER_UNIT_TRAIN_FINISH, null)
        set index = index + 1 
    endloop
//Now that the event is done i make the conditions and actions
    call TriggerAddAction( army, function army_acts )
    set army = null
endfunction

Set mi and ri to 0, and replaced disable trigger with destroy trigger ... also added the condition that the player must be an ally of player 6.
I didn't understood the group stuff you told me ... that is where i really need help =S that is the heart of the system =s.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Of course it's MUI. There are no waits and no globals.

But wait, do you want each player to be able to trigger it once? In that case, you'll need more than one trigger (just create multiple triggers in the InitTrig, 1 per player)

As for the number of units built so far, a global Unit Group Array is your friend.
 
Yes, i would like each player to be able to trigger it once. And for the units, i don't understand, am i doing anything wrong ??
My map has 2 teams: the North Alliance and the South Alliance (crappy names i know, hope i can think of a better name =P).
This case is for the North Alliance which includes a computer and 4 human players. The computer is ugly and it will not get the bonus, letting us with the other 4 human players. I want each of those 4 human player to be able to trigger this trigger only once if possible.
 
I see what you mean, and now that i can fuse multiple triggers i have my job a lot easier. Thx by the tips. Anyway here is the system improvement:

System:
JASS:
function army_acts takes nothing returns nothing
    local unit t = GetTrainedUnit()
    local rect m = gg_rct_Region_033
    local group g = CreateGroup()
    local group ut = CreateGroup()
    local unit f
    local location p = Location(GetRectCenterX(gg_rct_p1_workers_start), GetRectCenterY(gg_rct_p1_workers_start))
    local player pg = Player(5)
    local player p1 = Player(0) 
    local unit gate = CreateUnit( pg, 'hprt', GetRectCenterX(m), GetRectCenterY(m), 270.0)
    local effect ef = AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", GetRectCenterX(m), GetRectCenterY(m))
    local integer mi = 1
    local integer ri = 1
    local unit h1 = CreateUnit(pg, 'H015', GetRectCenterX(m), GetRectCenterY(m), 90.00)
    local unit array m1
    local unit array r1    
//Another problem to the party (group gt)
//i try add the unit to the group ... but i make no idea what i am doing
    call GroupAddUnit(ut, t)
    set t = null
    if CountUnitsInGroup(ut) == 20 then 
        call DisplayTextToForce (null, ( "The First Northrend Army arrived to aid " + ( GetPlayerName(p1) + "|r and his alliance !!!!! " ) ) )
        call CameraSetTargetNoiseEx(10, 500000, true)
        call CameraSetSourceNoiseEx(10, 500000, true)
        call GroupEnumUnitsInRect(ut, m, null)
//Here i create the m1 units        
        loop 
            exitwhen mi > 4
            set m1[mi] = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
            set mi = mi +1
        endloop
// Here i create the r1 units        
        loop 
            exitwhen  ri > 4
            set r1[ri] = CreateUnit(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)    
            set ri = ri +1
        endloop
//Here i order m1 and r1 to attack-move to loc      
        loop
            set f = FirstOfGroup(g)
            exitwhen f == null
            call IssuePointOrder(f, "attack", GetRectCenterX(m), GetRectCenterY(m))
            call GroupRemoveUnit(g, f)
        endloop
//More 1 problem, i don't know if this "calls" are coorect (the group)
// Problem 2: I try to make the trigger wait until all units of group "ut" are in the region, but i don't know how to 
//do that so i use "RandomUnitFromUnitGroup" which i don't like ... Hope i replace it soon
//Also i don't know how to remove the RMaxBJ and i want to remove it
        call DestroyEffect(ef)
        call KillUnit( gate )
        loop 
            exitwhen RectContainsUnit(gg_rct_p1_workers_start, GroupPickRandomUnit(ut)) == true 
            call TriggerSleepAction(RMaxBJ(0.10, 0.50))
        endloop     
//Here i change the ownership of the units to player1
        loop
            set mi = 0
            exitwhen mi > 4
            call SetUnitOwner(m1[mi], p1, true)
            set mi = mi +1
        endloop
        loop 
            set ri = 0
            exitwhen ri > 4
            call SetUnitOwner(r1[ri], p1, true)
            set ri = ri + 1
        endloop
//Here i shut the system down and nullify everyting
// I hope it is everyting ok down here
        call SetUnitOwner(h1, p1, true)
        call CameraSetTargetNoiseEx(0, 0, true)
        call CameraSetSourceNoiseEx(0, 0, true)
        call RemoveRect(m)
        call RemoveLocation(p)
        call DestroyGroup (ut)
        call DestroyGroup(g)
        set gate = null
        set ef = null
        set m = null
        set p = null
        set m1[mi] = null
        set r1[ri] = null
        set h1 = null
        set pg = null
        set p1 = null
        set g = null
        set ut = null
//Here i make sure i can only use this trigger once
        call DestroyTrigger(GetTriggeringTrigger())
    endif
endfunction
//===========================================================================
function InitTrig_Army_P1 takes nothing returns nothing
    local trigger army = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEvent(army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH, null)
    call TriggerAddAction( army, function army_acts )
    set army = null
endfunction

Much more efficient, just check the errors list:
4- Undeclared Var gg_rct_Region_033
7- Undeclared Var gg_rct_p1_workers_start

from original nearly 20-30 errors reduced only 2 errors. Lag incredibly reduced (i guess).

Changes:
1 - This trigger only applies to player 1 now, but there is no problem as i can fuse multiple triggers in order to save memory space.
2 - replaced the bj_FORCE_ALL_PLAYERS by its value which is "null"
3 - greatly improved the "DisplayTextToForce" call, making it independent from global variables and others.
4 - removed and nullified groups, plus added a new local Var(p1).
5 - Removed group arrays and excessive unneeded loops.
6 - Re-ordered the script to the correct order.
7 - Changed the "move" order to "attack". Now units will attack-move to the region.
8 - Unsuccessfully Tried the "TriggerSleepTime" to wait until all units are in the region, but i was unable to do it correctly and therefore i need help to accomplish it.

Well this are the major changes.
However i would like to make this script 100% independent from regions and other variables that may cause errors.
As i already asked, is there a way to don't use regions and use Coordinates ??
Ex: CreateUnit bla bla bla (corX, corY, corZ) ????

Because if it makes my scrip more efficient i would like to try it plz.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
What I was saying about global group arrays, I mean you should create one Globally (Use the Variable Manager) so that it's accessable between the trigger running.

Errors: It's just saying that you haven't defined those regions. If you get that in JASSCraft only, you should be fine, since JASSHelper doesn't know which globals you have unless you tell it.

native CreateUnit takes player id, integer unitid, real x, real y, real face returns unit

It's just like CreateUnitAtLoc but the loc is replaced by real x, real y
 
I feel very insulted .. for your information i already read nearly all your JASS tutorials, just have a look in tutorials section and you'll see that I was the last person to comment on them!!

I also know PurplePoot is trying to help me !! In fact he is the principal guy that helps people ... ok DiscipleOfLife and more 3 or 4 guys that are here also do the job but face it, 90% of the replies i have is he who makes them !! 8I mean no offense to all others who helped, or will help me if they want, their replies will always be appreciated by me and i will always replay back saying thanks as i always do)

I am also werrm (i am not english so i don't know the word) very greatful (dunno if it's this one, it is supposed to mean that some1 really appreciates a thing that some1 else did for him). Anyway i mean Very thanks to puple ... i appreciate his job and in fact i already told him that i was going to place his name in the main credits section of my map !! (this section only has 3 people: Soulsnatcher, Ah_e_Tal and now him).

In fact to be honest i think of purplepoot like my JASS teacher because he teaches me all the JASS stuff your tutorials don't have.

But i also have question, i try my best to learn, but there is always questions i have, and i face it i can be very boring sometimes but it is something i need to know...
It's like i have those questions a long time ago .... and i never said purplepoot wasn't helping me!

In fact if you read my posts Disciple of life you see that i also tried to help you about your JASS knockback spell.... yes i posted for you a JASS knockback spell that destroys tress and stuff like that i told you to check it because it could help you improve yours .. it was my way of saying thanks ...
When people help me, i help them in return if i can .. world is not fair, never was and never will be, but if i can do something to change that i will....

I try to be as honest and fair as i can and i usually don't forget people who help me ... when i don't understand things i just ask them to everyone until i have an answer ??? is that such a bad thing Disciple ??? don't you ever have questions about anything ??

I also know that you guys are pros in JASS and that's why i come here to ask for your help .... i usually never make the same mistake twice (or i try not to) because i really try to learn from you ...

To end this post i just want to say how insulted i feel.... If you think i am not being fair just say so ... don't mock my work or my tentatives to learn JASS, i am not as good as you guys, but one day i will be because i am trying hard ...
Every day i wait hours to see your comments ... it seems that this particularly comment of yours... well i just wished i never see it ...

Omg, ...and now the website says i took too long to write this post .. i will have to log in again ...
 
Last edited by a moderator:
Level 40
Joined
Dec 14, 2005
Messages
10,532
Globals are messy and can be replaced by unwanted values (which i don't want).
Good luck storing a value between functions, then... (well, you can use handle vars, but if you make them easy to access, they're worse than globals (slower + same weaknesses)). Also, you'd have to overwrite them yourself, which wouldn't be a particulairily good idea.

I understand why the JASSCRAFT gives the error but is there a way to fix it ?
Well, just write

JASS:
globals
    rect gg_rct_Region_033
    rect gg_rct_p1_workers_start
endglobals
(If you had anything else, you would add them in too)

And what about coordinates ?
I showed you how to use coordinates (functions like CreateUnit and AddSpecialEffect), but here are some functions that get them:

JASS:
constant native GetUnitX            takes unit whichUnit returns real
constant native GetUnitY            takes unit whichUnit returns real
native GetLocationX             takes location whichLocation returns real
native GetLocationY             takes location whichLocation returns real
native GetRectCenterX           takes rect whichRect returns real
native GetRectCenterY           takes rect whichRect returns real
native GetRectMaxX              takes rect whichRect returns real
native GetRectMaxY              takes rect whichRect returns real
native GetRectMinX              takes rect whichRect returns real
native GetRectMinY              takes rect whichRect returns real
native          GetDestructableX            takes destructable d returns real
native          GetDestructableY            takes destructable d returns real

And what about my trigger sleep action ?
What about it?

2 - replaced the bj_FORCE_ALL_PLAYERS by its value which is "null"
3 - greatly improved the "DisplayTextToForce" call, making it independent from global variables and others.
I don't think null would work as a force. Use bj_FORCE_ALL_PLAYERS. Also, I'm almost definitely sure that bj_FORCE_ALL_PLAYERS is just initialized at map initialization (since it only includes the players that are playing, as far as I know)

As i already asked, is there a way to don't use regions and use Coordinates ??
Ex: CreateUnit bla bla bla (corX, corY, corZ) ????

Because if it makes my scrip more efficient i would like to try it plz.

JASS:
native          CreateUnit              takes player id, integer unitid, real x, real y, real face returns unit
native AddSpecialEffect             takes string modelName, real x, real y returns effect
And so on

-------------------------------------------------------------------

By the way, it's "grateful"

Also, I edited both of your posts (flame+silvenon) to sound a little less offensive.

I don't think he was trying to insult you, flame, but yes, it could have been worded better.

-------------------------------------------------------------------

My sig still beats yours, silv :p
 
Thx purplepoot. I finally understood what coordinates are (Daelin tutorials were just to messy, the only thing some1 could understood is that using them is more efficient but blarg.. what a mess). I will post my script here and post the modifications and problems i still have:

JASS:
globals 
    rect gg_rct_Region_033
    rect gg_rct_p1_workers_start
    group array UnitsTrained //werm, what do i do with this now ?
endglobals                  //Group arrays are really not me speciality
function army_acts takes nothing returns nothing
    local unit t = GetTrainedUnit()
    local rect m = gg_rct_Region_033
    local group g = CreateGroup()
    local group ut = CreateGroup()
    local unit f
    local location p = Location(GetRectCenterX(gg_rct_p1_workers_start), GetRectCenterY(gg_rct_p1_workers_start))
    local player pg = Player(5)
    local player p1 = Player(0) 
    local unit gate = CreateUnit( pg, 'hprt', GetRectCenterX(m), GetRectCenterY(m), 270.0)
    local effect ef = AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", GetRectCenterX(m), GetRectCenterY(m))
    local integer mi = 1
    local integer ri = 1
    local unit h1 = CreateUnit(pg, 'H015', GetRectCenterX(m), GetRectCenterY(m), 90.00)
    local unit array m1
    local unit array r1  
//Another problem to the party (group gt)
//i try add the unit to the group ... but i make no idea what i am doing
    call GroupAddUnit(ut, t)
    set t = null
    if CountUnitsInGroup(ut) == 20 then 
        call DisplayTextToForce (bj_FORCE_ALL_PLAYERS, ( "The First Northrend Army arrived to aid " + ( GetPlayerName(p1) + "|r and his alliance !!!!! " ) ) )
        call CameraSetTargetNoiseEx(10, 500000, true)
        call CameraSetSourceNoiseEx(10, 500000, true)
        call GroupEnumUnitsInRect(ut, m, null)
//Here i create the m1 units        
        loop 
            exitwhen mi > 4
            set m1[mi] = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
            set mi = mi +1
        endloop
// Here i create the r1 units        
        loop 
            exitwhen  ri > 4
            set r1[ri] = CreateUnit(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)    
            set ri = ri +1
        endloop
//Here i order m1 and r1 to attack-move to loc      
        loop
            set f = FirstOfGroup(g)
            exitwhen f == null
            call IssuePointOrder(f, "attack", GetRectCenterX(m), GetRectCenterY(m))
            call GroupRemoveUnit(g, f)
        endloop
//More 1 problem, i don't know if this "calls" are coorect (the group)
// Problem 2: I try to make the trigger wait until all units of group "ut" are in the region, but i don't know how to 
//do that so i use "RandomUnitFromUnitGroup" which i don't like ... Hope i replace it soon
//Also i don't know how to remove the RMaxBJ and i want to remove it
        call DestroyEffect(ef)
        call KillUnit( gate )
        loop 
            exitwhen RectContainsUnit(gg_rct_p1_workers_start, GroupPickRandomUnit(ut)) == true 
            call TriggerSleepAction(RMaxBJ(0.10, 0.50))
        endloop     
//Here i change the ownership of the units to player1
        loop
            set mi = 0
            exitwhen mi > 4
            call SetUnitOwner(m1[mi], p1, true)
            set mi = mi +1
        endloop
        loop 
            set ri = 0
            exitwhen ri > 4
            call SetUnitOwner(r1[ri], p1, true)
            set ri = ri + 1
        endloop
//Here i shut the system down and nullify everyting
// I hope it is everyting ok down here
        call SetUnitOwner(h1, p1, true)
        call CameraSetTargetNoiseEx(0, 0, true)
        call CameraSetSourceNoiseEx(0, 0, true)
        call RemoveRect(m)
        call RemoveLocation(p)
        call DestroyGroup (ut)
        call DestroyGroup(g)
        set gate = null
        set ef = null
        set m = null
        set p = null
        set m1[mi] = null
        set r1[ri] = null
        set h1 = null
        set pg = null
        set p1 = null
        set g = null
        set ut = null
//Here i make sure i can only use this trigger once
        call DestroyTrigger(GetTriggeringTrigger())
    endif
endfunction
//===========================================================================
function InitTrig_Army_P1 takes nothing returns nothing
    local trigger army = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEvent(army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH, null)
    call TriggerAddAction( army, function army_acts )
    set army = null
endfunction

Changes:
1- added the globals, and added a group array global which i will soon try to figure out how it is supposed to be used.
2 - re-changed the bj_FORCE_ALL_PLAYERS again. Still, According to JassCraft:
JASS:
force bj_FORCE_ALL_PLAYERS = null
which kinda confuses me, but according Daelin i also know that sometimes Bj's are faster(not usually).
3 - the problem with the wait: i want the trigger to wait until all units of the group are inside the region .. but that doesn't happen, what happens is that the trigger choose a random unit and than when that unit reaches the area the wait ends... that unit could be te 1st or the last with no order and i want that to happen when all units are inside the area ... i already tried to do it but i don't know how ... that is my problem ... i will keep trying (won't give up just because it didn't work at the first time) but some tips would definitely be appreciated.

These are the major changes, i think it is everything for now.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Response to no#2: As I said, it's initialized at the start of the game. (bj_FORCE_ALL_PLAYERS). And bj globals (variables) have nothing to do with BJ functions in terms of efficiency and such.
Response to no#3: You'd have to loop through the group and make sure every unit can be found inside. Something like (assuming g contains the units you have - it's your global group. I just def'd it as a local here for readability):

JASS:
local group g = CreateGroup()
local group g2 = CreateGroup()
local unit u
local boolean b = true
//...
loop
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null or not b
        set b = RectContainsUnit(gg_rct_p1_workers_start,u)
        call GroupAddUnit(g2,u)
        call GroupRemoveUnit(g,u)
    endloop
    call DestroyGroup(g)
    set g = g2
    exitwhen b
    set g2 = CreateGroup()
    call TriggerSleepAction(.5)
endloop
 
blarg, i knew that wit problem i had needed to be solved with loops because i already checked stuff in the GUI by converting triggers, but i made no idea it was going to be this complicated ... i mean loops inside loops ?!

Improvement:
JASS:
globals 
    rect gg_rct_Region_033
    rect gg_rct_p1_workers_start
    group array udg_UT //werm, what do i do with this now ?
endglobals            //Group arrays are really not me speciality
function army_acts takes nothing returns nothing
    local integer P1 = 0 //where P1 means player 1 [Player(0)]
    local unit t = GetTrainedUnit()
    local rect m = gg_rct_Region_033
    local group g = CreateGroup()
    local unit f
    local location p = Location(GetRectCenterX(gg_rct_p1_workers_start), GetRectCenterY(gg_rct_p1_workers_start))
    local player pg = Player(5)
    local player p1 = Player(0) 
    local unit gate = CreateUnit( pg, 'hprt', GetRectCenterX(m), GetRectCenterY(m), 270.0)
    local effect ef = AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", GetRectCenterX(m), GetRectCenterY(m))
    local integer mi = 1
    local integer ri = 1
    local unit h1 = CreateUnit(pg, 'H015', GetRectCenterX(m), GetRectCenterY(m), 90.00)
    local unit array m1
    local unit array r1
    local boolean b == true
    local unit u
    local group ng = CreateGroup()
    local group ng2 = CreateGroup()  
//Another problem to the party (group gt)
//i try add the unit to the group ... but i make no idea what i am doing
    call GroupAddUnit(udg_UT[P1], t)
    set t = null
    if CountUnitsInGroup(udg_UT[P1]) == 20 then 
        call DisplayTextToForce (bj_FORCE_ALL_PLAYERS, ( "The First Northrend Army arrived to aid " + ( GetPlayerName(p1) + "|r and his alliance !!!!! " ) ) )
        call CameraSetTargetNoiseEx(10, 500000, true)
        call CameraSetSourceNoiseEx(10, 500000, true)
        call GroupEnumUnitsInRect(udg_UT[P1], m, null)
//Here i create the m1 units        
        loop 
            exitwhen mi > 4
            set m1[mi] = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
            set mi = mi +1
        endloop
// Here i create the r1 units        
        loop 
            exitwhen  ri > 4
            set r1[ri] = CreateUnit(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)    
            set ri = ri +1
        endloop
//Here i order m1 and r1 to attack-move to loc      
        loop
            set f = FirstOfGroup(g)
            exitwhen f == null
            call IssuePointOrder(f, "attack", GetRectCenterX(m), GetRectCenterY(m))
            call GroupRemoveUnit(g, f)
        endloop
//More 1 problem, i don't know if this "calls" are coorect (the group)
// Problem 2: I try to make the trigger wait until all units of group "ut" are in the region, but i don't know how to 
//do that so i use "RandomUnitFromUnitGroup" which i don't like ... Hope i replace it soon
//Also i don't know how to remove the RMaxBJ and i want to remove it
        call DestroyEffect(ef)
        call KillUnit( gate )
        loop 
            loop
                set u = FirstOfGroup(ng)
                exitwhen u == null or not b
                set b = RectContainsUnit(gg_rct_p1_workers_start,u)
                call GroupAddUnit(ng2, u)
                call GroupRemoveUnit(gn, u)
            endloop
            call DestroyGroup(g)
            set ng = ng2
            exitwhen b
            set ng2 = CreateGroup()
            call TriggerSleepAction(0.5)
        endloop     
//Here i change the ownership of the units to player1
        loop
            set mi = 0
            exitwhen mi > 4
            call SetUnitOwner(m1[mi], p1, true)
            set mi = mi +1
        endloop
        loop 
            set ri = 0
            exitwhen ri > 4
            call SetUnitOwner(r1[ri], p1, true)
            set ri = ri + 1
        endloop
//Here i shut the system down and nullify everyting
// I hope it is everyting ok down here
        call SetUnitOwner(h1, p1, true)
        call CameraSetTargetNoiseEx(0, 0, true)
        call CameraSetSourceNoiseEx(0, 0, true)
        call RemoveRect(m)
        call RemoveLocation(p)
        call DestroyGroup (ut)
        call DestroyGroup(g)
        set gate = null
        set ef = null
        set m = null
        set p = null
        set m1[mi] = null
        set r1[ri] = null
        set h1 = null
        set pg = null
        set p1 = null
        set g = null
        set ut = null
//Here i make sure i can only use this trigger once
        call DestroyTrigger(GetTriggeringTrigger())
    endif
endfunction
//===========================================================================
function InitTrig_Army_P1 takes nothing returns nothing
    local trigger army = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEvent(army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH, null)
    call TriggerAddAction( army, function army_acts )
    set army = null
endfunction

Changes:
1-added global group array
2-added player integer for global group
3-created locals for new loop
4- included complicated loop in script

i think that's all rit ? ( i know i can be dummy sometimes =p)
 
Okidoki, changes made, now i destroyed the group. Here is the spell:

JASS:
globals 
    rect gg_rct_Region_033
    rect gg_rct_p1_workers_start
    group array udg_UT //werm, what do i do with this now ?
endglobals            //Group arrays are really not me speciality
function army_acts takes nothing returns nothing
    local integer P1 = 0 //where P1 means player 1 [Player(0)]
    local unit t = GetTrainedUnit()
    local rect m = gg_rct_Region_033
    local group g = CreateGroup()
    local unit f
    local location p = Location(GetRectCenterX(gg_rct_p1_workers_start), GetRectCenterY(gg_rct_p1_workers_start))
    local player pg = Player(5)
    local player p1 = Player(0) 
    local unit gate = CreateUnit( pg, 'hprt', GetRectCenterX(m), GetRectCenterY(m), 270.0)
    local effect ef = AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", GetRectCenterX(m), GetRectCenterY(m))
    local integer mi = 1
    local integer ri = 1
    local unit h1 = CreateUnit(pg, 'H015', GetRectCenterX(m), GetRectCenterY(m), 90.00)
    local unit array m1
    local unit array r1
    local boolean b == true
    local unit u
    local group ng = CreateGroup()
    local group ng2 = CreateGroup()  
//Another problem to the party (group gt)
//i try add the unit to the group ... but i make no idea what i am doing
    call GroupAddUnit(udg_UT[P1], t)
    set t = null
    if CountUnitsInGroup(udg_UT[P1]) == 20 then 
        call DisplayTextToForce (bj_FORCE_ALL_PLAYERS, ( "The First Northrend Army arrived to aid " + ( GetPlayerName(p1) + "|r and his alliance !!!!! " ) ) )
        call CameraSetTargetNoiseEx(10, 500000, true)
        call CameraSetSourceNoiseEx(10, 500000, true)
        call GroupEnumUnitsInRect(udg_UT[P1], m, null)
//Here i create the m1 units        
        loop 
            exitwhen mi > 4
            set m1[mi] = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
            set mi = mi +1
        endloop
// Here i create the r1 units        
        loop 
            exitwhen  ri > 4
            set r1[ri] = CreateUnit(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)    
            set ri = ri +1
        endloop
//Here i order m1 and r1 to attack-move to loc      
        loop
            set f = FirstOfGroup(g)
            exitwhen f == null
            call IssuePointOrder(f, "attack", GetRectCenterX(m), GetRectCenterY(m))
            call GroupRemoveUnit(g, f)
        endloop
//More 1 problem, i don't know if this "calls" are coorect (the group)
// Problem 2: I try to make the trigger wait until all units of group "ut" are in the region, but i don't know how to 
//do that so i use "RandomUnitFromUnitGroup" which i don't like ... Hope i replace it soon
//Also i don't know how to remove the RMaxBJ and i want to remove it
        call DestroyEffect(ef)
        call KillUnit( gate )
        loop 
            loop
                set u = FirstOfGroup(ng)
                exitwhen u == null or not b
                set b = RectContainsUnit(gg_rct_p1_workers_start,u)
                call GroupAddUnit(ng2, u)
                call GroupRemoveUnit(ng, u)
            endloop
            call DestroyGroup(g)
            set ng = ng2
            exitwhen b
            set ng2 = CreateGroup()
            call TriggerSleepAction(0.5)
        endloop     
//Here i change the ownership of the units to player1
        loop
            set mi = 0
            exitwhen mi > 4
            call SetUnitOwner(m1[mi], p1, true)
            set mi = mi +1
        endloop
        loop 
            set ri = 0
            exitwhen ri > 4
            call SetUnitOwner(r1[ri], p1, true)
            set ri = ri + 1
        endloop
//Here i shut the system down and nullify everyting
// I hope it is everyting ok down here
        call SetUnitOwner(h1, p1, true)
        call CameraSetTargetNoiseEx(0, 0, true)
        call CameraSetSourceNoiseEx(0, 0, true)
        call RemoveRect(m)
        call RemoveLocation(p)
        call DestroyGroup (ut)
        call DestroyGroup(ng)
        set gate = null
        set ef = null
        set m = null
        set p = null
        set m1[mi] = null
        set r1[ri] = null
        set h1 = null
        set pg = null
        set p1 = null
        set g = null
        set ut = null
//Here i make sure i can only use this trigger once
        call DestroyTrigger(GetTriggeringTrigger())
    endif
endfunction
//===========================================================================
function InitTrig_Army_P1 takes nothing returns nothing
    local trigger army = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEvent(army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH, null)
    call TriggerAddAction( army, function army_acts )
    set army = null
endfunction

still it has 5 stupid errors ... and most of them are undeclared variables which are declared .. program bug maybe ?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
What's wrong;

Here we go, lines and errors. (All but the following 3 errors were due to the error on Line 23)

Line: ---- Error Def: --------- Explanation (by me)

Line 23: Syntax Error: local boolean b == true should be local boolean b = true

Line 94: Undeclared variable: ut: call DestroyGroup (ut) ut does not exist.

Note: if you fix Line 94, you get another error (unless you actually created ut...);

Line 107: Undeclared variable: ut: set ut = null ut does not exist.

I'm guessing ut should be udg_UT[P1]
 
Ok, thx by all help, i don't know if it works now, but i just hope it does. I am just kinda afraid of all those loops and arrays i don't know how to control. =S. And no, i don't want to nullify my global =P. It will keep growing and growing. Like here it is activated when the number is 20, but if this trigger works, i will make work also with other numbers such as 40 60 and so on.

Final Version ???
JASS:
globals 
    rect gg_rct_Region_033
    rect gg_rct_p1_workers_start
    group array udg_UT //werm, what do i do with this now ?
endglobals            //Group arrays are really not me speciality
function army_acts takes nothing returns nothing
    local integer P1 = 0 //where P1 means player 1 [Player(0)]
    local unit t = GetTrainedUnit()
    local rect m = gg_rct_Region_033
    local group g = CreateGroup()
    local unit f
    local location p = Location(GetRectCenterX(gg_rct_p1_workers_start), GetRectCenterY(gg_rct_p1_workers_start))
    local player pg = Player(5)
    local player p1 = Player(0) 
    local unit gate = CreateUnit( pg, 'hprt', GetRectCenterX(m), GetRectCenterY(m), 270.0)
    local effect ef = AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", GetRectCenterX(m), GetRectCenterY(m))
    local integer mi = 1
    local integer ri = 1
    local unit h1 = CreateUnit(pg, 'H015', GetRectCenterX(m), GetRectCenterY(m), 90.00)
    local unit array m1
    local unit array r1
    local boolean b = true
    local unit u
    local group ng = CreateGroup()
    local group ng2 = CreateGroup()  
//Another problem to the party (group gt)
//i try add the unit to the group ... but i make no idea what i am doing
    call GroupAddUnit(udg_UT[P1], t)
    set t = null
    if CountUnitsInGroup(udg_UT[P1]) == 20 then 
        call DisplayTextToForce (bj_FORCE_ALL_PLAYERS, ( "The First Northrend Army arrived to aid " + ( GetPlayerName(p1) + "|r and his alliance !!!!! " ) ) )
        call CameraSetTargetNoiseEx(10, 500000, true)
        call CameraSetSourceNoiseEx(10, 500000, true)
        call GroupEnumUnitsInRect(udg_UT[P1], m, null)
//Here i create the m1 units        
        loop 
            exitwhen mi > 4
            set m1[mi] = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
            set mi = mi +1
        endloop
// Here i create the r1 units        
        loop 
            exitwhen  ri > 4
            set r1[ri] = CreateUnit(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)    
            set ri = ri +1
        endloop
//Here i order m1 and r1 to attack-move to loc      
        loop
            set f = FirstOfGroup(g)
            exitwhen f == null
            call IssuePointOrder(f, "attack", GetRectCenterX(m), GetRectCenterY(m))
            call GroupRemoveUnit(g, f)
        endloop
//More 1 problem, i don't know if this "calls" are coorect (the group)
// Problem 2: I try to make the trigger wait until all units of group "ut" are in the region, but i don't know how to 
//do that so i use "RandomUnitFromUnitGroup" which i don't like ... Hope i replace it soon
//Also i don't know how to remove the RMaxBJ and i want to remove it
        call DestroyEffect(ef)
        call KillUnit( gate )
        loop 
            loop
                set u = FirstOfGroup(ng)
                exitwhen u == null or not b
                set b = RectContainsUnit(gg_rct_p1_workers_start,u)
                call GroupAddUnit(ng2, u)
                call GroupRemoveUnit(ng, u)
            endloop
            call DestroyGroup(g)
            set ng = ng2
            exitwhen b
            set ng2 = CreateGroup()
            call TriggerSleepAction(0.5)
        endloop     
//Here i change the ownership of the units to player1
        loop
            set mi = 0
            exitwhen mi > 4
            call SetUnitOwner(m1[mi], p1, true)
            set mi = mi +1
        endloop
        loop 
            set ri = 0
            exitwhen ri > 4
            call SetUnitOwner(r1[ri], p1, true)
            set ri = ri + 1
        endloop
//Here i shut the system down and nullify everyting
// I hope it is everyting ok down here
        call SetUnitOwner(h1, p1, true)
        call CameraSetTargetNoiseEx(0, 0, true)
        call CameraSetSourceNoiseEx(0, 0, true)
        call RemoveRect(m)
        call RemoveLocation(p)
        call DestroyGroup(ng)
        set gate = null
        set ef = null
        set m = null
        set p = null
        set m1[mi] = null
        set r1[ri] = null
        set h1 = null
        set pg = null
        set p1 = null
        set g = null
//Here i make sure i can only use this trigger once
        call DestroyTrigger(GetTriggeringTrigger())
    endif
endfunction
//===========================================================================
function InitTrig_Army_P1 takes nothing returns nothing
    local trigger army = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEvent(army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH, null)
    call TriggerAddAction( army, function army_acts )
    set army = null
endfunction

Hope so =p
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
PurplePoot said:
Also, I edited both of your posts (flame+silvenon) to sound a little less offensive.

Haha, you made me believe I wrote that :)

Hold your horses Flame, I wasn't trying to insult you or anything. It might have been the result of my bad mood that day.

I read that instead of saying "thank you" you rep someone, I read it in the rules, I think.......or maybe it was on wc3c, I don't know. It just feels right for me that people who deserve a rep gets it.

Nice job helping PurplePoot (not puple Flame!), I would rep you, but the darn rep limitation per person won't let me.

Sorry for any insults Flame (haha, flaming :p), I deeply apologize. I don't want to make enemies, I'm not that kind of guy (and I don't think anyone is).

Just to clear out any missunderstanding, 'to rep someone' means 'to give him a reputation point'.

As you all can see, I'm always avoiding the word 'lol' because everybody uses it and nobody knows why.

PurplePoot said:
My sig still beats yours, silv :p

Just you wait.....the right idea has to come :)

I will probably change the sig about ten times, but that's what people do when they can't think of a good sig :)
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
As you all can see, I'm always avoiding the word 'lol' because everybody uses it and nobody knows why.
lol. Kk, don't worry, I'm joking. You just made me want to do that.

Just you wait.....the right idea has to come :)

I will probably change the sig about ten times, but that's what people do when they can't think of a good sig :)
It take me several tries to come up with my current one, but all of the tries were with DoNothing (DoNothingForPlayer, DoNothingBJ, etc)

Haha, you made me believe I wrote that :)

Hold your horses Flame, I wasn't trying to insult you or anything. It might have been the result of my bad mood that day.

I read that instead of saying "thank you" you rep someone, I read it in the rules, I think.......or maybe it was on wc3c, I don't know. It just feels right for me that people who deserve a rep gets it.

Nice job helping PurplePoot (not puple Flame!), I would rep you, but the darn rep limitation per person won't let me.

Sorry for any insults Flame (haha, flaming :p), I deeply apologize. I don't want to make enemies, I'm not that kind of guy (and I don't think anyone is).

Just to clear out any missunderstanding, 'to rep someone' means 'to give him a reputation point'.

As you all can see, I'm always avoiding the word 'lol' because everybody uses it and nobody knows why.
Pfft, I already have the most rep of any coder on the site (except Daelin, I think, but I don't know if he got that for code anyways) and I would probably have more rep than almost anyone on the site if it wasn't for the 0 rep thing. I don't really need rep. I feed off helping people (I mean, what else am I supposed to do...?), so I don't mind ;). It's his choice x.x
 
My choice is to be fair. I really never used rep points because i didn't know what there were supposed to do (i thought people could only win them in hero contests or stuff like that).
So i will give you all rep points i can =).
Here is the 1st one.

Well, the World Editor says that the globals are not well places, how do i fix that ? it says that it was expecting a line after "endglobal"

what do i do to fix it ?

EDIT: i have another huge problem. Apparently the is executed 100 times .... and i don't know why ...

Rawcodes:
gate = hprt
hero = H015
dwarf melle = h014
dwarf ranged = hrif

Code in map:
JASS:
function army_acts takes nothing returns nothing
    local integer P1 = 0 //where P1 means player 1 [Player(0)]
    local unit t = GetTrainedUnit()
    local rect m = gg_rct_Region_033
    local group g = CreateGroup()
    local unit f
    local location p = Location(GetRectCenterX(gg_rct_p1_workers_start), GetRectCenterY(gg_rct_p1_workers_start))
    local player pg = Player(5)
    local player p1 = Player(0) 
    local unit gate = CreateUnit( pg, 'hprt', GetRectCenterX(m), GetRectCenterY(m), 270.0)
    local effect ef = AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", GetRectCenterX(m), GetRectCenterY(m))
    local integer mi = 1
    local integer ri = 1
    local unit h1 = CreateUnit(pg, 'H015', GetRectCenterX(m), GetRectCenterY(m), 90.00)
    local unit array m1
    local unit array r1
    local boolean b = true
    local unit u
    local group ng = CreateGroup()
    local group ng2 = CreateGroup()  
//Another problem to the party (group gt)
//i try add the unit to the group ... but i make no idea what i am doing
    call GroupAddUnit(udg_UT[P1], t)
    set t = null
    if CountUnitsInGroup(udg_UT[P1]) == 20 then 
        call DisplayTextToForce (bj_FORCE_ALL_PLAYERS, ( "The First Northrend Army arrived to aid " + ( GetPlayerName(p1) + "|r and his alliance !!!!! " ) ) )
        call CameraSetTargetNoiseEx(10, 500000, true)
        call CameraSetSourceNoiseEx(10, 500000, true)
        call GroupEnumUnitsInRect(udg_UT[P1], m, null)
//Here i create the m1 units        
        loop 
            exitwhen mi > 4
            set m1[mi] = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
            set mi = mi +1
        endloop
// Here i create the r1 units        
        loop 
            exitwhen  ri > 4
            set r1[ri] = CreateUnit(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)    
            set ri = ri +1
        endloop
//Here i order m1 and r1 to attack-move to loc      
        loop
            set f = FirstOfGroup(g)
            exitwhen f == null
            call IssuePointOrder(f, "attack", GetRectCenterX(m), GetRectCenterY(m))
            call GroupRemoveUnit(g, f)
        endloop
//More 1 problem, i don't know if this "calls" are coorect (the group)
// Problem 2: I try to make the trigger wait until all units of group "ut" are in the region, but i don't know how to 
//do that so i use "RandomUnitFromUnitGroup" which i don't like ... Hope i replace it soon
//Also i don't know how to remove the RMaxBJ and i want to remove it
        call DestroyEffect(ef)
        call KillUnit( gate )
        loop 
            loop
                set u = FirstOfGroup(ng)
                exitwhen u == null or not b
                set b = RectContainsUnit(gg_rct_p1_workers_start,u)
                call GroupAddUnit(ng2, u)
                call GroupRemoveUnit(ng, u)
            endloop
            call DestroyGroup(g)
            set ng = ng2
            exitwhen b
            set ng2 = CreateGroup()
            call TriggerSleepAction(0.5)
        endloop     
//Here i change the ownership of the units to player1
        loop
            set mi = 0
            exitwhen mi > 4
            call SetUnitOwner(m1[mi], p1, true)
            set mi = mi +1
        endloop
        loop 
            set ri = 0
            exitwhen ri > 4
            call SetUnitOwner(r1[ri], p1, true)
            set ri = ri + 1
        endloop
//Here i shut the system down and nullify everyting
// I hope it is everyting ok down here
        call SetUnitOwner(h1, p1, true)
        call CameraSetTargetNoiseEx(0, 0, true)
        call CameraSetSourceNoiseEx(0, 0, true)
        call RemoveRect(m)
        call RemoveLocation(p)
        call DestroyGroup(ng)
        set gate = null
        set ef = null
        set m = null
        set p = null
        set m1[mi] = null
        set r1[ri] = null
        set h1 = null
        set pg = null
        set p1 = null
        set g = null
//Here i make sure i can only use this trigger once
        call DestroyTrigger(GetTriggeringTrigger())
    endif
endfunction
//===========================================================================
function InitTrig_Army_P1 takes nothing returns nothing
    local trigger army = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEvent(army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH, null)
    call TriggerAddAction( army, function army_acts )
    set army = null
endfunction

When the trigger is activated it keeps self repeating and it never stops ... why ?

Image1.jpg

This is what happens ... it should only be 1 gate .. in fact the units may be created correctly, but because they receive no order they never get to the new location and the trigger never ends ..

any help ?
 
Last edited by a moderator:
Ok, i have really being thinking on the problem lately and i did some changes in my script but something is wrong again. Here it is:

JASS:
globals 
    rect gg_rct_Region_033
    rect gg_rct_p1_workers_start
    group array udg_UT //werm, what do i do with this now ?
endglobals            //Group arrays are really not me speciality
//============================================================
function army_acts takes nothing returns nothing
    local integer P1 = 0 //where P1 means player 1 [Player(0)]
    local unit t = GetTrainedUnit()
    local rect m = gg_rct_Region_033
    local group g = CreateGroup()
    local unit f
    local location p = Location(GetRectCenterX(gg_rct_p1_workers_start), GetRectCenterY(gg_rct_p1_workers_start))
    local player pg = Player(5)
    local player p1 = Player(0) 
    local unit gate
    local effect ef
    local integer mi = 1
    local integer ri = 1
    local unit h1
    local unit array m1
    local unit array r1
    local boolean b = true
    local unit u
    local group ng = CreateGroup()
    local group ng2 = CreateGroup()  
//Another problem to the party (group gt)
//i try add the unit to the group ... but i make no idea what i am doing
    call GroupAddUnit(udg_UT[P1], t)
    set t = null
    if CountUnitsInGroup(udg_UT[P1]) == 20 then 
        set h1 = CreateUnit(pg, 'H015', GetRectCenterX(m), GetRectCenterY(m), 90.00)
        set gate = CreateUnit( pg, 'hprt', GetRectCenterX(m), GetRectCenterY(m), 270.0)
        set ef = AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", GetRectCenterX(m), GetRectCenterY(m))  
        call DisplayTextToForce (bj_FORCE_ALL_PLAYERS, ( "The First Northrend Army arrived to aid " + ( GetPlayerName(p1) + "|r and his alliance !!!!! " ) ) )
        call CameraSetTargetNoiseEx(10, 500000, true)
        call CameraSetSourceNoiseEx(10, 500000, true)
        call GroupEnumUnitsInRect(udg_UT[P1], m, null)
//Here i create the m1 units        
        loop 
            exitwhen mi > 4
            set m1[mi] = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
            set mi = mi +1
        endloop
// Here i create the r1 units        
        loop 
            exitwhen  ri > 4
            set r1[ri] = CreateUnit(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)    
            set ri = ri +1
        endloop
//Here i order m1 and r1 to attack-move to loc      
        loop
            set f = FirstOfGroup(g)
            exitwhen f == null
            call IssuePointOrder(f, "attack", GetRectCenterX(m), GetRectCenterY(m))
            call GroupRemoveUnit(g, f)
        endloop
//More 1 problem, i don't know if this "calls" are coorect (the group)
// Problem 2: I try to make the trigger wait until all units of group "ut" are in the region, but i don't know how to 
//do that so i use "RandomUnitFromUnitGroup" which i don't like ... Hope i replace it soon
//Also i don't know how to remove the RMaxBJ and i want to remove it
        call DestroyEffect(ef)
        call KillUnit( gate )
        loop 
            loop
                set u = FirstOfGroup(ng)
                exitwhen u == null or not b
                set b = RectContainsUnit(gg_rct_p1_workers_start,u)
                call GroupAddUnit(ng2, u)
                call GroupRemoveUnit(ng, u)
            endloop
            call DestroyGroup(g)
            set ng = ng2
            exitwhen b
            set ng2 = CreateGroup()
            call TriggerSleepAction(0.5)
        endloop     
//Here i change the ownership of the units to player1
        loop
            set mi = 0
            exitwhen mi > 4
            call SetUnitOwner(m1[mi], p1, true)
            set mi = mi +1
        endloop
        loop 
            set ri = 0
            exitwhen ri > 4
            call SetUnitOwner(r1[ri], p1, true)
            set ri = ri + 1
        endloop
//Here i shut the system down and nullify everyting
// I hope it is everyting ok down here
        call SetUnitOwner(h1, p1, true)
        call CameraSetTargetNoiseEx(0, 0, true)
        call CameraSetSourceNoiseEx(0, 0, true)
        call RemoveRect(m)
        call RemoveLocation(p)
        call DestroyGroup(ng)
        set gate = null
        set ef = null
        set m = null
        set p = null
        set m1[mi] = null
        set r1[ri] = null
        set h1 = null
        set pg = null
        set p1 = null
        set g = null
//Here i make sure i can only use this trigger once
        call DestroyTrigger(GetTriggeringTrigger())
    endif
endfunction
//===========================================================================
function InitTrig_Army_P1 takes nothing returns nothing
    local trigger army = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEvent(army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH, null)
    call TriggerAddAction( army, function army_acts )
    set army = null
endfunction

Changes:
1 - Changed the local unit h1 and gate position among with the special effects position inside the if trigger, thus making them appear in the correct timing.
2 - Nothing else

Problems:
1 - the 10000 gate problem the picture shows is now eliminated. However it gave origin to problem 2.
2 - Now the only thing that happens is that 9 units are created. There is no gate and no special effect and i don't know why.
3 - the units never change the ownership, and i don't know why that happens

Any suggestions ?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
I don't see why the gate doesn't appear (that's 'hprt', right?)

Oh, could you please update the comments inside the script?

Ownership --

Move 'set m1 = 0' and 'set r1 = 0' out of their respective loops (with SetUnitOwner), to BEFORE them. That's what causing the trigger not to be destroyed among other things. (That may also have caused the portal bug...)

Eg;

JASS:
//you have
loop
    set mi = 0
    exitwhen mi > 4
    call SetUnitOwner(m1[mi],p1,true)
    set mi = mi + 1
endloop
loop
    set ri = 0
    exitwhen ri > 4
    call SetUnitOwner(r1[ri],p1,true)
    set ri = ri + 1
endloop

//you should use
set mi = 0
loop
    exitwhen mi > 4
    call SetUnitOwner(m1[mi],p1,true)
    set mi = mi + 1
endloop
set ri = 0
loop
    exitwhen ri > 4
    call SetUnitOwner(r1[ri],p1,true)
    set ri = ri + 1
endloop
 
Done.

script:
JASS:
globals 
    rect gg_rct_Region_033
    rect gg_rct_p1_workers_start
    group array udg_UT 
endglobals           
//============================================================
function army_acts takes nothing returns nothing
    local integer P1 = 0 
    local unit t = GetTrainedUnit()
    local rect m = gg_rct_Region_033
    local group g = CreateGroup()
    local unit f
    local location p = Location(GetRectCenterX(gg_rct_p1_workers_start), GetRectCenterY(gg_rct_p1_workers_start))
    local player pg = Player(5)
    local player p1 = Player(0) 
    local unit gate
    local effect ef
    local integer mi = 1
    local integer ri = 1
    local unit h1
    local unit array m1
    local unit array r1
    local boolean b = true
    local unit u
    local group ng = CreateGroup()
    local group ng2 = CreateGroup()  
    call GroupAddUnit(udg_UT[P1], t)
    set t = null
    if CountUnitsInGroup(udg_UT[P1]) == 20 then 
        set h1 = CreateUnit(pg, 'H015', GetRectCenterX(m), GetRectCenterY(m), 90.00)
        set gate = CreateUnit( pg, 'hprt', GetRectCenterX(m), GetRectCenterY(m), 270.0)
        set ef = AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTo.mdl", GetRectCenterX(m), GetRectCenterY(m))  
        call DisplayTextToForce (bj_FORCE_ALL_PLAYERS, ( "The First Northrend Army arrived to aid " + ( GetPlayerName(p1) + "|r and his alliance !!!!! " ) ) )
        call CameraSetTargetNoiseEx(10, 500000, true)
        call CameraSetSourceNoiseEx(10, 500000, true)
        call GroupEnumUnitsInRect(udg_UT[P1], m, null)      
        loop 
            exitwhen mi > 4
            set m1[mi] = CreateUnit(pg, 'h014', GetRectCenterX(m), GetRectCenterY(m), 90.00)
            set mi = mi +1
        endloop      
        loop 
            exitwhen  ri > 4
            set r1[ri] = CreateUnit(pg, 'hrif', GetRectCenterX(m), GetRectCenterY(m), 90.00)    
            set ri = ri +1
        endloop      
        loop
            set f = FirstOfGroup(g)
            exitwhen f == null
            call IssuePointOrder(f, "attack", GetRectCenterX(m), GetRectCenterY(m))
            call GroupRemoveUnit(g, f)
        endloop
        call DestroyEffect(ef)
        call KillUnit( gate )
        loop 
            loop
                set u = FirstOfGroup(ng)
                exitwhen u == null or not b
                set b = RectContainsUnit(gg_rct_p1_workers_start,u)
                call GroupAddUnit(ng2, u)
                call GroupRemoveUnit(ng, u)
            endloop
            call DestroyGroup(g)
            set ng = ng2
            exitwhen b
            set ng2 = CreateGroup()
            call TriggerSleepAction(0.5)
        endloop     
        set mi = 0
        loop
            exitwhen mi > 4
            call SetUnitOwner(m1[mi], p1, true)
            set mi = mi +1
        endloop
        set ri = 0
        loop 
            exitwhen ri > 4
            call SetUnitOwner(r1[ri], p1, true)
            set ri = ri + 1
        endloop
        call SetUnitOwner(h1, p1, true)
        call CameraSetTargetNoiseEx(0, 0, true)
        call CameraSetSourceNoiseEx(0, 0, true)
        call RemoveRect(m)
        call RemoveLocation(p)
        call DestroyGroup(ng)
        set gate = null
        set ef = null
        set m = null
        set p = null
        set m1[mi] = null
        set r1[ri] = null
        set h1 = null
        set pg = null
        set p1 = null
        set g = null
        call DestroyTrigger(GetTriggeringTrigger())
    endif
endfunction
//===========================================================================
function InitTrig_Army_P1 takes nothing returns nothing
    local trigger army = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEvent(army, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH, null)
    call TriggerAddAction( army, function army_acts )
    set army = null
endfunction


Array !
Good news and bad news.
Good:
1 - The units are created
2 - The unit are given to the player
Bad:
1 - The gate and the special effect are not created
2 - The camera no longer shakes
3 - The only thing that happens is that player 1 gets 9 new units
4 - Game crashes instantly and creates a critical error message

Now i am exhausted trying to find a solution for this dam problem but i can't ... any more opinions ?
 
Last edited:
Status
Not open for further replies.
Top