HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[Spell/JASS] Projectile won't do damage

09-19-2008, 05:10 PM#1
Murder X
Hi,

I wanted to create a simple firebolt like in Diablo II.
For those who don't know it: The sorceress releases a Firebolt
in a choosable diraction that explodes on the first enemy who hits it.
It won't deal AOE-Damage but damages only one target. The
Firebolt won't be blocked by friendly units.


Well, I've got the bolt, and that it will move towards the right direction.
Also, the bolt will be destroyed when hitting a wall.

But what ever I'm doing, I can't let the bolt deal any damage to enemy units.
I wanted to pick all units in Range of the firebolt and damage the enemy, but it seems that it won't work :/

I hope you can help me out.

Here is the code:

Collapse JASS:
function gg_trg_Feuerblitz_JASS_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
        return false
    endif
    return true
endfunction

function H2I takes handle h returns integer
    return h
    return 0
endfunction

function I2U takes integer i returns unit
    return i
    return null
endfunction

function ReturnTrue takes nothing returns boolean
    return true
endfunction

function Move takes nothing returns nothing
    local string s = I2S(H2I(GetExpiredTimer()))
    local timer t = GetExpiredTimer()
    local gamecache gc = udg_AbilityCache
    local real x = GetStoredReal(gc, s, "x")
    local real y = GetStoredReal(gc, s, "y")
    local integer i = GetStoredInteger(gc, s, "Geschoss")
    local unit Firebolt = I2U(i)
    local location l = PolarProjectionBJ(GetUnitLoc(Firebolt), 20.00, GetUnitFacing(Firebolt))
    local group g = CreateGroup()
    local unit u


    call GroupEnumUnitsInRange(g, GetLocationX(l), GetLocationY(l), 30, Condition(function ReturnTrue))
    call DisplayTextToForce( GetPlayersAll(), I2S(CountUnitsInGroup(g)) )

   if ( not ( IsTerrainPathableBJ(l, PATHING_TYPE_WALKABILITY) == true ) ) then
      call SetUnitX(Firebolt, GetLocationX(l))
      call SetUnitY(Firebolt, GetLocationY(l))
      set l = null
   else
      call KillUnit(Firebolt)
   endif

  loop
    set u = FirstOfGroup(g)
    exitwhen u == null
    call GroupRemoveUnit(g, u)
  if IsUnitEnemy(u, GetOwningPlayer(Firebolt)) and (GetWidgetLife(u) > 0.405) and (IsUnitType(u, UNIT_TYPE_FLYING) == false) then
    call UnitDamageTarget(Firebolt, GetEnumUnit(), 50.00, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_FIRE, null)
    call BJDebugMsg("damaged")
      call KillUnit(Firebolt)
  endif
  endloop 




endfunction

function Trig_Feuerblitz2_Kopieren_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local location targetl = GetSpellTargetLoc()
    local location casterl = GetUnitLoc(caster)
    local real x = GetUnitX ( caster )
    local real y = GetUnitY ( caster )
    local timer t = CreateTimer() 
    local gamecache gc = udg_AbilityCache
    local player p = GetOwningPlayer ( caster )
    local real f = AngleBetweenPoints(casterl, (targetl))
    local unit Firebolt = CreateUnit ( p, 'h001', x, y, f )
    local string s = I2S(H2I(t))
    local integer i = H2I(Firebolt)
    
    call StoreInteger(gc, s, "Geschoss", i)
    call StoreReal(gc, s, "x", x)
    call StoreReal(gc, s, "y", y)
    call TimerStart(t, 0.05, true, function Move)
endfunction




//===========================================================================
function InitTrig_Feuerblitz_JASS_2 takes nothing returns nothing
    set gg_trg_Feuerblitz_JASS_2 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Feuerblitz_JASS_2, EVENT_PLAYER_UNIT_SPELL_CHANNEL )
    call TriggerAddCondition( gg_trg_Feuerblitz_JASS_2, Condition( function gg_trg_Feuerblitz_JASS_Conditions ) )
    call TriggerAddAction( gg_trg_Feuerblitz_JASS_2, function Trig_Feuerblitz2_Kopieren_Actions )
endfunction


I know, there are also some additional things like the use of locations I need to get rid of and I doesn't destroy the timer, the group and so on, but first, let's focuse on my damage problem...It's driving me crazy -.-


Thx for everyone who can help me :)
09-19-2008, 09:30 PM#2
Anopob
Have you tried to download (and modify if you needed) "Fireball" from the Spell Request thread stickied in this forum? I know you want it to be destroyed at walls as well but you can probably edit that and it's really simple IMO.
09-19-2008, 10:04 PM#3
Murder X
Yeah, I also tried this...and well, I have no idea how to edit this spell, what confuse me most, is that the hole trigger is written in the tallness, if you understand what I mean...

(Example:

Normal:

Bla
Bla
Bla

There: bla bla bla bla
)


Also I think it should be more easy to edit this spell that it will do the right thing instead of modifie this spell...

Additional I want to learn from this spell I'm making, cause I have nearly no JASS experience, and it's the first time, I'm working with gamecach, returnbug and local timers...

Most I learned from this one tutorial of this page, with that warstomp...
But it doesn't helped me with my damage problem :/
09-20-2008, 02:39 AM#4
Pyrogasm
The reason I post the zip files is because they contain the code to the spells. I know the code gets f'd up in the WE, so I attach .rtf files of the relevant code. Check the .zip file for Fireball and you'll find a 'normal' version of the spell.

As for your issue, it's this line: call UnitDamageTarget(Firebolt, GetEnumUnit(), 50.00, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_FIRE, null). That GetEnumUnit() is returning null, and you need to use "u" there instead.

Another thing I noticed about your code: your location "l" is leaking here:
Collapse JASS:
    local location l = PolarProjectionBJ(GetUnitLoc(Firebolt), 20.00, GetUnitFacing(Firebolt))
//...
   if ( not ( IsTerrainPathableBJ(l, PATHING_TYPE_WALKABILITY) == true ) ) then
      call SetUnitX(Firebolt, GetLocationX(l))
      call SetUnitY(Firebolt, GetLocationY(l))
      set l = null
   else
      call KillUnit(Firebolt)
   endif
Actually, now that I think about it you seem to not know about/understand leaks at all (though you did null "l" once...). I would suggest you read this and see if you can figure out how to fix your leaks (you're leaking groups and locations, but you also don't null your locals).
09-26-2008, 03:03 PM#5
Murder X
Well, I noticed that my code will leak horrible, because I haven't implemented anything to stop the timer and so on^^

Because Why I should do that, if the rest of my code isn't working at all? ^_^'

Very well, I have to thank you, it really was this problem that I needed u, but why? I mean, yeah, GetEnumUnit would be stupid to use there, cause you have u and it ist more specific, but why is GetEnumUnit returning null, when I picked a micro second before all units in range?
09-26-2008, 06:51 PM#6
Blubb-Tec
GetEnumUnit() does only work inside a function that was called using ForGroup().
09-26-2008, 07:01 PM#7
Vestras
Quote:
Originally Posted by grim001
or GroupEnum type functions, i.e. GroupEnumUnitsInRange()

What? That's GetFilterUnit()...