Struct loop not working.

Zalinian

New Member
Reaction score
0
There's actually 2 problems with my code. 1) The first time the code is triggered, it doesn't execute the 3 ele_buff functions. 2) the two loop while unit has buff loops don't work correctly. It does the loop and its contents once, but doesn't continue to loop when the unit has the buff.
Just so you know, it compiles fine, it just doesn't work correctly.

Here's the code:
JASS:
function Trig_Elementalist_Buff_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A01E' ) ) then
        return false
    endif
    return true
endfunction
//===========================================================================
globals
    elementalist_buff elementalist_buff_temp_struct
endglobals
  
struct elementalist_buff
// Main Varaibles
    unit caster
    player owner
    integer owner_id
    integer orbs_f
    integer orbs_i
    integer orbs_l
    integer ability_level
    integer orb_level
    real spell_power
    real buff_radius
    group buff_targets
    location point

// 	Universal Methods
private static method enemy_check takes nothing returns boolean
    local elementalist_buff this = elementalist_buff_temp_struct
    return IsUnitEnemy(GetFilterUnit(),(.owner)) == true and IsUnitAliveBJ(GetFilterUnit()) == true
endmethod
static method ally_check takes nothing returns boolean
    local elementalist_buff this = elementalist_buff_temp_struct
    return IsUnitAlly(GetFilterUnit(),(.owner)) == true and IsUnitAliveBJ(GetFilterUnit()) == true
endmethod
//	Fire
private static method flame_damage takes nothing returns nothing
    local effect sfx
    local unit caster
	local elementalist_buff this = elementalist_buff_temp_struct
    call AddSpecialEffectTargetUnitBJ("chest", GetEnumUnit(), "Abilities\\Spells\\Other\\BreathOfFire\\BreathOfFireDamage.mdl")
    set sfx = GetLastCreatedEffectBJ()
    call BJDebugMsg("damage tick" + R2S(.spell_power))
    call UnitDamageTarget(.caster, GetEnumUnit(), .spell_power, true, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_FIRE, null)
    call TriggerSleepAction(1.0)
    call DestroyEffect(sfx)
endmethod
private static method flame_aura takes nothing returns nothing
	local unit f_caster
	local unit target
	local location point
	local group damage_targets
    local real check
	local elementalist_buff this = elementalist_buff_temp_struct
	set target = GetEnumUnit()
    set point = GetUnitLoc(target)
	call CreateNUnitsAtLoc(1, 'h008', .owner, point, bj_UNIT_FACING)
	set f_caster = GetLastCreatedUnit()
	call UnitApplyTimedLifeBJ(0.5, 'BTLF', f_caster)
    call SetUnitAbilityLevel(f_caster, 'A01D', .orbs_f)
    call IssueTargetOrderById(f_caster, OrderId("innerfire"), target)
    set point = null
	loop  // !PROBLEM: This loop only runs once even while true.
        exitwhen (UnitHasBuffBJ(target, 'B00M') == false)
        set point = GetUnitLoc(target)
        set damage_targets = GetUnitsInRangeOfLocMatching(300, point, Condition (function elementalist_buff.enemy_check))
        set elementalist_buff_temp_struct = this
        call ForGroup(damage_targets, function elementalist_buff.flame_damage)
        call GroupClear(damage_targets)
        set point = null
        call TriggerSleepAction(1.0)
    endloop
    call RemoveLocation(point)
    call DestroyGroup(damage_targets)
endmethod
method ele_buff_fire takes nothing returns nothing
    if this.orbs_f > 0 then
        set elementalist_buff_temp_struct = this
        call ForGroup(this.buff_targets, function elementalist_buff.flame_aura)
    endif
endmethod
// 	Ice
private static method frost_barrier takes nothing returns nothing
    local unit target
    local unit i_caster
    local location point
    local elementalist_buff this = elementalist_buff_temp_struct
    set target = GetEnumUnit()
    set point = GetUnitLoc(target)
    call CreateNUnitsAtLoc(1, 'h008', .owner, point, bj_UNIT_FACING)
	set i_caster = GetLastCreatedUnit()
	call UnitApplyTimedLifeBJ(0.5, 'BTLF', i_caster)
    call SetUnitAbilityLevel(i_caster, 'A01B', .orbs_i)
    call IssueTargetOrderById(i_caster, OrderId("frostarmor"), target)
    set point = null
    call TriggerSleepAction(3.0)
    loop // !PROBLEM: This loop only runs once even while true.
        exitwhen (UnitHasBuffBJ(target, 'B00L') == false)
        set point = GetUnitLoc(target)
        call CreateNUnitsAtLoc(1, 'h008', .owner, point, bj_UNIT_FACING)
        set i_caster = GetLastCreatedUnit()
        call UnitApplyTimedLifeBJ(0.5, 'BTLF', i_caster)
        call SetUnitAbilityLevel(i_caster, 'A01C', .ability_level)
        call IssueImmediateOrder( i_caster, "thunderclap" )
        call TriggerSleepAction(1.0)
    endloop
endmethod
method ele_buff_ice takes nothing returns nothing
    if this.orbs_i > 0 then
        set elementalist_buff_temp_struct = this
        call ForGroup(this.buff_targets, function elementalist_buff.frost_barrier)
    endif
endmethod
//	Lightning
private static method static_burst takes nothing returns nothing
    local unit target
    local unit l_caster
    local location point
    local elementalist_buff this = elementalist_buff_temp_struct
    set target = GetEnumUnit()
    set point = GetUnitLoc(target)
    call CreateNUnitsAtLoc(1, 'h008', .owner, point, bj_UNIT_FACING)
	set l_caster = GetLastCreatedUnit()
	call UnitApplyTimedLifeBJ(0.5, 'BTLF', l_caster)
    call SetUnitAbilityLevel(l_caster, 'A01A', .orbs_l)
    call IssueTargetOrderById(l_caster, OrderId("bloodlust"), target)
    call RemoveLocation(point)
endmethod
method ele_buff_lightning takes nothing returns nothing
    if this.orbs_l > 0 then
        set elementalist_buff_temp_struct = this
        call ForGroup(this.buff_targets, function elementalist_buff.static_burst)
    endif
endmethod
endstruct

//	Main Function
function Trig_Elementalist_Buff_Actions takes nothing returns nothing
	local elementalist_buff data = elementalist_buff.create()
	set data.caster = GetTriggerUnit()
	set data.owner = GetOwningPlayer(data.caster)
	set data.owner_id = GetConvertedPlayerId(( data.owner ))
	set data.ability_level = GetUnitAbilityLevelSwapped('A01E' , ( data.caster ))
	set data.orb_level = GetUnitAbilityLevelSwapped('A00F' , ( data.caster ))
	set data.buff_radius = 400 + (50 * data.ability_level)
	set data.point = GetUnitLoc(data.caster)
	set data.buff_targets = GetUnitsInRangeOfLocMatching(data.buff_radius , data.point, Condition (function elementalist_buff.ally_check))
	set data.spell_power = ( 100.00 + ( ( 0.5 + ( 0.3 * I2R(data.ability_level) ) ) * ( 2.50 * I2R(GetHeroStatBJ(bj_HEROSTAT_INT , (data.caster) , true)) ) ) )
	set data.orbs_f = tally_fire(data.owner_id, data.orb_level)
    set data.orbs_i = tally_ice(data.owner_id, data.orb_level)
    set data.orbs_l = tally_lightning(data.owner_id, data.orb_level) 
    //call elementalist_orb_clear(data.owner_id)
 // These 3 execute functions don't run the first time the spell is triggered, only 2nd and on.
    call data.ele_buff_lightning.execute()
	call data.ele_buff_ice.execute()
    call data.ele_buff_fire.execute()
	call TriggerSleepAction( 35.00 )
    call data.destroy()
endfunction
//===========================================================================
function InitTrig_Elementalist_Buff takes nothing returns nothing
    set gg_trg_Elementalist_Buff = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Elementalist_Buff, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Elementalist_Buff, Condition( function Trig_Elementalist_Buff_Conditions ) )
    call TriggerAddAction( gg_trg_Elementalist_Buff, function Trig_Elementalist_Buff_Actions )
endfunction
 

Nestharus

o-o
Reaction score
84
No one likes to look through huge masses of code =).

My suggestion is to cnp the parts that actually don't work, and then cnp under them the complete code complete with debug messages so that we can see exactly what is going on easily ^_^.


Prepare the code for others to look over =P. I know that's the only way I ever help out with code, and I always do that to code when I need help =).
 

Zalinian

New Member
Reaction score
0
When I do that, people say post the entire code so they can figure out the problem : /

Edited with notes on the problem parts.
 

Jesus4Lyf

Good Idea™
Reaction score
397
>My suggestion is to cnp the parts that actually don't work, and then cnp under them the complete code complete with debug messages so that we can see exactly what is going on easily ^_^.

>people say post the entire code
Where'd you get the idea he suggested otherwise? :p

Edit:
>[LJASS]call TriggerSleepAction(3.0)[/LJASS]
You cannot trigger sleep inside a [LJASS]ForGroup[/LJASS] as far as I recall. Do another .execute thing or something.
 

Jesus4Lyf

Good Idea™
Reaction score
397
>I need to have some kind of delay, its a 'dot' type effect.
>[LJASS]call TriggerSleepAction(3.0)[/LJASS]
You cannot trigger sleep inside a [LJASS]ForGroup[/LJASS] as far as I recall. Do another .execute thing or something.
That is how. Wrap the [LJASS]TriggerSleepAction[/LJASS] in another .execute(). :)
 

Zalinian

New Member
Reaction score
0
Ok, I fix'd the delay issue, but I still have the problem where the first time the ability is used it does nothing. After that it works.

Updated code:
JASS:
function Trig_Elementalist_Buff_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A01E' ) ) then
        return false
    endif
    return true
endfunction
//===========================================================================
globals
    elementalist_buff elementalist_buff_temp_struct
endglobals
  
struct elementalist_buff
// Main Varaibles
    unit caster
    player owner
    integer owner_id
    integer orbs_f
    integer orbs_i
    integer orbs_l
    integer ability_level
    integer orb_level
    real spell_power
    real buff_radius
    group buff_targets
    location point
// 	Universal Methods
private static method enemy_check takes nothing returns boolean
    local elementalist_buff this = elementalist_buff_temp_struct
    return IsUnitEnemy(GetFilterUnit(),(.owner)) == true and IsUnitAliveBJ(GetFilterUnit()) == true
endmethod
static method ally_check takes nothing returns boolean
    local elementalist_buff this = elementalist_buff_temp_struct
    return IsUnitAlly(GetFilterUnit(),(.owner)) == true and IsUnitAliveBJ(GetFilterUnit()) == true
endmethod
//	Fire
private static method flame_damage takes nothing returns nothing
    local effect sfx
    local unit caster
	local elementalist_buff this = elementalist_buff_temp_struct
    call AddSpecialEffectTargetUnitBJ("chest", GetEnumUnit(), "Abilities\\Spells\\Other\\BreathOfFire\\BreathOfFireDamage.mdl")
    set sfx = GetLastCreatedEffectBJ()
    call UnitDamageTarget(.caster, GetEnumUnit(), (0.5* .spell_power), true, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_FIRE, null)
    call TriggerSleepAction(0.45)
    call DestroyEffect(sfx)
endmethod
private static method flame_tick takes unit u, elementalist_buff t returns nothing
    local group damage_targets
    local elementalist_buff this = t
    local unit target = u
    local location point
    loop
        exitwhen (UnitHasBuffBJ(target, 'B00M') == false)
        set point = GetUnitLoc(target)
        set damage_targets = GetUnitsInRangeOfLocMatching(300, point, Condition (function elementalist_buff.enemy_check))
        set elementalist_buff_temp_struct = this
        call ForGroup(damage_targets, function elementalist_buff.flame_damage)
        call GroupClear(damage_targets)
        set point = null
        call TriggerSleepAction(0.5)
    endloop
    call RemoveLocation(point)
    call DestroyGroup(damage_targets)
endmethod
private static method flame_aura takes nothing returns nothing
	local unit f_caster
	local unit target
	local location point
	local elementalist_buff this = elementalist_buff_temp_struct
	set target = GetEnumUnit()
    set point = GetUnitLoc(target)
	call CreateNUnitsAtLoc(1, 'h008', .owner, point, bj_UNIT_FACING)
	set f_caster = GetLastCreatedUnit()
	call UnitApplyTimedLifeBJ(0.5, 'BTLF', f_caster)
    call SetUnitAbilityLevel(f_caster, 'A01D', .orbs_f)
    call IssueTargetOrderById(f_caster, OrderId("innerfire"), target)
    call RemoveLocation(point)
    call elementalist_buff.flame_tick.execute(target, this)
endmethod
method ele_buff_fire takes nothing returns nothing
    if this.orbs_f > 0 then
        set elementalist_buff_temp_struct = this
        call ForGroup(this.buff_targets, function elementalist_buff.flame_aura)
    endif
endmethod
// 	Ice
private static method ice_tick takes unit u, player p, integer i returns nothing
    local unit target = u
    local unit i_caster
    local player owner = p
    local integer ability_level = i
    local location point
    call TriggerSleepAction(3.0)
    loop
        exitwhen (UnitHasBuffBJ(target, 'B00L') == false)
        set point = GetUnitLoc(target)
        call CreateNUnitsAtLoc(1, 'h008', owner, point, bj_UNIT_FACING)
        set i_caster = GetLastCreatedUnit()
        call UnitApplyTimedLifeBJ(0.5, 'BTLF', i_caster)
        call SetUnitAbilityLevel(i_caster, 'A01C', ability_level)
        call IssueImmediateOrder( i_caster, "thunderclap" )
        call TriggerSleepAction(2.5)
    endloop
endmethod
private static method frost_barrier takes nothing returns nothing
    local unit target
    local unit i_caster
    local location point
    local elementalist_buff this = elementalist_buff_temp_struct
    set target = GetEnumUnit()
    set point = GetUnitLoc(target)
    call CreateNUnitsAtLoc(1, 'h008', .owner, point, bj_UNIT_FACING)
	set i_caster = GetLastCreatedUnit()
	call UnitApplyTimedLifeBJ(0.5, 'BTLF', i_caster)
    call SetUnitAbilityLevel(i_caster, 'A01B', .orbs_i)
    call IssueTargetOrderById(i_caster, OrderId("frostarmor"), target)
    set point = null
    call elementalist_buff.ice_tick.execute(target, .owner, .ability_level)
endmethod
method ele_buff_ice takes nothing returns nothing
    if this.orbs_i > 0 then
        set elementalist_buff_temp_struct = this
        call ForGroup(this.buff_targets, function elementalist_buff.frost_barrier)
    endif
endmethod
//	Lightning
private static method static_burst takes nothing returns nothing
    local unit target
    local unit l_caster
    local location point
    local elementalist_buff this = elementalist_buff_temp_struct
    set target = GetEnumUnit()
    set point = GetUnitLoc(target)
    call CreateNUnitsAtLoc(1, 'h008', .owner, point, bj_UNIT_FACING)
	set l_caster = GetLastCreatedUnit()
	call UnitApplyTimedLifeBJ(0.5, 'BTLF', l_caster)
    call SetUnitAbilityLevel(l_caster, 'A01A', .orbs_l)
    call IssueTargetOrderById(l_caster, OrderId("bloodlust"), target)
    call RemoveLocation(point)
endmethod
method ele_buff_lightning takes nothing returns nothing
    if this.orbs_l > 0 then
        set elementalist_buff_temp_struct = this
        call ForGroup(this.buff_targets, function elementalist_buff.static_burst)
    endif
endmethod
endstruct

//	Main Function
function Trig_Elementalist_Buff_Actions takes nothing returns nothing
	local elementalist_buff data = elementalist_buff.create()
	set data.caster = GetTriggerUnit()
	set data.owner = GetOwningPlayer(data.caster)
	set data.owner_id = GetConvertedPlayerId(( data.owner ))
	set data.ability_level = GetUnitAbilityLevelSwapped('A01E' , ( data.caster ))
	set data.orb_level = GetUnitAbilityLevelSwapped('A00F' , ( data.caster ))
	set data.buff_radius = 400 + (50 * data.ability_level)
	set data.point = GetUnitLoc(data.caster)
	set data.buff_targets = GetUnitsInRangeOfLocMatching(data.buff_radius , data.point, Condition (function elementalist_buff.ally_check))
	set data.spell_power = ( 100.00 + ( ( 0.5 + ( 0.3 * I2R(data.ability_level) ) ) * ( 2.50 * I2R(GetHeroStatBJ(bj_HEROSTAT_INT , (data.caster) , true)) ) ) )
	set data.orbs_f = tally_fire(data.owner_id, data.orb_level)
    set data.orbs_i = tally_ice(data.owner_id, data.orb_level)
    set data.orbs_l = tally_lightning(data.owner_id, data.orb_level) 
    //call elementalist_orb_clear(data.owner_id)
 // These 3 execute functions don't run the first time the spell is triggered, only 2nd and on.
    call data.ele_buff_lightning.execute()
	call data.ele_buff_ice.execute()
    call data.ele_buff_fire.execute()
	call TriggerSleepAction( 35.00 )
    call data.destroy()
endfunction
//===========================================================================
function InitTrig_Elementalist_Buff takes nothing returns nothing
    set gg_trg_Elementalist_Buff = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Elementalist_Buff, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Elementalist_Buff, Condition( function Trig_Elementalist_Buff_Conditions ) )
    call TriggerAddAction( gg_trg_Elementalist_Buff, function Trig_Elementalist_Buff_Actions )
endfunction
 

Zalinian

New Member
Reaction score
0
Anyone? Only problem left is that it doesn't work the first time the ability is casted.

Edit: nvm, was a simple fix. I forgot to set the temp struct to data. before the 3 buff calls.
 
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