• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

[JASS] What's wrong with it?

Status
Not open for further replies.
Level 21
Joined
Dec 9, 2007
Messages
3,096
JASS:
scope FireBolt initializer Init
    globals

        private constant integer AbilityID = 'A001'
        private constant integer FireBoltUnitTypeID = 'u000'
        private constant real FireBoltSpawnDistance = 15
    endglobals

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == AbilityID
endfunction

function Actions takes nothing returns nothing
    local player owner = GetOwningPlayer(GetSpellAbilityUnit())
    local location p1 = GetUnitLoc(GetSpellAbilityUnit())
    local location p2 = GetSpellTargetLoc()
    local real angle = Atan2(GetLocationY(p2) - GetLocationY(p1), GetLocationX(p2) - GetLocationX(p1))
    local real x = GetLocationX(p1) + FireBoltSpawnDistance * Cos(angle)
    local real y = GetLocationX(p1) + FireBoltSpawnDistance * Sin(angle)
    local unit firebolt
    local integer damage = GetHeroInt(GetSpellAbilityUnit(), true) * GetUnitAbilityLevel(GetSpellAbilityUnit(), 'A001')
    //Done with variables xD
    set firebolt = CreateUnitAtLoc(owner, FireBoltUnitTypeID, Location(x,y), angle)
    call GroupAddUnit(udg_FireBolts, firebolt)
    call SetUnitUserData( firebolt, damage )
    //Leak?
    call RemoveLocation(p1)
    call RemoveLocation(p2)
    set owner = null
    set firebolt = null
endfunction

//===========================================================================
//Initialization

private constant function AntiLeak takes nothing returns boolean
    return true
endfunction

private function Init takes nothing returns nothing
     local trigger t = CreateTrigger()
    local filterfunc f = Filter(function AntiLeak)
    local integer i = 0
    loop
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, f)
        set i = i + 1
        exitwhen i >= 16
    endloop
    call TriggerAddCondition(t, Condition( function Conditions ) )
    call TriggerAddAction(t, function Actions )
    call DestroyFilter(f)
    set f = null
endfunction

endscope

What's wrong with this code?
What makes it not work?

The hero casts the ability but the unit just doesn't spawn!
 
Whats the part that errors? That would be more helpfull (unless it compliles right). If it is compiling, then try changing the units flying height, since unit-effect type things are normally underground without a flying height
 
The unit raw code is exactly the necessary one.
This works, though:
JASS:
scope FireBolt initializer Init
private function Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A001' ) ) then
        return false
    endif
    return true
endfunction

private function Actions takes nothing returns nothing
    local location p1 = GetUnitLoc(GetSpellAbilityUnit())
    local location p2 = GetSpellTargetLoc()
    local location pp = PolarProjectionBJ(p1, 15.00, AngleBetweenPoints(p1, p2))
    call CreateUnitAtLocSaveLast( GetOwningPlayer(GetSpellAbilityUnit()), 'u000', pp, AngleBetweenPoints(p1, p2) )
    call GroupAddUnit( udg_FireBolts, bj_lastCreatedUnit )
    call SetWidgetLife( bj_lastCreatedUnit, 3.00 )
    call SetUnitUserData( bj_lastCreatedUnit, ( GetHeroInt(GetSpellAbilityUnit(), true) * GetUnitAbilityLevel(GetSpellAbilityUnit(), 'A001') ) )
    call RemoveLocation(p1)
    call RemoveLocation(p2)
    call RemoveLocation(pp)
endfunction

//===========================================================================
private constant function AntiLeak takes nothing returns boolean
    return true
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local filterfunc f = Filter(function AntiLeak)
    local integer i = 0
    loop
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, f)
        set i = i + 1
        exitwhen i >= 16
    endloop
    call TriggerAddCondition(t, Condition( function Conditions ) )
    call TriggerAddAction(t, function Actions )
    call DestroyFilter(f)
    set f = null
endfunction
endscope

Oh and
JASS:
call CreateUnit(GetTriggeringPlayer() or something, 'hpea', 0, 0, Angle)
Will create a unit.
I need the unit stored in a variable, and just calling this functions gives an unit, nothing more.
 
JASS:
scope FireBolt initializer Init
    globals

        private constant integer AbilityID = 'A001'
        private constant integer FireBoltUnitTypeID = 'u000'
        private constant real FireBoltSpawnDistance = 15
    endglobals

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == AbilityID
endfunction

private function Actions takes nothing returns nothing
    local unit u = GetSpellAbilityUnit()
    local player owner = GetOwningPlayer(u)
    local location p2 = GetSpellTargetLoc()
    local real angle = Atan2(GetLocationY(p2) - GetUnitY(u), GetLocationX(p2) - GetUnitX(u))
    local real x = GetUnitX(u) + FireBoltSpawnDistance * Cos(angle)
    local real y = GetUnitY(u) + FireBoltSpawnDistance * Sin(angle)
    local unit firebolt = CreateUnit(owner, FireBoltUnitTypeID, x , y, angle)
    local integer damage = GetHeroInt(u, true) * GetUnitAbilityLevel(u, 'A001')
    local group g = CreateGroup()
 
    call GroupAddUnit(g, firebolt)
    call SetUnitUserData( firebolt, damage )
    
    call DestroyGroup(g)
    call RemoveLocation(p2)
    set p2 = null
    set g= null
endfunction

//===========================================================================
//Initialization

private function Init takes nothing returns nothing
     local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEvent(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition( function Conditions ) )
    call TriggerAddAction(t, function Actions )
endfunction

endscope


this should work but this all doesnt make sence with each other thing what you r doing in that trigger e.g. why setting the x and y things if you dont work with them
 
Status
Not open for further replies.
Back
Top