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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • 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 Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top