• 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] Unit comes within range of my recenly created Fireball

Status
Not open for further replies.
Level 4
Joined
May 6, 2006
Messages
79
I'm making a Fireball Spell for my Full Action RPG - Preview Map, but I don't know how to JASS it

It's based on a dummy point targetting ability (silence)

A fireball should be created at the caster's position (done) and should move towards target point (done). If anything stands in its way (ally or enemy) it should explode, killing the fireball and damaging nearby units (htf do i do that? how can I make a Unit within range event for that?)

Also it woild be solved if everytime I created a Fireball I added the Unit In Range Event to the explotion trigger, but then I would have an event for everytime I cast a fireball... that's lots of events and lots of damaging since that particular event wouldn't mind if the fireball is alive or isn't. So I would need to remove events... is that possible??

The prize for the answer is your name in the spell... ohhh imagine "Cast Ronald Brown's Fireball " (well I really wouldn't do that, but I'll be really thankful)
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
In your move trigger, instead of ordering the fireball to move to the point, WHEN CAST

---make a timer that calls a func that does something like this---

JASS:
function Loop takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit( t, "fireball" )
    local real x = GetUnitX( u ) + (dist per 0.01s) * Cos( GetUnitFacing( u ) * bj_DEGTORAD )
    local real y = GetUnitY( u ) + (dist per 0.01s) * Sin( GetUnitFacing( u ) * bj_DEGTORAD )
    local group g = CreateGroup()
    local location Endpoint = GetHandleLocation( t, "targ" )
    local unit u2
    local boolean explode = false

    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
    call GroupAddUnitsInRange( g, x, y, null )
    loop
        set u2 = FirstOfGroup( g )
        exitwhen u2 == null
        if IsUnitEnemy( u2, GetOwningPlayer( u ) and GetUnitState(u2, UNIT_STATE_LIFE) >= 0 then
            set explode = true
            call UnitDamageTarget( u, u2, true, false, HowMuchDamage, attacktype, damagetype, weapontype )
        endif
        call GroupeRemoveUnit( g, u2 )
        set u2 = null
    endloop
    if explode or SquareRoot( ( GetUnitX( u ) - GetLocationX( Endpoint ) ) * ( GetUnitX( u ) - GetLocationX( Endpoint ) ) + ( GetUnitY( u ) - GetLocationY( Endpoint ) ) * ( GetUnitY( u ) - GetLocationY( Endpoint ) ) <= 25 then
        call PauseTimer( t )
        call FlushHandleLocals( t )
        call DestroyTimer( t )
        call KillUnit( u )
    endif
    call RemoveLocation( Endpoint )
    set Endpoint = null
    set u = null
    call DestroyGroup( g )
    set g = null
endfunction

------------------------------------------------------

PS. as this was NOT done in a JASS editor i may have made some typos. i also left some fields open to be changed, so this is not a copy-paste thing, it is a read thru and learn from thing.

you also need a starter for the timer.
 
Level 4
Joined
May 6, 2006
Messages
79
wow man , u rule!

thanks a lot, thought I just don't understand GetHandleUnit and GetHandleLocation

I guess i should first do something like

JASS:
function actions takes nothing returns nothing
local timer T

set T = CreateTimer()
call TimerStart(T,0.01,true,function Loop)//anything else here?? like handle-unit or handle-location??
endfunction

how do you send a unit and a region to a timer??
because:
JASS:
call TimerStart(T,0.01,true,function WithArguments(udg_something))
is impossible
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
using the Handle Vars

(thats what the GetHandle things are), make sure you have them implemented in ur map, they are found at www.wc3jass.com ( cant give you a direct link bc its down today, but you will have to make GetHandleLocation yourself ( tho it is ez once you read thru them ). Neways, it is in Standard Functions in the Scripts Section. look for The Local Handle Vars. )
to set them would look like this ( this demonstrates the usefullness of how general a type Handle is )

and some mistakes you made are - you can set a variable when it is created

JASS:
function actions takes nothing returns nothing 
local timer t = CreateTimer() 
local location l = GetSpellTargetLoc()
local location l2 = GetUnitLoc( GetTriggerUnit() )
call SetHandleHandle( t, "fireball", CreateUnit( DummyRawcodeHere, PlayerOwner, GetUnitX( GetTriggerUnit() ), GetUnitY( GetTriggerUnit() ), AngleBetweenPoints( l, l2 ) )
call SetHandleHandle( t, "targ", l )
call TimerStart(t,0.01,true,function Loop
set t = null
call RemoveLocation ( l2 )
set l = null//the reason i dont remove it is because it is used by the other function
set l2 = null
endfunction
 
Level 4
Joined
May 6, 2006
Messages
79
well that was damn helpful. I changed it a little so the fireball explodes on impact or after a short time (not in target point), and it woks perfectly.

Kattanas Handle functions are indeed of great help!
 
Status
Not open for further replies.
Top