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

Stupid Jass

Status
Not open for further replies.
Level 8
Joined
Jun 16, 2008
Messages
333
I have this jass code that I got from a program to kill when someone touches player 12 for a maze and the it keeps saying there is an error can some one help me with this?
JASS:
function Trig_Collision_UnitCheck takes nothing returns boolean
    if GetOwningPlayer(GetFilterUnit()) == Player(11) then
      return true
    endif

    return false
endfunctionfunction Trig_Collision_Actions takes nothing returns nothing
    local location p
    local unit u
    local group g1
    local group g2
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 9
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if GetPlayerSlotState(ConvertedPlayer(GetForLoopIndexA())) == PLAYER_SLOT_STATE_PLAYING then
         set g1 = GetUnitsOfPlayerAndTypeId(ConvertedPlayer(GetForLoopIndexA()), 'E000')
         set u = GroupPickRandomUnit(g1)
         set p = GetUnitLoc(u)
         set g2 = GetUnitsInRangeOfLocMatching(60.00, p, Condition(function Trig_Collision_UnitCheck))
         if GetBooleanAnd(CountUnitsInGroup(g2) > 0, IsUnitAliveBJ(u) ) then
             call KillUnit( u)
         endif
         call RemoveLocation(p)
         call DestroyGroup(g1)
         call DestroyGroup(g2)
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

function InitTrig_Collision takes nothing returns nothing
    set gg_trg_Collision = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Collision, 0.02 )
    call TriggerAddAction( gg_trg_Collision, function Trig_Collision_Actions )
endfunction
 
JASS:
function Trig_Collision_UnitCheck takes nothing returns boolean
    if GetOwningPlayer(GetFilterUnit()) == Player(11) then
      return true
    endif
endfunction

function Trig_Collision_Actions takes nothing returns nothing
    local location p
    local unit u
    local group g1
    local group g2
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 9
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if GetPlayerSlotState(ConvertedPlayer(GetForLoopIndexA())) == PLAYER_SLOT_STATE_PLAYING then
         set g1 = GetUnitsOfPlayerAndTypeId(ConvertedPlayer(GetForLoopIndexA()), 'E000')
         set u = GroupPickRandomUnit(g1)
         set p = GetUnitLoc(u)
         set g2 = GetUnitsInRangeOfLocMatching(60.00, p, Condition(function Trig_Collision_UnitCheck))
         if GetBooleanAnd(CountUnitsInGroup(g2) > 0, IsUnitAliveBJ(u) ) then
             call KillUnit( u)
         endif
         call RemoveLocation(p)
         call DestroyGroup(g1)
         call DestroyGroup(g2)
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Melee_Initialization takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddAction( t, function Trig_Collision_Actions )
endfunction
 
Level 31
Joined
May 3, 2008
Messages
3,155
JASS:
function Trig_Collision_UnitCheck takes nothing returns boolean
    return GetOwningPlayer(GetFilterUnit()) == Player(11) 
endfunction

function Trig_Collision_Actions takes nothing returns nothing
    local location p
    local unit u
    local group g1
    local group g2
    local integer loop=1
    loop
        exitwhen loop > 9
        if GetPlayerSlotState(ConvertedPlayer(loop)) == PLAYER_SLOT_STATE_PLAYING then
         set g1 = GetUnitsOfPlayerAndTypeId(ConvertedPlayer(loop), 'E000')
         set u = GroupPickRandomUnit(g1)
         set p = GetUnitLoc(u)
         set g2 = GetUnitsInRangeOfLocMatching(60.00, p, Condition(function Trig_Collision_UnitCheck))
         if GetBooleanAnd(CountUnitsInGroup(g2) > 0, IsUnitAliveBJ(u) ) then
             call KillUnit( u)
         endif
         call RemoveLocation(p)
         call DestroyGroup(g1)
         call DestroyGroup(g2)
        endif
        set loop= loop+ 1
    endloop
endfunction

//===========================================================================
function InitTrig_Melee_Initialization takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddAction( t, function Trig_Collision_Actions )
endfunction
[/QUOTE]

You could have use GetUnitX and GetUnitY since it was much quicker, instead of using IsUnitAliveBJ, you could use GetWidjet (I forgot what is the name of that stupid command) that are much cleaner and efficient.

Cannot help much since I don't have WE with me :p
 
This is it all inlined, I just took advantage of the bj_globals for all the filtering and what-not.

Yeah, it is sloppy but efficient (not really much of a difference compared to using the BJ's but whatever, at least it is more direct):
JASS:
function CollisionUnitCheck takes nothing returns boolean
    if GetOwningPlayer(GetFilterUnit()) == Player(11) then
        set bj_groupCountUnits = bj_groupCountUnits+1
    endif
    return false 
endfunction

function CollisionFilt takes nothing returns boolean
    if GetUnitTypeId(GetFilterUnit()) == bj_groupEnumTypeId then
        set bj_groupRandomConsidered = bj_groupRandomConsidered+1
        if GetRandomInt(1,bj_groupRandomConsidered) == 1 then
            set bj_groupRandomCurrentPick = GetFilterUnit()
        endif
    endif 
    return false
endfunction

function Trig_Collision_Actions takes nothing returns nothing
    local real x
    local real y 
    local unit u
    local group g1  = CreateGroup()
    local integer i = 1
    loop
        exitwhen i > 8
        if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
            set bj_groupEnumTypeId        = 'E000' //For filtering the unit-type
            set bj_groupRandomConsidered  = 0      //For picking a random unit
            set bj_groupRandomCurrentPick = null   //For picking a random unit
            set bj_groupCountUnits        = 0      //For counting the units in the group
            call GroupEnumUnitsOfPlayer(g1,Player(i),Filter(function CollisionFilt))
            set u = bj_groupRandomCurrentPick
            set x = GetUnitX(u)
            set y = GetUnitY(u)
            call GroupEnumUnitsInRange(g1,x,y,60,Filter(function CollisionUnitCheck))
            if bj_groupCountUnits>0 and GetWidgetLife(u)>.405 then
                call KillUnit(u)
            endif
        endif
        set i = i + 1
    endloop
    call DestroyGroup(g1)
    set u  = null
    set g1 = null
endfunction

//===========================================================================
function InitTrig_Melee_Initialization takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddAction( t, function Trig_Collision_Actions )
endfunction
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Ugh. That code seriously needs a makeover. Could be better if you used vJass (such as using a global group).

JASS:
function Trig_Collision_Filter takes nothing returns boolean
    return GetOwningPlayer(GetFilterUnit()) == Player(11)
endfunction

function Trig_Collision_TID takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit()) == 'E000' and not IsUnitType(GetFilterUnit(),UNIT_TYPE_DEAD)
endfunction

function Trig_Collision_Actions takes nothing returns nothing
    local unit u
    local group g = CreateGroup()
    local integer i = 0
    loop
        exitwhen i > 8
        if GetPlayerSlotState(i) == PLAYER_SLOT_STATE_PLAYING then
            call GroupEnumUnitsOfPlayer(g,Player(i),Filter(function Trig_Collision_TID))
            set u = GroupPickRandomUnit(g)
            call GroupEnumUnitsInRange(g,GetUnitX(u),GetUnitY(u),60.,Filter(function Trig_Collision_Filter))
            if FirstOfGroup(g) != null then
                call KillUnit(u)
            endif
        endif
        set i = i + 1
    endloop
    call DestroyGroup(g)
    set g = null
    set u = null
endfunction

//your init trig was wrong, since I assume you don't just want this to run at the start of the game, since that would be... stupid, to say the least.
 
@PurplePoot: Yeah, you're right. I didn't really consider what the code was actually doing.

@iown_azz: You have to have a function called InitTrig_collision at the bottom. Example:
JASS:
function InitTrig_collision takes nothing returns nothing
 //create trigger
 //register event
 //add actions, conditions etc.
endfunction

When do you want this trigger to fire? (As in, after what event?)
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Sorry for the jack, I'm on a really slow connection (plus I had to write the code) so I started posting before yours was up.

He presumably wants the trigger to fire at an interval, since it's for a maze. However, I don't understand why he isn't just using immolation.

So I'll go ahead and guess this is what he needs:

JASS:
function InitTrig_Collision takes nothing returns nothing //I put caps on Collision since he said the trigger was called "Collision", not "collision"
    call TimerStart(CreateTimer(),.2,true,function Trig_Collision_Actions)
endfunction
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
I gave you a function to use above. It goes at the bottom of the script, so you can just copy-paste this in for the entire script. Your trigger must be named Collision with a capital C.

JASS:
function Trig_Collision_Filter takes nothing returns boolean
    return GetOwningPlayer(GetFilterUnit()) == Player(11)
endfunction

function Trig_Collision_TID takes nothing returns boolean
    local unit u = GetFilterUnit()
    local group g = CreateGroup()
    if GetUnitTypeId(u) == 'E000' and not IsUnitType(u,UNIT_TYPE_DEAD) then
        call GroupEnumUnitsInRange(g,GetUnitX(u),GetUnitY(u),60.,Filter(function Trig_Collision_Filter))
        if FirstOfGroup(g) != null then
            call KillUnit(u)
        endif
    endif
    call DestroyGroup(g)
    set g = null
    set u = null
    return false
endfunction

function Trig_Collision_Actions takes nothing returns nothing
    local group g = CreateGroup()
    local integer i = 0
    loop
        exitwhen i > 8
        if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
            call GroupEnumUnitsOfPlayer(g,Player(i),Filter(function Trig_Collision_TID))
        endif
        set i = i + 1
    endloop
    call DestroyGroup(g)
    set g = null
endfunction

function InitTrig_Collision takes nothing returns nothing
    call TimerStart(CreateTimer(),.2,true,function Trig_Collision_Actions)
endfunction

EDIT: I just realized I had copied what you guys were doing without noticing that it was flawed.

Fixing... I will edit again to tell you when it's fixed.

EDIT2: Fixed.
 
Status
Not open for further replies.
Top