HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Spell Help

08-30-2009, 12:21 AM#1
Tastingo
Well I have a basic spell that seems to be bugging out when two or more people cast it at same time and when it hits each other.

The spell is a type of boomerang, the hero aims it and it throws it in a straight path and comes back to the hero. Any other heros in the path of it will die.

I was testing it and I had 2 heros that casted it at same time and it's always the first hero to cast it that it works for. With the other the spell goes right through it. Everything works, but the killing sometimes screws up. Thought maybe someone could look at it. I'm sorry I don't use VJASS, but I do use JASS. Any help would help a lot. I will describe all the globals to make it a bit easier.

I know its a lot of work and a big annoyance reading the code and such, and I will really appreciate the help.

udg_thrown is an array for each player that checks if the player casted the spell.
udg_boomerangs is an array that stores each player's boomerang.
udg_move is anb array counter for how many times the boomerang has moved for each player.
udg_return is an array that checks if the boomerang is ready to return or not.
udg_wardens is an array that stores the casters of each spell. (It is set when the unit is created)
udg_big is an array that stores if big powerup was used.
udg_quick is an array that stores if quick powerup was used.
udg_long is an array that stores if long powerup was used.
udg_invisible is an array that stores if invisible powerup was used.
udg_double is an array that stores if double powerup was used.

Collapse JASS:
function MoveAllBoomerangs takes nothing returns nothing
    local real x = 0.0
    local real y = 0.0
    local integer i = 0
    local integer i2 = 0
    local unit boomerang = null
    local unit warden = null
    local multiboarditem mbitem = null
    
    loop
        if( udg_thrown[i] == true) then
            set boomerang = udg_boomerangs[i]
            set x = GetUnitX(boomerang)
            set y = GetUnitY(boomerang)
            
            loop        //Check Distance
                set warden = udg_wardens[i2]
                if(warden != null) then
                    if(DistanceBetweenUnits(boomerang, warden) <= 130 and i != i2 and udg_dead[i2] == false and udg_left[i2] == false and udg_invulnerble[i2] == false and udg_big[i] == false) then    //Normal Boomerang
                        set udg_dead[i2] = true
                        if(udg_double[i] == false) then    //Normal Points
                            set udg_points[i] = udg_points[i] + 1
                        else     //Double Points
                            set udg_points[i] = udg_points[i] + 2
                        endif
                        
                        set mbitem = MultiboardGetItem(udg_mb, udg_spot[i], 1)
                        call MultiboardSetItemValue(mbitem, udg_colors[i] + I2S(udg_points[i]))
                        call MultiboardReleaseItem(mbitem)
                        call SetPlayerState(Player(i), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Player(i), PLAYER_STATE_RESOURCE_GOLD) + 1)
                        
                        call DisplayTimedTextToPlayer(Player(i), 0, 0, 5.0, "You have killed " + udg_colors[i2] + GetPlayerName(Player(i2)) + ".")
                        call DisplayTimedTextToPlayer(Player(i2), 0, 0, 5.0, "You were killed by " + udg_colors[i] + GetPlayerName(Player(i)) + ".")
                        
                        if(udg_points[i] >= udg_victory) then
                            call GameOver(Player(i), warden)
                        endif
                        
                        call KillUnit(warden)
                        call TimerStart( udg_resTimer[i2], 5.0, false, null )
                    elseif(DistanceBetweenUnits(boomerang, warden) <= 140 and i != i2 and udg_dead[i2] == false and udg_left[i2] == false and udg_invulnerble[i2] == false and udg_big[i] == true) then    //Big Boomerang
                        set udg_dead[i2] = true
                        if(udg_double[i] == false) then    //Normal Points
                            set udg_points[i] = udg_points[i] + 1
                        else    //Double Points
                            set udg_points[i] = udg_points[i] + 2
                        endif
                        
                        set mbitem = MultiboardGetItem(udg_mb, udg_spot[i], 1)
                        call MultiboardSetItemValue(mbitem, udg_colors[i] + I2S(udg_points[i]))
                        call MultiboardReleaseItem(mbitem)
                        call SetPlayerState(Player(i), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Player(i), PLAYER_STATE_RESOURCE_GOLD) + 1)
                        
                        call DisplayTimedTextToPlayer(Player(i), 0, 0, 5.0, "You have killed " + udg_colors[i2] + GetPlayerName(Player(i2)) + ".")
                        call DisplayTimedTextToPlayer(Player(i2), 0, 0, 5.0, "You were killed by " + udg_colors[i] + GetPlayerName(Player(i)) + ".")
                        
                        if(udg_points[i] >= udg_victory) then
                            call GameOver(Player(i), warden)
                        endif
                        
                        call KillUnit(warden)
                        call TimerStart( udg_resTimer[i2], 5.0, false, null )
                    endif
                endif
                        
                set i2 = i2 + 1
                exitwhen i2 > 7
            endloop
            
            set warden = udg_wardens[i]     //Set to caster
            
            if( udg_return[i] == false) then        //Move boomerang away
                if(udg_quick[i] == false) then  //Normal boomerang away
                    call PolarReal(boomerang, x, y, 30.7, GetUnitFacing(boomerang) + 360)
                else    //Quick boomerang away
                    call PolarReal(boomerang, x, y, 40.0, GetUnitFacing(boomerang) + 360)
                endif
                set udg_moved[i] = udg_moved[i] + 1
                
                if(udg_moved[i] >= 23 and udg_long[i] == false and udg_quick[i] == false) then    //Allow return of boomerang with no powerup
                    set udg_return[i] = true
                elseif(udg_moved[i] >= 34 and udg_long[i] == true and udg_quick[i] == false) then    //Allow return of boomerang with long powerup
                    set udg_return[i] = true
                elseif(udg_moved[i] >= 18 and udg_long[i] == false and udg_quick[i] == true) then  //Allow return of boomerang with quick powerup
                    set udg_return[i] = true
                endif
            else        //Return boomerang
                if(udg_quick[i] == false) then  //Normal boomerang return
                    call Polar(boomerang, 30.7, AngleBetweenUnits(boomerang, warden) + 360)
                else
                    call Polar(boomerang, 40.0, AngleBetweenUnits(boomerang, warden) + 360)
                endif
                
                if(DistanceBetweenUnits(boomerang, warden) <= 75) then      //Catch boomerang
                    set udg_return[i] = false
                    set udg_thrown[i] = false
                    call RemoveUnit(boomerang)
                    call UnitRemoveAbility(udg_wardens[i], 'A002')
                    call UnitAddAbility(udg_wardens[i], 'A001')
                endif
            endif
        endif
        
        set i = i + 1
        exitwhen i > 7
    endloop
    
    set boomerang = null
    set warden = null
    set mbitem = null
endfunction

//===========================================================================
function InitTrig_Move_All_Boomerangs takes nothing returns nothing
    set gg_trg_Move_All_Boomerangs = CreateTrigger(  )
    call TriggerRegisterTimerEvent( gg_trg_Move_All_Boomerangs, 0.05, true )
    call TriggerAddAction( gg_trg_Move_All_Boomerangs, function MoveAllBoomerangs )
endfunction

Collapse JASS:
function Throw takes nothing returns nothing
    local unit t = GetTriggerUnit()
    local integer i = GetPlayerId(GetOwningPlayer(t))
    local real x = GetUnitX(t)
    local real y = GetUnitY(t)
    local real spellX = GetSpellTargetX()
    local real spellY = GetSpellTargetY()
    
    if(GetSpellAbilityId() == 'A001') then
        set udg_return[i] = false
        if(udg_big[i] == false) then    //Create normal boomerang
            set udg_boomerangs[i] = CreateUnit(GetOwningPlayer(t), 'h000', x, y, AngleBetweenReals(x, spellX, y, spellY))
        else    //Create big boomerang
            set udg_boomerangs[i] = CreateUnit(GetOwningPlayer(t), 'h002', x, y, AngleBetweenReals(x, spellX, y, spellY))
        endif
        set udg_thrown[i] = true
        set udg_moved[i] = 0
        call UnitRemoveAbility(t, 'A001')
        call UnitAddAbility(t, 'A002')
        call UnitAddAbility(udg_boomerangs[i], 'Aloc')
    endif
    
    set t = null
endfunction

//===========================================================================
function InitTrig_Throw_Boomerang takes nothing returns nothing
    local integer i = 0
    set gg_trg_Throw_Boomerang = CreateTrigger(  )
    
    loop
        call TriggerRegisterPlayerUnitEvent( gg_trg_Throw_Boomerang, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null )
        set i = i + 1
        exitwhen i > 11
    endloop
    
    call TriggerAddAction( gg_trg_Throw_Boomerang, function Throw )
endfunction
08-30-2009, 03:15 AM#2
Zerzax
Considering the "spaghettiness" of the regular old JASS code you'll probably be hearing from people - if there is no serious reason for you to avoid vjass code, then I would swap over - the altered syntax makes all this global work much easier to comprehend and thus easier for people to help you and the bug to be found more quickly. You definitely explained the globals well, I'll take a look at it now.
08-30-2009, 04:01 AM#3
Tastingo
Oh sick thank you. And I know I should really learn it, guess my laziness is bleh. Any help would be appreciated. I know its a mess so I will understand if your like no way, this is a mess.
08-30-2009, 04:14 AM#4
Zerzax
One of the most important concepts to learn about vjass is the more object-oriented approach of using structs. I'd recommend checking this out. In this case you could use 12 static instances of a struct, but I'm not exactly sure if thats the best way to do it. It would at least look more streamlined.
08-30-2009, 04:18 AM#5
Tastingo
I do agree VJass is easier and better. I know Java so I think I would pick up easy on it. I just haven't learned everything about VJass yet, and its syntax. So never have used it yet.
08-30-2009, 04:23 AM#6
Zerzax
Check out that tutorial - it's dense, but worth a million once you understand each bit.
08-30-2009, 04:25 AM#7
Karawasa
You'll be glad you did. Vanilla JASS simply burns the eyes.
08-30-2009, 04:29 AM#8
Tastingo
Ok, I'll check it out tomorrow. Did you guys want me to read over it, and repost it as VJass then? Or are you gonna read over this, and saying for future reference VJass only? Wasn't sure lol.
08-30-2009, 05:35 AM#9
Karawasa
Quote:
Originally Posted by Tastingo
Did you guys want me to read over it, and repost it as VJass then? Or are you gonna read over this, and saying for future reference VJass only? Wasn't sure lol.

Perhaps someone can still read vanilla JASS, but you'll get a lot more feedback if it's posted in vJASS.
08-30-2009, 05:51 AM#10
Deaod
If i am not mistaken, you dont reset i2 for further use. Just place set i2=0 after the inner loop and see if that helps.
08-30-2009, 01:26 PM#11
Tastingo
Oh wow that was the problem. I feel like an idiot lol, and thank you. I will learn VJass to make it easier for you guys next time. + rep :).