HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Help with spell

07-04-2008, 07:17 AM#1
Feroc1ty
Collapse JASS:
struct spelldata
    real x
    real y
    real distance
    real angle
    unit bullet
endstruct

function time takes nothing returns boolean
    local spelldata a = TT_GetData()
    set a.distance = a.distance + 12
    set a.x = a.x + (800 * 0.03125) * Cos( a.angle * bj_DEGTORAD )
    set a.y = a.y + (800 * 0.03125) * Sin( a.angle * bj_DEGTORAD )
    call SetUnitX( a.bullet, a.x )
    call SetUnitY( a.bullet, a.y )
    if a.distance > 1200 then
        call RemoveUnit( a.bullet )
        set a.bullet = null
        return true
    endif
    return false
endfunction

function Conditions takes nothing returns boolean
    if GetSpellAbilityId() == 'shot' then
        return true
    endif
    return false
endfunction

function shoot_Actions takes nothing returns nothing
    local spelldata a = spelldata.create()
    local timer t = CreateTimer()
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    set a.bullet = CreateUnit( p , 'bllt', 0, 0, 0 )
    set a.x = GetUnitX(u)
    set a.y = GetUnitY(u)
    set a.angle = (bj_RADTODEG * Atan2(GetLocationY(GetSpellTargetLoc()) - GetUnitY(u), GetLocationX(GetSpellTargetLoc()) - GetUnitX(u)))
    call TT_Start( function time, a )
endfunction

//===========================================================================
function InitTrig_Shoot takes nothing returns nothing
    set gg_trg_Shoot = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Shoot, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Shoot, Condition( function Conditions ) )
    call TriggerAddAction( gg_trg_Shoot, function shoot_Actions )
endfunction


Okay, the issue i'm having here is that when I destroy the spelldata, either after TT_Start, or just before returning true to end the timer, the spell stops working after any of the projectiles get to distance 1200, i can cast many before that, but after one of them gets to the distance, the whole spell stops working, i don't know if im misusing the TT or it's a glitch or something, but someone head me the right way, btw can anyone help me detecting collision with units on the spell?
07-04-2008, 04:32 PM#2
Themerion
I have no experience with TT.

This is how you do collision detection (according to Vexorian it's faster than Trigger - Register Unit In Range).

Collapse JASS:
// You can ofc. use another temporary group, or use group recycling.

globals
    private group tempGroup
    private boolexpr be

    private player tempPlayer
endglobals

// This is a Condition-function.
// GetFilterUnit() == Unit - Get Matching Unit

private function Enum takes nothing returns boolean
  local unit u=GetFilterUnit()

// The conditions. Only hits alive enemies.
    if IsUnitEnemy(u,tempPlayer) and GetWidgetLife(u)>.405 then
        call BJDebugMsg("COLLISION!")
    endif

  set u=null
  return true
endfunction

private function Actions takes nothing returns nothing
  local integer x=GetUnitX(the_missile)
  local integer y=GetUnitY(the_missile)

// Provided you have changed the_missile's player to the caster.
// Otherwise store the casting player in your spelldata-struct.
    set tempPlayer=GetOwningPlayer(the_missile)

    call ClearGroup(tempGroup)
    call GroupEnumUnitsInRange(tempGroup,x,y,be)
endfunction

private function Init takes nothing returns nothing
    set be=Condition(function Enum)
    set tempGroup=CreateGroup()
endfunction
07-04-2008, 05:54 PM#3
Feroc1ty
So basically check if anyone that's alive is in range of the bullet? Can't believe didn't think of it myself... So simple haha, but I still need help with the damn TT.

oh btw is there any way to detect collision between bullets, they are locust so group thing wont work
07-05-2008, 12:07 AM#4
Feroc1ty
anyone?
07-05-2008, 12:22 PM#5
Themerion
Don't double post. Some people dislike that.

For your TT-issues, you should destroy the spellstruct right before returning true. Add some BJDebugMsg in your code to find out what runs/what does not run. For instance it might be helpful to check that the structs are not zero. call BJDebugMsg(I2S(spelldata))
Regarding missiles colliding: I would suggest you put all active missiles in a group, then for each missile check the distance to the others (yeah, you could cut the number of calculations by 50% if you made a single timer and turned spelldata into a linked list item. But let's not overcomplicate it :p)

Collapse JASS:
globals
    private group bullets=CreateGroup()
    private unit checked
endglobals

function CheckDistance takes nothing returns nothing
 // Pythagoras theorem:
 local integer dx=GetUnitX(GetEnumUnit())-GetUnitX(checked)
 local integer dy=GetUnitY(GetEnumUnit())-GetUnitY(checked)
 if SquareRoot(dx*dx+dy*dy) < 100 then
     call BJDebugMsg("Missiles colliding!")
 endif
endfunction

function Loop takes nothing returns nothing
    set checked = spelldata.missile
    call ForGroup(bullets,function CheckDistance)
endfunction