Unit Group in struct not working.

Zalinian

New Member
Reaction score
0
[FIXED]Unit Group in struct not working.

I'm trying to set units within range of a unit matching certain conditions to a group. However the units are not being added in.

Condition function:
JASS:

static method lightning_chain_check takes nothing returns boolean
    local elementalist_wrath this = temp_struct
	return IsUnitAliveBJ(GetFilterUnit()) == true and GetFilterUnit() != (.l_current_target) and IsUnitEnemy(GetFilterUnit(), (.owner)) == true
endmethod

Block of code setting the group.
JASS:

call GroupEnumUnitsInRange(this.l_random_targets, GetUnitX(this.l_current_target), GetUnitY(this.l_current_target), 1000.00, Condition (function elementalist_wrath.lightning_chain_check))
set this.l_new_target = GroupPickRandomUnit(this.l_random_targets)
call BJDebugMsg(GetUnitName(this.l_new_target))


I checked with the debug, it detects the current target and its location fine, so its something with the condition, or something with the struct. I'm new to this so any help would be appreciated.

I also have this before the struct for use in the condition methods
JASS:
globals
   elementalist_wrath temp_struct
endglobals

The struct is called elementalist_wrath
 

Zalinian

New Member
Reaction score
0
Any help at all? This problem has been driving me crazy for nearly two weeks.

Pretty much the problem is I need to use a static method for the condition part of grouping the units. However, using a static method doesn't allow me to use the data stored in the struct (this.blahblah), therefor I can't filter the units correctly.
 

Zalinian

New Member
Reaction score
0
Alright, its quite complex though. This should be the original code with the problem (I've been editing like mad trying to fix it).

Its a chain lightning, with each hit making a forked lightning come off, chaining 'orbs_l' number of times. The fire and ice parts haven't been coded yet. Everything else works fine, just not the condition part for the unit groups.

JASS:
globals
    elementalist_wrath temp_struct
endglobals
  
struct elementalist_wrath
// Main Varaibles
    unit caster
    player owner
    integer owner_id
    real spell_power
    integer orbs_f
    integer orbs_i
    integer orbs_l
    integer ability_level
    integer orb_level
    // Combat Variables
        // Fire
        // Ice
        // Lightning
    unit l_current_target
	unit l_new_target
	unit l_chain_caster
	unit l_fork_caster
	group l_random_targets
	group l_fork_damage
    location l_point
    // Tally Orbs
    integer slot_num
//  ==========      Wrath-Lightning Method        ==========
static method fork_damage_check takes nothing returns boolean //PROBLEM
    local elementalist_wrath this = temp_struct
    return (IsUnitEnemy(GetFilterUnit(),(.owner)) == true)
endmethod
static method fork_damage takes nothing returns nothing //PROBLEM
    local elementalist_wrath this = temp_struct
    call UnitDamageTarget((.caster), GetEnumUnit(), (.spell_power / 4.00 ), true, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_LIGHTNING, null )
endmethod
static method lightning_chain_check takes nothing returns boolean //PROBLEM
    local elementalist_wrath this = temp_struct
	return IsUnitAliveBJ(GetFilterUnit()) == true and GetFilterUnit() != (.l_current_target) and IsUnitEnemy(GetFilterUnit(), (.owner)) == true
endmethod
method wrath_lightning takes nothing returns nothing
    local integer start
    local integer end
    set this.l_current_target = this.caster
    set start = 1
    set end = ( this.orbs_l )
    loop
        exitwhen start > end
        set this.l_point = GetUnitLoc(this.l_current_target)
        call CreateNUnitsAtLoc( 1, 'h008',(this.owner),(this.l_point), bj_UNIT_FACING )
        set this.l_chain_caster = GetLastCreatedUnit()
        call UnitApplyTimedLifeBJ(0.50, 'BTLF', this.l_chain_caster)
        set this.l_random_targets = GetUnitsInRangeOfLocMatching(1000.00, this.l_point, Condition (function elementalist_wrath.lightning_chain_check)) // PROBLEM HERE
        set this.l_new_target = GroupPickRandomUnit(this.l_random_targets)
        call IssueTargetOrderById( this.l_chain_caster, OrderId("chainlightning"), this.l_new_target )
        call TriggerSleepAction( 0.10 )
        call RemoveLocation(this.l_point)
        call CreateNUnitsAtLoc( 1, 'h008',(this.owner),(this.l_point), bj_UNIT_FACING )
        set this.l_fork_caster = GetLastCreatedUnit()
        call UnitApplyTimedLifeBJ(0.50, 'BTLF', this.l_fork_caster)
        call IssueTargetOrderById( this.l_fork_caster, OrderId("forkedlightning"), this.l_new_target )
        call UnitDamageTargetBJ((this.caster),(this.l_new_target),(this.spell_power), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_LIGHTNING )
        set this.l_fork_damage = GetUnitsInRangeOfLocMatching(250.00 , this.l_point, Condition (function elementalist_wrath.fork_damage_check))
        call TriggerSleepAction( 0.05 )
        call ForGroup(this.l_fork_damage, function elementalist_wrath.fork_damage) //SIMILAR PROBLEM HERE
        set this.l_current_target = this.l_new_target
        set start = start + 1
        call RemoveLocation(this.l_point)
        call GroupClear(this.l_random_targets)
        call GroupClear(this.l_fork_damage)
    endloop   
endmethod
//  ==========      Tally Method     ==========
method tally takes integer player_id, integer orb_level returns nothing
	set this.slot_num = (player_id - 1) * 9
	set this.orbs_f = 0
    set this.orbs_i = 0
    set this.orbs_l = 0

    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = ( orb_level )
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( udg_elementalist_OrbSlotElement[( ( this.slot_num ) + GetForLoopIndexA() )] == "|c00FF0000Fire|r" ) then
            set this.orbs_f = ( ( this.orbs_f ) + 1 )
        elseif ( udg_elementalist_OrbSlotElement[( ( this.slot_num ) + GetForLoopIndexA() )] == "|c000000FFIce|r" ) then
            set this.orbs_i = ( ( this.orbs_i ) + 1 )
        elseif (udg_elementalist_OrbSlotElement[( ( this.slot_num ) + GetForLoopIndexA() )] == "|c00FFFF00Lightning|r" ) then
            set this.orbs_l = ( ( this.orbs_l ) + 1 )
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endmethod
endstruct
//  ==========        Primary Function       ==========
function Wrath_of_Elements takes nothing returns nothing
    local elementalist_wrath data = elementalist_wrath.create()
    set data.caster = GetSpellAbilityUnit()
    set data.orb_level = GetUnitAbilityLevelSwapped('A00F' , ( data.caster ))
	set data.ability_level = GetUnitAbilityLevelSwapped('A00O' , ( data.caster ))
	set data.spell_power = ( 1000.00 + ( ( 1 + ( 0.50 * I2R(data.ability_level) ) ) * ( 10.00 * I2R(GetHeroStatBJ(bj_HEROSTAT_INT , ( data.caster ) , true)) ) ) )
	set data.owner = GetOwningPlayer(GetSpellAbilityUnit())
	set data.owner_id = GetConvertedPlayerId(( data.owner ))
		// [power is = to: 1000 + (1 + 0.5*Ability level)*(10*hero int)]
	call data.tally(data.owner_id, data.orb_level)
    call data.wrath_lightning()
    call BJDebugMsg( "Fire: " + I2S((data.orbs_f)))
    call BJDebugMsg( "Ice: " + I2S((data.orbs_i)))
    call BJDebugMsg( "Lightning: " + I2S((data.orbs_l)))
    call TriggerSleepAction( 10 )
    call data.destroy()
endfunction
//===========================================================================
function Trig_Wrath_Test_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A00O' )
endfunction
//===========================================================================
function InitTrig_Wrath_Test takes nothing returns nothing
    set gg_trg_Wrath_Test = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Wrath_Test, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Wrath_Test, Condition( function Trig_Wrath_Test_Conditions ) )
    call TriggerAddAction( gg_trg_Wrath_Test, function Wrath_of_Elements )
endfunction
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
You never do [ljass]set temp_struct = this[/ljass] . You should to that in the beginning of the wrath_lightning method.
You're also leaking groups. GetUnitsInRangeOfLocMatching creates a new group which you never destroy, GroupClear does not destroy the group. Simply replace GroupClear with DestroyGroup (alternatively use just one unit group).
This might be of interest: http://wiki.thehelper.net/wc3/Group_API
 

chobibo

Level 1 Crypt Lord
Reaction score
48
JASS:
static method lightning_chain_check takes elementalist_wrath object returns boolean
    local elementalist_wrath this = object


include the struct as a parameter to the static methods.
 

Zalinian

New Member
Reaction score
0
OK, I made some changes and added in that one line (its always one stupid small thing that screws everything up....). It works now.
Final code:
JASS:
globals
    elementalist_wrath temp_struct
endglobals
  
struct elementalist_wrath
// Main Varaibles
    unit caster
    player owner
    integer owner_id
    real spell_power
    integer orbs_f
    integer orbs_i
    integer orbs_l
    integer ability_level
    integer orb_level
    // Combat Variables
        // Fire
        // Ice
        // Lightning
    unit l_current_target
	unit l_new_target
	unit l_chain_caster
	unit l_fork_caster
	group l_random_targets
	group l_fork_damage
    location l_point
    // Tally Orbs
    integer slot_num
//  ==========      Wrath-Lightning Method        ==========
static method fork_damage_check takes nothing returns boolean
    local elementalist_wrath this = temp_struct
    return (IsUnitEnemy(GetFilterUnit(),(.owner)) == true)
endmethod
static method fork_damage takes nothing returns nothing
    local elementalist_wrath this = temp_struct
    call UnitDamageTarget((.caster), GetEnumUnit(), (.spell_power / 4.00 ), true, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_LIGHTNING, null )
endmethod
static method lightning_chain_check takes nothing returns boolean
    local elementalist_wrath this = temp_struct
	return IsUnitAliveBJ(GetFilterUnit()) == true and GetFilterUnit() != (.l_current_target) and IsUnitEnemy(GetFilterUnit(), (.owner)) == true
endmethod
method wrath_lightning takes nothing returns nothing
    local integer start
    local integer end
    set this.l_current_target = this.caster
    set start = 1
    set end = ( this.orbs_l )
    loop
        exitwhen start > end
        set this.l_point = GetUnitLoc(this.l_current_target)
        call CreateNUnitsAtLoc( 1, 'h008',(this.owner),(this.l_point), bj_UNIT_FACING )
        set this.l_chain_caster = GetLastCreatedUnit()
        call UnitApplyTimedLifeBJ(0.50, 'BTLF', this.l_chain_caster)
        set temp_struct = this
        set this.l_random_targets = GetUnitsInRangeOfLocMatching(1000.00, this.l_point, Condition (function elementalist_wrath.lightning_chain_check))
        set this.l_new_target = GroupPickRandomUnit(this.l_random_targets)
        call IssueTargetOrderById( this.l_chain_caster, OrderId("chainlightning"), this.l_new_target )
        call TriggerSleepAction( 0.10 )
        call RemoveLocation(this.l_point)
        set this.l_point = GetUnitLoc(this.l_new_target)
        call CreateNUnitsAtLoc( 1, 'h008',(this.owner),(this.l_point), bj_UNIT_FACING )
        set this.l_fork_caster = GetLastCreatedUnit()
        call UnitApplyTimedLifeBJ(0.50, 'BTLF', this.l_fork_caster)
        call IssueTargetOrderById( this.l_fork_caster, OrderId("forkedlightning"), this.l_new_target )
        call UnitDamageTargetBJ((this.caster),(this.l_new_target),(this.spell_power), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_LIGHTNING )
        set temp_struct = this
        set this.l_fork_damage = GetUnitsInRangeOfLocMatching(130.00 , this.l_point, Condition (function elementalist_wrath.fork_damage_check))
        call TriggerSleepAction( 0.05 )
        call ForGroup(this.l_fork_damage, function elementalist_wrath.fork_damage)
        set this.l_current_target = this.l_new_target
        set start = start + 1
        call RemoveLocation(this.l_point)
        call DestroyGroup(this.l_random_targets)
        call DestroyGroup(this.l_fork_damage)
    endloop   
endmethod
//  ==========      Tally Method     ==========
method tally takes integer player_id, integer orb_level returns nothing
	set this.slot_num = (player_id - 1) * 9
	set this.orbs_f = 0
    set this.orbs_i = 0
    set this.orbs_l = 0

    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = ( orb_level )
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( udg_elementalist_OrbSlotElement[( ( this.slot_num ) + GetForLoopIndexA() )] == "|c00FF0000Fire|r" ) then
            set this.orbs_f = ( ( this.orbs_f ) + 1 )
        elseif ( udg_elementalist_OrbSlotElement[( ( this.slot_num ) + GetForLoopIndexA() )] == "|c000000FFIce|r" ) then
            set this.orbs_i = ( ( this.orbs_i ) + 1 )
        elseif (udg_elementalist_OrbSlotElement[( ( this.slot_num ) + GetForLoopIndexA() )] == "|c00FFFF00Lightning|r" ) then
            set this.orbs_l = ( ( this.orbs_l ) + 1 )
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endmethod
endstruct
//  ==========        Primary Function       ==========
function Wrath_of_Elements takes nothing returns nothing
    local elementalist_wrath data = elementalist_wrath.create()
    set data.caster = GetSpellAbilityUnit()
    set data.orb_level = GetUnitAbilityLevelSwapped('A00F' , ( data.caster ))
	set data.ability_level = GetUnitAbilityLevelSwapped('A00O' , ( data.caster ))
	set data.spell_power = ( 1000.00 + ( ( 1 + ( 0.50 * I2R(data.ability_level) ) ) * ( 10.00 * I2R(GetHeroStatBJ(bj_HEROSTAT_INT , ( data.caster ) , true)) ) ) )
	set data.owner = GetOwningPlayer(GetSpellAbilityUnit())
	set data.owner_id = GetConvertedPlayerId(( data.owner ))
		// [power is = to: 1000 + (1 + 0.5*Ability level)*(10*hero int)]
	call data.tally(data.owner_id, data.orb_level)
    call data.wrath_lightning()
    //call BJDebugMsg( "Fire: " + I2S((data.orbs_f)))
    //call BJDebugMsg( "Ice: " + I2S((data.orbs_i)))
    //call BJDebugMsg( "Lightning: " + I2S((data.orbs_l)))
    call TriggerSleepAction( 10 )
    call data.destroy()
endfunction
//===========================================================================
function Trig_Wrath_Test_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A00O' )
endfunction
//===========================================================================
function InitTrig_Wrath_Test takes nothing returns nothing
    set gg_trg_Wrath_Test = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Wrath_Test, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Wrath_Test, Condition( function Trig_Wrath_Test_Conditions ) )
    call TriggerAddAction( gg_trg_Wrath_Test, function Wrath_of_Elements )
endfunction


Thanks to both of you for the help.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top