1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

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

Discussion in 'Triggers & Scripts' started by Flame_Phoenix, Aug 28, 2007.

  1. Flame_Phoenix

    Flame_Phoenix

    Joined:
    May 4, 2007
    Messages:
    2,283
    Resources:
    11
    Tools:
    1
    Maps:
    1
    Spells:
    6
    Tutorials:
    3
    Resources:
    11
    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:

    Code (vJASS):
    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.
     
  2. Silvenon

    Silvenon

    Joined:
    Nov 22, 2006
    Messages:
    1,233
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Code (vJASS):
    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:

    Code (vJASS):
    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:

    Code (vJASS):
    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
     
  3. Flame_Phoenix

    Flame_Phoenix

    Joined:
    May 4, 2007
    Messages:
    2,283
    Resources:
    11
    Tools:
    1
    Maps:
    1
    Spells:
    6
    Tutorials:
    3
    Resources:
    11
    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:

    Code (vJASS):
    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:
    Code (vJASS):
    call CameraSetTargetNoiseEx(10, 5*Pow(10, 5), true)
            call CameraSetSourceNoiseEx(10, 5*Pow(10, 5), true)

    and will display the following text using:
    Code (vJASS):
    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: Aug 29, 2007
  4. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    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 ;)
     
  5. Flame_Phoenix

    Flame_Phoenix

    Joined:
    May 4, 2007
    Messages:
    2,283
    Resources:
    11
    Tools:
    1
    Maps:
    1
    Spells:
    6
    Tutorials:
    3
    Resources:
    11
    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:
    Code (vJASS):
    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 ?
     
  6. Silvenon

    Silvenon

    Joined:
    Nov 22, 2006
    Messages:
    1,233
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    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.

    A location consists of two coordinates, x and y.

    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.

    Code (vJASS):
    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.

    Code (vJASS):
    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)):

    Code (vJASS):
    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.

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

    Not everything......

    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
     
  7. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    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:

    Code (vJASS):
    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.
     
  8. Flame_Phoenix

    Flame_Phoenix

    Joined:
    May 4, 2007
    Messages:
    2,283
    Resources:
    11
    Tools:
    1
    Maps:
    1
    Spells:
    6
    Tutorials:
    3
    Resources:
    11
    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..


    Code (vJASS):
    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:
    Code (vJASS):
    // 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.
     
  9. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    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.
     
  10. Flame_Phoenix

    Flame_Phoenix

    Joined:
    May 4, 2007
    Messages:
    2,283
    Resources:
    11
    Tools:
    1
    Maps:
    1
    Spells:
    6
    Tutorials:
    3
    Resources:
    11
    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):
    Code (vJASS):
    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.
     
  11. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    local location p = gg_rct_p1_workers_start
    you'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 = 1
    uses 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.
     
  12. Silvenon

    Silvenon

    Joined:
    Nov 22, 2006
    Messages:
    1,233
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    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
     
  13. Flame_Phoenix

    Flame_Phoenix

    Joined:
    May 4, 2007
    Messages:
    2,283
    Resources:
    11
    Tools:
    1
    Maps:
    1
    Spells:
    6
    Tutorials:
    3
    Resources:
    11
    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:
    Code (vJASS):
    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 ?
     
  14. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    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
     
  15. Flame_Phoenix

    Flame_Phoenix

    Joined:
    May 4, 2007
    Messages:
    2,283
    Resources:
    11
    Tools:
    1
    Maps:
    1
    Spells:
    6
    Tutorials:
    3
    Resources:
    11
  16. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    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!
     
  17. Flame_Phoenix

    Flame_Phoenix

    Joined:
    May 4, 2007
    Messages:
    2,283
    Resources:
    11
    Tools:
    1
    Maps:
    1
    Spells:
    6
    Tutorials:
    3
    Resources:
    11
    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:
    Code (vJASS):
    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:
    Code (vJASS):
    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:
    Code (vJASS):
    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: Aug 30, 2007
  18. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    No, you have to use a unit... Integers != units.

    Try using a unit array though. Eg.

    Code (vJASS):
    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


    Use a unit group array (one group per player)



    And that spell would be MUI if it compiled.
     
  19. Flame_Phoenix

    Flame_Phoenix

    Joined:
    May 4, 2007
    Messages:
    2,283
    Resources:
    11
    Tools:
    1
    Maps:
    1
    Spells:
    6
    Tutorials:
    3
    Resources:
    11
    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:
    Code (vJASS):
    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 ??
     
  20. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    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.