Spell Problem

Cidzero

Imma firin mah lazer!!!1!1
Reaction score
39
Issue is, the units spawned don't stay in the 400 range of the hero.

JASS:
scope IceEnergy
    globals
        private constant gamecache cache = InitGameCache("IceEnergies")
        private constant integer SpellID = 'A004'
        private constant integer DumID = 'd000'
        private constant integer AbilID = 'A003'
        private constant integer lvlskip = 1
        private constant real frostRange = 600.0
        private constant real frostDmg = 20.0
        private constant real frostTime = 25.0
        private constant real checkTime = 0.03
        private constant real dmgAoE = 50.0
        private constant real dmg = 0.05
        private constant real moveSpeed = 15.0
        private constant real moveArea = 400.0
        private constant real height = 50.0
        private constant real size = 1.00
        private constant string energyMdl = "Abilities\\Weapons\\ZigguratFrostMissile\\ZigguratFrostMissile.mdl"
    endglobals
    
    private function H2I takes handle h returns integer
        return h
        return 0
    endfunction
  
    private function HS takes handle i returns string
        return I2S(H2I(i))
    endfunction
    
    private function IsUnitNotImmun takes unit c,unit u returns boolean
        return ((c!=u) and not IsUnitType(u,UNIT_TYPE_STRUCTURE) and not IsUnitType(u,UNIT_TYPE_MAGIC_IMMUNE) and (IsUnitEnemy(u, GetOwningPlayer(c))==true) and (GetUnitState(u,UNIT_STATE_LIFE)>0.00))
    endfunction
//=================== The struct =========================\\  
    private struct Missile
        unit missile
        unit caster
        real angle
        real dist
        real tdist
        integer special
        real stime
        real ttime
        real lvl
        effect mdl
        timer t
        
        method make takes real x, real y, real a,real h, real s, string m, player p, real l, unit c, real d returns nothing
            set this.missile = CreateUnit(p,DumID,x,y,a)
            call UnitAddAbility(this.missile,AbilID)
            call SetUnitFlyHeight(this.missile,h,0)
            set this.mdl = AddSpecialEffectTarget(m,this.missile,"chest")
            call SetUnitScale(this.missile,s,s,s)
            set this.angle = a
            set this.caster = c
            set this.dist = 0
            set this.tdist = d
            set this.stime = 0
            set this.ttime = 0
            set this.lvl = l
            set this.t = CreateTimer()
            call StoreInteger(cache,HS(this.t),"missile",this)
        endmethod
        
        method attack takes nothing returns nothing
            local group g = CreateGroup()
            local unit u
            local unit t
            local integer c = 0
            local real x = GetUnitX(this.missile)
            local real y = GetUnitY(this.missile)
            if (GetUnitState(this.caster,UNIT_STATE_LIFE)>0) then
                call GroupEnumUnitsInRange(g,x,y,dmgAoE,null)
                loop
                    exitwhen (CountUnitsInGroup(g)<1)
                    set u = FirstOfGroup(g)
                    if IsUnitNotImmun(this.missile,u) then
                        call UnitDamageTarget(this.missile,u,(this.lvl*dmg),false,false,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_COLD,null)
                    endif
                    call GroupRemoveUnit(g,u)
                endloop
                call DestroyGroup(g)
                if (this.ttime>=this.stime) then
                    call GroupEnumUnitsInRange(g,x,y,frostRange,null)
                    loop
                        exitwhen (CountUnitsInGroup(g)<1)
                        set u = FirstOfGroup(g)
                        if IsUnitNotImmun(this.missile,u) then
                            set c = c + 1
                            if (GetRandomInt(1,c)==1) then
                                set t = u
                            endif
                        endif
                        call GroupRemoveUnit(g,u)
                    endloop
                    if (t!=null) then
                        call SetUnitAbilityLevel(this.missile,AbilID,R2I(this.lvl))
                        call IssueTargetOrder(this.missile,"shadowstrike",t)
                        set this.ttime = this.ttime - this.stime
                    endif
                else
                    set this.ttime = this.ttime + checkTime
                endif
            endif
            call DestroyGroup(g)
            set g = null
            set u = null
            set t = null
        endmethod
        
        method turn takes nothing returns nothing
            local real x1 = GetUnitX(this.caster)
            local real y1 = GetUnitY(this.caster)
            local real x2 = GetRandomReal(x1-(moveArea*0.50),x1+(moveArea*0.50))
            local real y2 = GetRandomReal(y1-(moveArea*0.50),y1+(moveArea*0.50))
            set this.angle = bj_RADTODEG*Atan2(y2-y1,x2-x1)
            set this.tdist = SquareRoot(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)))
            set this.dist = 0
        endmethod
        
        method move takes real speed returns nothing
            local real x1 = GetUnitX(this.missile)
            local real y1 = GetUnitY(this.missile)
            local real x2 = x1+speed*Cos(this.angle*bj_DEGTORAD)
            local real y2 = y1+speed*Sin(this.angle*bj_DEGTORAD)
            if ((RectContainsCoords(bj_mapInitialPlayableArea,x2,y2)==false) or (this.dist>=this.tdist)) then
                call this.turn()
            else
                call SetUnitX(this.missile,x2)
                call SetUnitY(this.missile,y2)
                set this.dist = this.dist+speed
            endif
            call this.attack()
        endmethod
        
        method remove takes nothing returns nothing
            call RemoveUnit(this.missile)
            set this.missile = null
            set this.caster = null
            call DestroyEffect(this.mdl)
            set this.mdl = null
            call PauseTimer(this.t)
            call FlushStoredMission(cache,HS(this.t))
            call DestroyTimer(this.t)
            set this.t = null
            call this.destroy()
        endmethod
    endstruct

    private function Conditions takes nothing returns boolean
        return (GetLearnedSkill()==SpellID)
    endfunction
    
    private function MissileMotion takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local Missile energy = GetStoredInteger(cache,HS(t),"missile")
        
        set energy.lvl = I2R(GetUnitAbilityLevel(energy.caster,SpellID))
        call energy.move(moveSpeed)
        
        call TimerStart(t,checkTime,false,function MissileMotion)
        set t = null
    endfunction
    
    private function CreateEnergy takes real x, real y, real a,real h, real s, string m, player p, real l, unit c, real d returns nothing
        local Missile energy = Missile.create()
        call energy.make(x,y,a,h,s,m,p,l,c,d)
        set energy.stime = frostTime
        call TimerStart(energy.t,checkTime,false,function MissileMotion)
    endfunction

    private function IceEnergiesActions takes nothing returns nothing
        local real cx
        local real cy
        local real nx
        local real ny
        local real a
        local real d
        local player p
        local unit u
        local integer l
        
        set u  = GetTriggerUnit()
        set p = GetOwningPlayer(u)
        set l = GetUnitAbilityLevel(u,SpellID)
        
        if ((l==1) or (ModuloInteger(l,lvlskip)==0)) then
            set cx = GetUnitX(u)
            set cy = GetUnitY(u)
            set nx = GetRandomReal(cx-moveArea*0.50,cx+moveArea*0.50)
            set ny = GetRandomReal(cy-moveArea*0.50,cy+moveArea*0.50)
            set a = (bj_RADTODEG*Atan2(ny-cy,nx-cx))
            set d = SquareRoot((nx-cx)*(nx-cx)+(ny-cy)*(ny-cy))
            call CreateEnergy(cx,cy,a,height,size,energyMdl,p,I2R(l),u,d)
        endif
        set u = null
        set p = null
    endfunction

    //===========================================================================
    public function InitTrig takes nothing returns nothing
        local trigger IceEnergy = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(IceEnergy,EVENT_PLAYER_HERO_SKILL)
        call TriggerAddCondition(IceEnergy,Condition(function Conditions))
        call TriggerAddAction(IceEnergy,function IceEnergiesActions)
    endfunction
endscope
 
Please provide more information about what this is intended to do. I could figure it out reading your code, but I'd rather not have to if you can explain it to me.
 
Its the moving part and the turning part, for some reason, it sets the point at which the unit is supposed to move to farther away than the intended allowed region. I used the calculations provided by the BJ functions to figure out how to just use x and y instead of locations and regions. But it seems to fail...

method move and method turn handle the directions and moving.
 
Well, I'm just assuming this is supposed to make dummy unit's that circle around our intended hero?
 
Well, not circle, but essentially, yes stay around the intended hero. Kinda like a passive Locust Swarm.

> Make your gamecache not constant?

That would solve what now? So far constant gamecache hasn't bugged me.
 
Might I suggest
JASS:
call SetUnitPositionLoc(ourunit, ourlocation)

and

JASS:
call SetUnitFacing(ourunit, AngleBetweenPoints(currentlocation, targetlocation))


Then use

JASS:
function PolarProjectionBJ takes location source, real dist, real angle returns location
    local real x = GetLocationX(source) + dist * Cos(angle * bj_DEGTORAD)
    local real y = GetLocationY(source) + dist * Sin(angle * bj_DEGTORAD)
    return Location(x, y)
endfunction


To calculate the locations. Just a thought, Ill have to try out your code to see whats ACTUALLY happening.


This should work just fine...
JASS:
function RotateDemo takes nothing returns nothing
//Moves Some Unit
local timer t = GetExpiredTimer()
local unit u = GetEnumUnit()
local unit target = GetHandleUnit(t, "rotation")
local real x1 = GetUnitX(u)
local real y1 = GetUnitY(u)
local real x2 = GetUnitX(target)
local real y2 = GetUnitY(target)
local real angle = GetHandleReal(u, "angle") + .15
local real distance = 100

call SetUnitPosition(u, x2+distance*Cos(angle), y2+distance*Sin(angle))
call SetHandleReal(u, "angle", angle)
set t = null
set u = null
set target = null
endfunction
 
Edit: Double Post

Yea just looks like your calculations are a bit off.

Also I really don't recommend using SetUnitX and SetUnitY. Please use SetUnitPosition. If you run SetUnitX and say the X position is not pathable with the ORIGINAL Y position the unit will not move in the X direction even if the FINAL X,Y position is pathable.
 
I rather not have them go in a circle...but freely roam within a set range of the intended hero...

EDIT: Anywho, I tried something else, using order strings, and it worked perfect (guess is when constantly being set to a new position the angle somehow got messed up by the unit positioning). But now I have the problem if I use my Ice Orb they stop moving...(had this with the set unit position also...lol)
 
Also I really don't recommend using SetUnitX and SetUnitY. Please use SetUnitPosition. If you run SetUnitX and say the X position is not pathable with the ORIGINAL Y position the unit will not move in the X direction even if the FINAL X,Y position is pathable.

I'm sorry but this is bullshit.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/

      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