• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Non-errorish script doesn't work

Status
Not open for further replies.

Oli

Oli

Level 4
Joined
Aug 9, 2015
Messages
42
Hello,
recently i've encountered some problems that i've fixed with the help of some that answered my last thread [[JASS] - Indexing]. Apparentely, the script just won't work even after fixing it.

JASS:
globals
    hashtable rocketHash
endglobals

function rocket_condition takes nothing returns boolean
    if (GetSpellAbilityId() == 'A000') then
        return true
    elseif (GetSpellAbilityId() == 'A001') then
        return true
    endif
        return false
endfunction

function explosion takes nothing returns nothing
    local timer RocketTimer = GetExpiredTimer()
    local unit rocket = LoadUnitHandle(rocketHash, GetHandleId(RocketTimer), 0)
    call UnitDamagePointLoc(rocket, 0, 100, GetUnitLoc(rocket), 20, ATTACK_TYPE_PIERCE,DAMAGE_TYPE_NORMAL)
    call CreateUnitAtLoc(GetOwningPlayer(rocket), 'hpea', GetUnitLoc(rocket), 270)
    call RemoveUnit(rocket)
///Variable cleansing
    call FlushChildHashtable(rocketHash, GetHandleId(RocketTimer))
    call PauseTimer(RocketTimer)
    call DestroyTimer(RocketTimer)
    set RocketTimer = null
    set rocket = null
endfunction

function rocket_action takes nothing returns nothing
    local unit rocket = CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'hpea', OffsetLocation(GetUnitLoc(GetTriggerUnit()), 50.00, 0), GetUnitFacing(GetTriggerUnit()))
    local timer RocketTimer = CreateTimer()
    call SaveUnitHandle(rocketHash, GetHandleId(RocketTimer), 0, rocket)
    call TimerStart(RocketTimer, 1.5, false, function explosion)
    // the height
    call IssuePointOrderLocBJ( rocket, "move", PolarProjectionBJ(GetUnitLoc(rocket), 500.00, GetUnitFacing(rocket)) )
    call SetUnitFlyHeight(rocket, GetUnitFlyHeight(GetTriggerUnit()), 0)
    call SetUnitFlyHeight(rocket, 0 , 1.5 / GetUnitFlyHeight(rocket))
    // cleaning
    set RocketTimer = null
    set rocket = null
endfunction

//===========================================================================
function InitTrig_Rockets takes nothing returns nothing
    set gg_trg_Rockets = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Rockets, EVENT_PLAYER_UNIT_SPELL_CHANNEL)
    call TriggerAddCondition(gg_trg_Rockets, Condition(function rocket_condition))
    call TriggerAddAction(gg_trg_Rockets, function rocket_action)
endfunction

(For those who helped me on the last thread - i've merged the two triggers together.)
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
Alright, if it's not channeling then it shouldn't be using the channeling event. Use this instead:
EVENT_PLAYER_UNIT_SPELL_EFFECT

And your Hashtable is never initialized:
vJASS:
globals
    hashtable rocketHash = InitHashtable()
endglobals

Lastly, you're leaking a lot of Points (locations). This won't prevent it from working but it's something to note.
 

Oli

Oli

Level 4
Joined
Aug 9, 2015
Messages
42
Alright, if it's not channeling then it shouldn't be using the channeling event. Use this instead:
EVENT_PLAYER_UNIT_SPELL_EFFECT

And your Hashtable is never initialized:
vJASS:
globals
    hashtable rocketHash = InitHashtable()
endglobals

Lastly, you're leaking a lot of Points (locations). This won't prevent it from working but it's something to note.
Thank you, seems to work. Seems like making a temp loc or temp point local and cleansing it afterwards will remove the leaks?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
If a function can use a Point (Location) then there's also a version that can use x/y coordinates:
vJASS:
local real x = GetUnitX(someUnit)
local real y = GetUnitY(someUnit)
call CreateUnit(Player(0), 'hpea', x, y, 270)
vJASS:
local real x = GetLocationX(someLoc)
local real y = GetLocationY(someLoc)
call CreateUnit(Player(0), 'hpea', x, y, 270)
You can get the X/Y of a Unit/Location/Special Effect/Region, etc...
 
Status
Not open for further replies.
Top