• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] JASSING a missile

Status
Not open for further replies.
Level 4
Joined
May 6, 2006
Messages
79
hi, i'm using katana's handles and made a function called Missile to be used with a timer. So here's the function

JASS:
function Missile takes nothing returns nothing

//===================IMPORTED VARS===========================

   local timer t = GetExpiredTimer()

   local integer ExploType = GetHandleInt(t,"ExploID")

   local unit u = GetHandleUnit(t,"u")
   local unit cast = GetHandleUnit(t,"cast")
   local unit targ = null

   local real dmg = GetHandleReal(t,"dmg")
   local real radius = GetHandleReal(t,"rad")
   local real sense = GetHandleReal(t,"sns")

   local boolean homing = GetHandleBoolean(t,"Hom")
   local boolean FF = GetHandleBoolean(t,"FF")

   local location target = GetHandleLocation(t,"targloc")

   local real speed = GetHandleReal(t,"Speed")
   local real maxdist = GetHandleReal(t,"MxDist")
   local real dist = GetHandleReal(t,"Dist")

   local sound explode = GetHandleSound (t,"Sonido")

//===================NOT IMPORTED VARS===========================

   local boolean ReachesRegion=false
   local boolean NOW=false
   local boolean multit = true

   local unit U
   local group g

   local real x = GetUnitX( u ) + (speed) * Cos( GetUnitFacing( u )*bj_DEGTORAD )
   local real y = GetUnitY( u ) + (speed) * Sin( GetUnitFacing( u )*bj_DEGTORAD)

   local location locazo

if (homing) then
   set targ = GetHandleUnit(t,"target")
   set target = GetUnitLoc(targ)
   set x = GetUnitX( u ) + (speed) * Cos( AngleBetweenPoints(GetUnitLoc(u),GetUnitLoc(targ))*bj_DEGTORAD )
   set y = GetUnitY( u ) + (speed) * Sin( AngleBetweenPoints(GetUnitLoc(u),GetUnitLoc(targ))*bj_DEGTORAD )
endif

if(maxdist==0)then
   set ReachesRegion=true
endif

if(radius==0)then
   set multit=false
endif

//================= moves the projectile =================

if x < GetRectMaxX( bj_mapInitialPlayableArea ) and x > GetRectMinX( bj_mapInitialPlayableArea ) and y < GetRectMaxY( bj_mapInitialPlayableArea ) and y > GetRectMinY( bj_mapInitialPlayableArea ) then
        call SetUnitX( u, x )
        call SetUnitY( u, y )
endif

set dist=dist+speed
call SetHandleReal(t,"Dist",dist)

//================== should it explode?===================

set locazo = GetUnitLoc(u)
set g = GetUnitsInRangeOfLocAll(sense,locazo)
set U = FirstOfGroup(g)

if(homing)then
   loop
   set U = FirstOfGroup(g)
   exitwhen (U==null)or(NOW)
   if(U==targ)then
      set NOW=true
   endif
   call GroupRemoveUnit( g, U)
   set U=null

endloop
else
   
    if(FF)then
       loop
         set U = FirstOfGroup(g)
         exitwhen(U==null)or(NOW)
         if(U!=cast)and(U!=u)and(IsUnitAliveBJ(U))then
             set NOW = true
             set targ=U
         endif
         call GroupRemoveUnit( g, U)
         set U=null

       endloop
    else
       loop
         set U = FirstOfGroup(g)
         exitwhen(U==null)or(NOW)
         if(IsUnitAliveBJ(U))and(IsUnitEnemy(U,GetOwningPlayer(cast)))then
             set NOW = true
             set targ=U
         endif
         call GroupRemoveUnit( g, U)
         set U=null
       endloop
    endif 

endif

if(ReachesRegion)then
   if(DistanceBetweenPoints(locazo,target)<=30)then
      set NOW = true
   endif
elseif(dist>=maxdist)then
   set NOW = true
endif

//=============== did it explode? ========================

if(NOW)then



     if(explode!=null)then
        call PlaySoundAtPointBJ(gg_snd_FBTarg,100,GetUnitLoc(u),0.00)
     endif
     if(ExploType!=0)then
        call CreateNUnitsAtLoc( 1, ExploType, GetOwningPlayer(u), GetUnitLoc(u), bj_UNIT_FACING )
        call KillUnit( GetLastCreatedUnit() )
     endif

        call KillUnit( u )

    if(multit)then
        set g = GetUnitsInRangeOfLocAll(radius,locazo)
        if(FF)then
              call UnitDamagePointLoc( cast, 0, radius, locazo, dmg, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
        else
              loop
                  set U = FirstOfGroup(g)
                  exitwhen(U==null)
                  if(IsUnitEnemy(U,GetOwningPlayer(cast)))then
                      call UnitDamageTargetBJ(cast,U,dmg,ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL)
      
                  endif
                  call GroupRemoveUnit(g,U)
                  set U=null
              endloop
        endif
    else
           call UnitDamageTargetBJ(cast,targ,dmg,ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL)

    endif
call RemoveLocation (target)


call PauseTimer( t )
call FlushHandleLocals( t )
call DestroyTimer( t )

endif
    call RemoveLocation (locazo)
    set target = null
    set u = null
    call DestroyGroup( g )
    set g = null

endfunction



function MissileUL takes integer MisID, integer ExploID, unit caster, location target, real damage, real radius, real speed, real sensibilidad, real maxdist, boolean friendlyfire, sound sonidoC, sound sonidoT returns nothing

local timer t = CreateTimer()

    local location LC = GetUnitLoc( caster )

    if (sonidoC!=null) then
    call PlaySoundAtPointBJ(sonidoC,100,LC,0)
    endif

    call SetHandleHandle(t,"sonido",sonidoT)
    
    call SetHandleInt(t,"ExploID",ExploID)

    call SetHandleHandle(t,"cast",caster)
    call SetHandleHandle( t, "u", CreateUnit( GetOwningPlayer(caster),MisID, GetUnitX( caster ), GetUnitY( caster ), AngleBetweenPoints( LC, target )) )
    
    call SetHandleReal(t, "Speed", speed)
    call SetHandleReal(t, "MxDist", maxdist)
    call SetHandleReal(t, "Dist", 0)

    call SetHandleBoolean(t,"Hom",false)
    call SetHandleBoolean(t,"FF",friendlyfire)


    call SetHandleHandle(t,"targloc",target)

    call SetHandleReal(t,"dmg",damage)
    call SetHandleReal(t,"rad",radius)
    call SetHandleReal(t,"sns",sensibilidad)

    call TimerStart(t,0.01,true,function Missile)

    set t = null
    call RemoveLocation ( LC )
    set target = null
    set LC = null

endfunction


I hope this works for you guys... it rocks for me... I fixed the leaaks purple poot talks about in his post below XD.

The MissileUL function is missile from Unit to Location. HOMEWORK: Make MissileLL, MissileUU,MissileLU on your own

oh, and if you want to make them homming just enable homming by adding

call SetHandleBoolean(t,"Hom",true)

in the missile XU (it should always target a unit to be homming... or else... it will crash in an unknown way we all fear

By the way:
local unit u is the missile unit with locust
local boolean FF is for friendly fire on or off[/code]
 
Level 4
Joined
May 6, 2006
Messages
79
Oh I got it working... all i had to do was to set the projectile unit's movement to different than 0

You're damn right P.Poot. I should start adding some destroyers!!
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
O.O forgot about that

BTW, your projectile WAS moving :wink:

its just that when you use SetUnitX/Y natives with a movespeed of 0, it moves the unit, but not it's model. another funny thing is that this means that all orders target the model, but must be in range of the unit. you select the unit by selecting the model xD
 
Level 4
Joined
May 6, 2006
Messages
79
yeah... when i selected it i saw a moving selection circle... then i figured it out.

By the way... i think there's still memory leak in there... 'cause i then made a trigger that shot a missile every 0.3 seconds and it creates such a lag... man!!

please, could you help me find the leak?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
here are all the leaks, and other things to be changed

(oh, and i c u learned alot from my fireball script O.O)


set x = GetUnitX( u ) + (speed) * Cos( AngleBetweenPoints(GetUnitLoc(u),GetUnitLoc(targ))*bj_DEGTORAD )
set y = GetUnitY( u ) + (speed) * Sin( AngleBetweenPoints(GetUnitLoc(u),GetUnitLoc(targ))*bj_DEGTORAD )

is the first one. you are leaking two locations for each variable.

IsUnitAliveBJ(U))

thats not a leak, but change taht to GetUnitState( U, UNIT_STATE_LIFE ) > 0. it will reduce a little bit of lag :wink:

CreateNUnitsAtLoc( 1, ExploType, GetOwningPlayer(u), GetUnitLoc(u), bj_UNIT_FACING )

you leak a unit location ther. also, you are using CreateNUnitsAtLoc, which sucks. Use

CreateUnit( ExploType, GetOwningPlayer(u), GetUnitX(u), GetUnitY( u ), 0.00 )

(x and y wont leak, and this runs faster)

also, BJ_UNIT_FACING is just 270.00, but to save space, use 0.00.

call KillUnit( GetLastCreatedUnit() )

if you do it my way, this wont work. instead, when u use createUnit, you would say set U = CreateUnit(blahblahblah) and then KillUnit( U )

call UnitDamagePointLoc( cast, 0, radius, locazo, dmg, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )

eww. first, this will hurt allies, second, thats a BJ u have there xD ( UnitDamagePointLoc is a simplified BJ-added UnitDamagePoint, and it uses locations, so it sucks )

call UnitDamageTargetBJ(cast,U,dmg,ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL)

another Bj. fix that

call UnitDamageTargetBJ(cast,targ,dmg,ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL)

again!?
call RemoveLocation (locazo)

good, but you still have to set locazo = null

make sure u null ALL handles at the end of your script :wink:

i hope that helps!
 
Level 4
Joined
May 6, 2006
Messages
79
thank you very very much!!!
i'll start cleaning up tomorrow... it's 2:30 am :S

I don't understand what BJs are... could you please explain to me??

oh and about those damage functions:

the DamagePointLoc IS supposed to damage allies... fot ir will trigger if the Friendly Fire (FF) boolean is on.

The first UnitDamageTarget is in a loop to damage every enemy. The second one is triggered only when multit (multitarget) is false, so it will damage a single unit.

Well... and everything there was done thanks to your fireball spell ;) it changed my life. And thanks again for all the support (and reading all the script, u rock!)

And... i will correct these leaks and submit the fixed code tomorrow. I will also add MissileUU, MissileLU, and MissileLL (explained above). so I really hope someone finds it useful.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
BJ = Blizzard.J or Blizzard JASS ( im guessing here xD )

anyways, they are functions that call another one ( or more ) other functions. most of them just rearrange the parameters, making them take up extra processing speed. Some, however, like ForcePickRandomPlayer and TriggerRegisterAnyUnitEventBJ are useful however, because when they call so many functions, they are much easier to use, and do not significantly affect the speed comparing to their effects.

And UnitDamagePointLoc is another BJ ( they arent always called BJ, they can be BJ, Swap, Swapped, or just no suffix at all :shock: )

so is UnitDamageTargetBJ. deal with them xD
 
Status
Not open for further replies.
Top