• 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.

Converting a Knockback spell to JASS

Status
Not open for further replies.
Level 3
Joined
Jul 29, 2006
Messages
61
I have a Knockback spell And I wish to convert it to JASS. I want to use local variables to make it MUI.

heres my triggers
Code:
Bloodwind
    Events
        Unit - A unit Starts the effect of an ability
    Conditions
        (Ability being cast) Equal to Bloodwind I 
    Actions
        Set Caster = (Casting unit)
        Unit Group - Pick every unit in (Units within 512.00 of (Position of Caster) matching (((Owner of (Matching unit)) controller) Equal to Computer)) and do (Actions)
            Loop - Actions
                Unit - Create 1 Dummy for Player 1 (Red) at (Position of (Picked unit)) facing (Position of (Casting unit))
                Unit - Add a 1.50 second Generic expiration timer to (Last created unit)
                Unit - Cause (Last created unit) to damage (Picked unit), dealing 800.00 damage of attack type Spells and damage type Lightning
                Set target = (Units within 512.00 of (Position of Caster) matching (((Owner of (Matching unit)) controller) Equal to Computer))
        Set BloodwindTimer = 0.00
        Trigger - Turn on BloodwindKnockback <gen>

BloodwindKnockback
    Events
        Time - Every 0.01 seconds of game time
    Conditions
    Actions
        Set BloodwindTimer = (BloodwindTimer + 1.00)
        Unit Group - Pick every unit in (Units in (Playable map area) matching (((Matching unit) is in target) Equal to True)) and do (Actions)
            Loop - Actions
                Unit - Move (Picked unit) instantly to ((Position of (Picked unit)) offset by 10.00 towards (Angle from (Position of Caster) to (Position of (Picked unit))) degrees)
                If (BloodwindTimer Greater than or equal to 51.00) then do (Trigger - Turn off (This trigger)) else do (Do nothing)

And here it is converted to JASS
JASS:
function Trig_Bloodwind_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A009' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Bloodwind_Func002001003 takes nothing returns boolean
    return ( GetPlayerController(GetOwningPlayer(GetFilterUnit())) == MAP_CONTROL_COMPUTER )
endfunction

function Trig_Bloodwind_Func002Func004002003 takes nothing returns boolean
    return ( GetPlayerController(GetOwningPlayer(GetFilterUnit())) == MAP_CONTROL_COMPUTER )
endfunction

function Trig_Bloodwind_Func002A takes nothing returns nothing
    call CreateNUnitsAtLocFacingLocBJ( 1, 'h000', Player(0), GetUnitLoc(GetEnumUnit()), GetUnitLoc(GetSpellAbilityUnit()) )
    call UnitApplyTimedLifeBJ( 1.50, 'BTLF', GetLastCreatedUnit() )
    call UnitDamageTargetBJ( GetLastCreatedUnit(), GetEnumUnit(), 800.00, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_LIGHTNING )
    set udg_target = GetUnitsInRangeOfLocMatching(512, GetUnitLoc(udg_Caster), Condition(function Trig_Bloodwind_Func002Func004002003))
endfunction

function Trig_Bloodwind_Actions takes nothing returns nothing
    set udg_Caster = GetSpellAbilityUnit()
    call ForGroupBJ( GetUnitsInRangeOfLocMatching(512, GetUnitLoc(udg_Caster), Condition(function Trig_Bloodwind_Func002001003)), function Trig_Bloodwind_Func002A )
    set udg_BloodwindTimer = 0.00
    call EnableTrigger( gg_trg_BloodwindKnockback )
endfunction

//===========================================================================
function InitTrig_Bloodwind takes nothing returns nothing
    set gg_trg_Bloodwind = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Bloodwind, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Bloodwind, Condition( function Trig_Bloodwind_Conditions ) )
    call TriggerAddAction( gg_trg_Bloodwind, function Trig_Bloodwind_Actions )
endfunction
JASS:
function Trig_BloodwindKnockback_Func002001002 takes nothing returns boolean
    return ( IsUnitInGroup(GetFilterUnit(), udg_target) == true )
endfunction

function Trig_BloodwindKnockback_Func002Func002001 takes nothing returns boolean
    return ( udg_BloodwindTimer >= 51.00 )
endfunction

function Trig_BloodwindKnockback_Func002A takes nothing returns nothing
    call SetUnitPositionLoc( GetEnumUnit(), PolarProjectionBJ(GetUnitLoc(GetEnumUnit()), 10.00, AngleBetweenPoints(GetUnitLoc(udg_Caster), GetUnitLoc(GetEnumUnit()))) )
    if ( Trig_BloodwindKnockback_Func002Func002001() ) then
        call DisableTrigger( GetTriggeringTrigger() )
    else
        call DoNothing(  )
    endif
endfunction

function Trig_BloodwindKnockback_Actions takes nothing returns nothing
    set udg_BloodwindTimer = ( udg_BloodwindTimer + 1 )
    call ForGroupBJ( GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function Trig_BloodwindKnockback_Func002001002)), function Trig_BloodwindKnockback_Func002A )
endfunction

//===========================================================================
function InitTrig_BloodwindKnockback takes nothing returns nothing
    set gg_trg_BloodwindKnockback = CreateTrigger(  )
    call DisableTrigger( gg_trg_BloodwindKnockback )
    call TriggerRegisterTimerEventPeriodic( gg_trg_BloodwindKnockback, 0.01 )
    call TriggerAddAction( gg_trg_BloodwindKnockback, function Trig_BloodwindKnockback_Actions )
endfunction
How would I change them to use local variables?
 
Level 11
Joined
Jul 12, 2005
Messages
764
here u go:
This needs the Local Handle Vars!!!

JASS:
function Trig_Bloodwind_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A009'
endfunction

function Bloodwind_Timer takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t, "KBunit")
    local real x = GetHandleReal(t, "X")
    local real y = GetHandleReal(t, "Y")
    local real angle = bj_RADTODEG * Atan2(GetLocationY(GetUnitY(u)) - y, GetUnitX(u) - x)
    local real ppx = GetUnitX(u) + 10 * Cos(angle * bj_DEGTORAD)
    local real ppy = GetUnitY(u) + 10 * Sin(angle * bj_DEGTORAD)
    call SetHandleInt(t, "Times", GetHandleInt(t, "Times") + 1)
    call SetUnitPosition(u, ppx, ppy)
    if GetHandleInt(t, "Times") == 50 then
        call PauseTimer(t)
        call FlushHandleLocals(t)
        call DestroyTimer(t)
    endif
    set t = null
    set u = null
endfunction
function Trig_Bloodwind_Actions takes nothing returns nothing
    local unit caster = GetSpellAbilityUnit()
    local location loc = GetUnitLoc(caster)
    local group g = GetUnitsInRangeOfLocAll(512, loc)
    local unit u = null
    local unit d = null
    call RemoveLocation(loc)
    loop
        set u = FirstOfGroup(g)
        call GroupRemoveUnit(g, u)
        exitwhen u == null
        if GetPlayerController(GetOwningPlayer(u)) == MAP_CONTROL_COMPUTER then
            set d = CreateUnit(Player(0), 'h000', GetUnitX(u), GetUnitY(u), 0)
            call UnitApplyTimedLife(d, 'BTLF', 1)
            call UnitDamageTargetBJ(d, u, 800.00, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_LIGHTNING )
            set d = null
            set t = CreateTimer()
            call SetHandleHandle(t, "KBunit", u)
            call SetHandleReal(t, "X", GetUnitX(caster))
            call SetHandleReal(t, "Y", GetUnitY(caster))
            call TimerStart(t, 0.02, true, function Bloodwind_Timer)
        endif
    endloop
    call DestroyGroup(g)
    set caster = null
    set u = null
    set g = null
endfunction

this is one trigger!
i wrote this to you in the hope that you will learn JASS. Primise u will!
 
Level 3
Joined
Jul 29, 2006
Messages
61
I will don't worry, I'm reading Daelins tutorials as well as working on a multiplayer map (and I want MUI).

edit: I'm getting werid bugs when i try to run it, (I alrady changed the B in the first boolean to a b.)

First heres how I have set up my code:
JASS:
function Trig_Bloodwind_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A009'
endfunction

function Bloodwind_Timer takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t, "KBunit")
    local real x = GetHandleReal(t, "X")
    local real y = GetHandleReal(t, "Y")
    local real angle = bj_RADTODEG * Atan2(GetLocationY(GetUnitY(u)) - y, GetUnitX(u) - x)
    local real ppx = GetUnitX(u) + 10 * Cos(angle * bj_DEGTORAD)
    local real ppy = GetUnitY(u) + 10 * Sin(angle * bj_DEGTORAD)
    call SetHandleInt(t, "Times", GetHandleInt(t, "Times") + 1)
    call SetUnitPosition(u, ppx, ppy) if GetHandleInt(t, "Times") == 50 then
        call PauseTimer(t)
        call FlushHandleLocals(t)
        call DestroyTimer(t)
    endif
    set t = null
    set u = null
endfunction

function Trig_Bloodwind_Actions takes nothing returns nothing
    local unit caster = GetSpellAbilityUnit()
    local location loc = GetUnitLoc(caster)
    local group g = GetUnitsInRangeOfLocAll(512, loc)
    local unit u = null
    local unit d = null
    call RemoveLocation(loc)
    loop
        set u = FirstOfGroup(g)
        call GroupRemoveUnit(g, u)
        exitwhen u == null
        if GetPlayerController(GetOwningPlayer(u)) == MAP_CONTROL_COMPUTER then
            set d = CreateUnit(Player(0), 'h000', GetUnitX(u), GetUnitY(u), 0)
            call UnitApplyTimedLife(d, 'BTLF', 1)
            call UnitDamageTargetBJ(d, u, 800.00, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_LIGHTNING )
            set d = null
            set t = CreateTimer()
            call SetHandleHandle(t, "KBunit", u)
            call SetHandleReal(t, "X", GetUnitX(caster))
            call SetHandleReal(t, "Y", GetUnitY(caster))
            call TimerStart(t, 0.02, true, function Bloodwind_Timer)
        endif
    endloop
    call DestroyGroup(g)
    set caster = null
    set u = null
    set g = null
endfunction

//===========================================================================
function InitTrig_Bloodwind takes nothing returns nothing
    set gg_trg_Bloodwind = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Bloodwind, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Bloodwind, Condition( function Trig_Bloodwind_Conditions ) )
    call TriggerAddAction( gg_trg_Bloodwind, function Trig_Bloodwind_Actions )
endfunction

Most problems seem to come from these lines:
JASS:
function Bloodwind_Timer takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t, "KBunit")
    local real x = GetHandleReal(t, "X")
    local real y = GetHandleReal(t, "Y")
    local real angle = bj_RADTODEG * Atan2(GetLocationY(GetUnitY(u)) - y, GetUnitX(u) - x)
    local real ppx = GetUnitX(u) + 10 * Cos(angle * bj_DEGTORAD)
    local real ppy = GetUnitY(u) + 10 * Sin(angle * bj_DEGTORAD)
    call SetHandleInt(t, "Times", GetHandleInt(t, "Times") + 1)
    call SetUnitPosition(u, ppx, ppy) if GetHandleInt(t, "Times") == 50 then
        call PauseTimer(t)
        call FlushHandleLocals(t)

function Trig_Bloodwind_Actions takes nothing returns nothing
    local unit caster = GetSpellAbilityUnit()
    local location loc = GetUnitLoc(caster)
    local group g = GetUnitsInRangeOfLocAll(512, loc)
    local unit u = null
    local unit d = null

I'm guessing I was supposed to do something but I'm unclear on what.[/quote]
 
Level 11
Joined
Jul 12, 2005
Messages
764
yeah there it is! sorry...
JASS:
//this line is wrong:
local real angle = bj_RADTODEG * Atan2(GetLocationY(GetUnitY(u)) - y, GetUnitX(u) - x)

//delete the GetLocationY:
local real angle = bj_RADTODEG * Atan2(GetUnitY(u) - y, GetUnitX(u) - x)

and it was ok!! don't delete the 'if then' statement man!!!
its a counter, when it reaches 50, it destroys the timer.
 
Level 3
Joined
Jul 29, 2006
Messages
61
when I copied the script that didn't copy, werid.

edit: Still having problems with the "KBunit" the GetHandleReal(t, "X") and GetHandleReal(t, "Y") It still registers
JASS:
    local real angle = bj_RADTODEG * Atan2(GetUnitY(u)) - y, GetUnitX(u) - x)
as wrong.
bacissaly most of the start in Bloodwind_Timer is registers as having an error
 
Level 11
Joined
Jul 12, 2005
Messages
764
I told you this needs the Local Handle Vars!!! but i see u don't nkow what it is...
[url]http://www.wc3jass.com/viewtopic.php?t=224
[/url]
anyway check out this site, :!: copy the whole script to your map's custom script section :!: (the very first trigger, that has your map's name).

now the spell must be working. use the first srcipt i wrote, and change the wrong line only!!
 
Level 3
Joined
Jul 29, 2006
Messages
61
okay trying that, And yes i'm a big newband didn't know what that was.

*tries it*

okay that works, thanks man :D

edit: hmm when I try to save errors still appear, but hopefully they are nothing?

edit2: nope they are a problem. I'll post a screenshot of what Problems I get.

ErrorScreenie.png


Edit3: Oh I think I might of found the problem, you never declared t in actions..

Edit 4: Ok I fixed it using local timer t = null
 
Status
Not open for further replies.
Top