Works Properly Once.

Crazy_Dead

New Member
Reaction score
24
My spell, which has been 54(53) posts about arguing between me and Berb( Thehive ), and now i got this compiling, and It works. ONCE :mad:.
And this makes me kinda angry, because of that simple fact, i want to make it.

Code, please look at it, and find the problem. Appreciate. Very much.

JASS:
library StrengthAura initializer Init

globals
    // CLOSE_RANGE_BONUS = How much strength you get when in Close Range
    private constant integer    CLOSE_RANGE_BONUS       = 15
    // MEDIUM_RANGE_BONUS = How much strength you get when in Medium Range
    private constant integer    MEDIUM_RANGE_BONUS      = 10
    // LONG_RANGE_BONUS = How much strength you get when in Long Range
    private constant integer    LONG_RANGE_BONUS        = 5
    // CLOSE_RANGE = Indicates how long Close Range is.
    private constant real       CLOSE_RANGE             = 200
    // MEDIUM_RANGE = Indicates how long Medium Range is.
    private constant real       MEDIUM_RANGE            = 400
    // LONG_RANGE = Indicates how long Long Range is.
    private constant real       LONG_RANGE              = 600
    // FULL_STR = Should it Include Bonuses from strength gain??
    private constant boolean    FULL_STR                = TRUE
    // SPELL_ID = ...
    private constant integer    SPELL_ID                = 'A00I'
    // BUFF_ID = ...
    private constant integer    BUFF_ID                 = 'B00C'
    // TIMERTICK = Every X seconds ticks, checking and adding strength.
    private constant real       TIMERTICK               = .05
    
//Dont Touch. Just dont do it.
//=========================================================|
/*          */real globX                                //=|
/*          */real globY                                //=|
/*          */group tmpGrp = CreateGroup()             //=|
/*          */unit picked                               //=|
/*          */unit Owner                                //=|
/*          */timer ti                                  //=|
/*          */private hashtable table = InitHashtable() //=|
/*          */unit array HeroWithAura                   //=|
/*          */integer HeroWithAuraCount = 0             //=|
//=========================================================|
endglobals

private constant function TYPES takes nothing returns boolean
return IsUnitType(picked, UNIT_TYPE_HERO) and not /*
    */ IsUnitType(picked, UNIT_TYPE_ANCIENT) and not/*
    */ IsUnitType(picked, UNIT_TYPE_ETHEREAL) and not/*
    */ IsUnitType(picked, UNIT_TYPE_MAGIC_IMMUNE) and not/*
    */ IsUnitType(picked, UNIT_TYPE_SUMMONED) and/*
    */ IsUnitInGroup(picked, tmpGrp)
endfunction

//==================================================================================================================

private struct Data
    public real x
    public real y
    public real range
    public real xx
    public real yy
    public real r
    public unit Enum

   private method ApplyBonus takes unit u, integer bonus returns nothing
        if HaveSavedInteger(table, GetHandleId(u), 1) then
            call SetHeroStr(u, GetHeroStr(u, true)-LoadInteger(table, GetHandleId(u), 1), false)
            if bonus == 0 then
                call RemoveSavedInteger(table, GetHandleId(u), 1)
            else
                call SaveInteger(table, GetHandleId(u), 1, bonus)
            endif
        else
            if bonus != 0 then
                call SaveInteger(table, GetHandleId(u), 1, bonus)
            endif
        endif
        call SetHeroStr(u, GetHeroStr(u, true)+bonus, false)
endmethod

    private method GetUnitAuraBonus takes unit u returns integer
        local integer i = 0
        local integer m = 0
        loop
            exitwhen i == HeroWithAuraCount
            if IsUnitInRange(u, HeroWithAura<i>, LONG_RANGE) then
            
                if IsUnitInRange(u, HeroWithAura<i>, CLOSE_RANGE) then
                    if CLOSE_RANGE_BONUS &gt; m then
                        debug call BJDebugMsg(&quot; Mission 3: Dummy Msg &quot;)
                        set m = CLOSE_RANGE_BONUS
                    endif
                elseif IsUnitInRange(u, HeroWithAura<i>, MEDIUM_RANGE) then
                    if MEDIUM_RANGE_BONUS &gt; m then
                        set m = MEDIUM_RANGE_BONUS
                        debug call BJDebugMsg(&quot; Mission 3: Dummy Msg1 &quot;)
                    endif
                else
                    if LONG_RANGE_BONUS &gt; m then
                        set m = LONG_RANGE_BONUS
                        debug call BJDebugMsg(&quot; Mission 3: Dummy Msg2 \n\n\n\n\n\n LOL&quot;)
                    endif
                endif
            
            endif
            set i = i + 1
        endloop
        return 0
    endmethod

    public static method loopFuncEnum takes nothing returns nothing
        local thistype this = allocate()
        call BJDebugMsg(&quot; Mission 2: ApplyBonus &quot;)
        set Enum = GetEnumUnit()
        call ApplyBonus(Enum, GetUnitAuraBonus(Enum))
    endmethod    
    
endstruct

//==================================================================================================================

public function onLearn takes nothing returns nothing
        set HeroWithAura[HeroWithAuraCount] = GetLearningUnit()
        set HeroWithAuraCount = HeroWithAuraCount + 1
endfunction

//==================================================================================================================

private function hasBuff takes nothing returns boolean
    return GetUnitAbilityLevel(GetFilterUnit(), BUFF_ID) &gt; 0
    // Filter, which picks all units in the range Which has the buff.
endfunction

//==================================================================================================================

private function Conditions takes nothing returns boolean
    return GetLearnedSkill() == SPELL_ID
    // Gets the Learned Skill.
endfunction

//==================================================================================================================
private function doLoop takes nothing returns nothing
        call ForGroup(tmpGrp, function Data.loopFuncEnum)
        call GroupEnumUnitsInRect(tmpGrp, GetWorldBounds(), Filter(function hasBuff))
        call BJDebugMsg(&quot; Completed Mission 1: GroupEnum&quot; ) 
        call ForGroup(tmpGrp, function Data.loopFuncEnum)
endfunction
//==================================================================================================================
//==================================================================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        set ti = CreateTimer()
        call TimerStart( ti , TIMERTICK , true , function doLoop )
        //==========================================================
        set t = CreateTrigger()
            loop
                exitwhen i == 16
                    call TriggerRegisterPlayerUnitEvent( t , Player(i) , EVENT_PLAYER_HERO_SKILL , null )
                set i = i + 1
            endloop
        call TriggerAddCondition( t , Condition(function Conditions ))
        call TriggerAddAction( t , function onLearn )
        //===========================================================
            
endfunction
//==================================================================================================================
//==================================================================================================================
endlibrary</i></i></i>

EDIT: Just wanted to tell ya, that im kinda proud of this. :D
Thanks.

//Crazy_Dead :thup:
 

Bribe

vJass errors are legion
Reaction score
67
Berbanog does like to argue.

You're Chaos_Knight? OK, well, now I know there's one fewer guy who posts angry messages when his code doesn't work.

What I PM'ed to you on The Hive was that I thought you did a nice job decorating this box:

JASS:

//=========================================================|
/*          */real globX                                //=|
/*          */real globY                                //=|
/*          */group tmpGrp = CreateGroup()              //=|
/*          */unit picked                               //=|
/*          */unit Owner                                //=|
/*          */timer ti                                  //=|
/*          */private hashtable table = InitHashtable() //=|
/*          */unit array HeroWithAura                   //=|
/*          */integer HeroWithAuraCount = 0             //=|
//=========================================================|
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
You're not telling us what isn't working and it would help if you replicated the problem in a map that you should upload.

Things I suggest before moving on with this:
01) Give us a detailed explanation of what is supposed to happen
02) Give us a detailed explanation of what happens instead
03) Tell us if you've tried anything or if you have a 'hint' of what might be wrong
04) Attach a map to the OP (Original Post) with a scenario where replicating your problem is easy

=P
 

Crazy_Dead

New Member
Reaction score
24
You're not telling us what isn't working and it would help if you replicated the problem in a map that you should upload.

Things I suggest before moving on with this:
01) Give us a detailed explanation of what is supposed to happen
02) Give us a detailed explanation of what happens instead
03) Tell us if you've tried anything or if you have a 'hint' of what might be wrong
04) Attach a map to the OP (Original Post) with a scenario where replicating your problem is easy

=P

1)

The unit( Enum ) should get bonus strength based on how far distance they are from the owner.

2)

The unit doesnt get the bonus, and i get all Messeages.
Still, if i instead does this:
call ApplyBonus(GetEnumUnit(), 10/*I get 10 bonus strength once*/)
instead of the
GetUnitAuraBonus(GetEnumUnit()) Which adds nothing.

3)

I think it's the GetUnitAuraBonus which is wrong somewhere.

4)

No, sorry. Too big file and i dont have time(I'm way to lame) to make a new map. Maybe will. :thup:
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
is GetUnitAuraBonus() supposed to always return 0?

I guess not by looking at the ApplyBonus() function
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
JASS:
    private method GetUnitAuraBonus takes unit u returns integer
        local integer i = 0
        local integer m = 0
        loop
            exitwhen i == HeroWithAuraCount
            if IsUnitInRange(u, HeroWithAura<i>, LONG_RANGE) then
            
                if IsUnitInRange(u, HeroWithAura<i>, CLOSE_RANGE) then
                    if CLOSE_RANGE_BONUS &gt; m then
                        debug call BJDebugMsg(&quot; Mission 3: Dummy Msg &quot;)
                        set m = CLOSE_RANGE_BONUS
                    endif
                elseif IsUnitInRange(u, HeroWithAura<i>, MEDIUM_RANGE) then
                    if MEDIUM_RANGE_BONUS &gt; m then
                        set m = MEDIUM_RANGE_BONUS
                        debug call BJDebugMsg(&quot; Mission 3: Dummy Msg1 &quot;)
                    endif
                else
                    if LONG_RANGE_BONUS &gt; m then
                        set m = LONG_RANGE_BONUS
                        debug call BJDebugMsg(&quot; Mission 3: Dummy Msg2 \n\n\n\n\n\n LOL&quot;)
                    endif
                endif
            
            endif
            set i = i + 1
        endloop
        return 0 // maybe set it to return m? just a wild guess xd
    endmethod</i></i></i>
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Was that so hard? :/
JASS:
library StrengthAura requires UAC, GT

    globals
        private constant integer    CLOSE_RANGE_BONUS       = 15
        private constant integer    MEDIUM_RANGE_BONUS      = 10
        private constant integer    LONG_RANGE_BONUS        = 5
        private constant real       CLOSE_RANGE             = 200.
        private constant real       MEDIUM_RANGE            = 400.
        private constant real       LONG_RANGE              = 600.
        //<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite4" alt=":mad:" title="Mad    :mad:" loading="lazy" data-shortname=":mad:" /> I wondered why still some people don&#039;t want to put dot for the real <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite4" alt=":mad:" title="Mad    :mad:" loading="lazy" data-shortname=":mad:" />
        private constant integer    SPELL_ID                = &#039;AEev&#039;
        private constant integer    BUFF_ID                 = &#039;B00C&#039;
        private constant boolean    IS_BONUS                = TRUE
    endglobals
    
    private struct Data extends UAC
        private static group closeRange = CreateGroup()
        private static group midRange = CreateGroup()
        private static group longRange = CreateGroup()
        
        method andFilterA takes unit picked returns boolean
            return GetUnitAbilityLevel(picked,BUFF_ID) &gt; 0
        endmethod
        
        method unitPeriodic takes unit u returns nothing
            if IsUnitInRange(u,.main,CLOSE_RANGE) then
            //Unit is in close range.
                if IsUnitInGroup(u,.midRange) then
                //Unit was in medium range.
                    call GroupRemoveUnit(.midRange,u)
                    call SetHeroStr(u,GetHeroStr(u,false) - MEDIUM_RANGE_BONUS,IS_BONUS)
                    //Remove all bonus granted under medium range.
                elseif IsUnitInGroup(u,.longRange) then
                //Unit was in long range.
                    call GroupRemoveUnit(.longRange,u)
                    call SetHeroStr(u,GetHeroStr(u,false) - LONG_RANGE_BONUS,IS_BONUS)
                    //Remove all bonus granted under long range.
                endif
                if not IsUnitInGroup(u,.closeRange) then
                //Unit was not affected.
                    call GroupAddUnit(.closeRange,u)
                    call SetHeroStr(u,GetHeroStr(u,false) + CLOSE_RANGE_BONUS,IS_BONUS)
                //Grants bonus under close range.
                endif
            elseif IsUnitInRange(u,.main,MEDIUM_RANGE) then
            //Unit is in medium range.
                if IsUnitInGroup(u,.closeRange) then
                //Unit was in close range.
                    call GroupRemoveUnit(.closeRange,u)
                    call SetHeroStr(u,GetHeroStr(u,false) - CLOSE_RANGE_BONUS,IS_BONUS)
                    //Remove all bonus granted under close range.
                elseif IsUnitInGroup(u,.longRange) then
                //Unit was in long range.
                    call GroupRemoveUnit(.longRange,u)
                    call SetHeroStr(u,GetHeroStr(u,false) - LONG_RANGE_BONUS,IS_BONUS)
                    //Remove all bonus granted under long range.
                endif
                if not IsUnitInGroup(u,.midRange) then
                //Unit was not affected.
                    call GroupAddUnit(.midRange,u)
                    call SetHeroStr(u,GetHeroStr(u,false) + MEDIUM_RANGE_BONUS,IS_BONUS)
                    //Grants bonus under medium range.
                endif
            else
            //Unit is in long range.
                if IsUnitInGroup(u,.closeRange) then
                //Unit was in close range.
                    call GroupRemoveUnit(.closeRange,u)
                    call SetHeroStr(u,GetHeroStr(u,false) - CLOSE_RANGE_BONUS,IS_BONUS)
                    //Remove all bonus granted under close range.
                elseif IsUnitInGroup(u,.midRange) then
                //Unit was in medium range.
                    call GroupRemoveUnit(.midRange,u)
                    call SetHeroStr(u,GetHeroStr(u,false) - MEDIUM_RANGE_BONUS,IS_BONUS)
                    //Remove all bonus granted under medium range.
                endif
                if not IsUnitInGroup(u,.longRange) then
                //Unit was not affected.
                    call GroupAddUnit(.longRange,u)
                    call SetHeroStr(u,GetHeroStr(u,false) + LONG_RANGE_BONUS,IS_BONUS)
                    //Grants bonus under long range.
                endif
            endif
        endmethod
        
        method unitLeave takes unit u returns nothing
            if IsUnitInGroup(u,.closeRange) then
            //Unit was in close range.
                call GroupRemoveUnit(.closeRange,u)
                call SetHeroStr(u,GetHeroStr(u,false) - CLOSE_RANGE_BONUS,IS_BONUS)
            //Remove all bonus granted under close range.
            elseif IsUnitInGroup(u,.midRange) then
            //Unit was in medium range.
                call GroupRemoveUnit(.midRange,u)
                call SetHeroStr(u,GetHeroStr(u,false) - MEDIUM_RANGE_BONUS,IS_BONUS)
            //Remove all bonus granted under medium range.
            elseif IsUnitInGroup(u,.longRange) then
            //Remove all bonus granted under long range.
                call GroupRemoveUnit(.longRange,u)
                call SetHeroStr(u,GetHeroStr(u,false) - LONG_RANGE_BONUS,IS_BONUS)
            //Remove all bonus granted under long range.
            endif
        endmethod
        
        private static method onLearn takes nothing returns boolean
            call thistype.create(GetTriggerUnit(),LONG_RANGE)
            return false
        endmethod
        
        private static method onInit takes nothing returns nothing
            call GT_AddLearnsAbilityAction(function thistype.onLearn, SPELL_ID)
            //Lazy to use original init method. <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />
        endmethod
    endstruct
    
endlibrary
 

Bribe

vJass errors are legion
Reaction score
67
I think it's harder for people still in high school to figure this stuff out. No offense to the kids here.
 

Crazy_Dead

New Member
Reaction score
24
I think that I havent got problem with the UAC, the math is the real big problem.
Still, im just 11 years old, and SquareRoot and such things is abit complicated for me, im sorry. :thdown:
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
I think that I havent got problem with the UAC, the math is the real big problem.
Still, im just 11 years old, and SquareRoot and such things is abit complicated for me, im sorry.

I don't think maths knowledge is a requirement to code this spell.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Did you see the code that I posted?
But I don't think you don't know what is plus and minus. :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top