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
 

Steel

Software Engineer
Reaction score
109
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.
 

Cidzero

Imma firin mah lazer!!!1!1
Reaction score
39
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.
 

Steel

Software Engineer
Reaction score
109
Well, I'm just assuming this is supposed to make dummy unit's that circle around our intended hero?
 

Cidzero

Imma firin mah lazer!!!1!1
Reaction score
39
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.
 

Steel

Software Engineer
Reaction score
109
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
 

Steel

Software Engineer
Reaction score
109
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.
 

Cidzero

Imma firin mah lazer!!!1!1
Reaction score
39
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)
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
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 Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top