• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Need JASS PRO to change spell

Status
Not open for further replies.
Level 5
Joined
May 27, 2007
Messages
144
hi i have a problem with an imported spell. I makes monster lagg when it knocks all units back instead of one. Could someone take a look into it and change it so that i would knockback only heroes pls

Here it is:
JASS:
constant function Powerbash_SpellId takes nothing returns integer
    return 'A02A' // Powerbash rawcode
endfunction

constant function Powerbash_Initialdamage takes real level returns real
    return 0 + level * 50 // Initial damage a unit suffers when bashed
endfunction

constant function Powerbash_Movement takes real level returns real
    return 2 + level * 0.5 // The distance per 0.01 seconds the target unit moves when bashed
endfunction

constant function Powerbash_Time takes real level returns real
    return 2 + level * 0 // How long a unit is bashed and moving
endfunction

constant function Powerbash_Braketime takes real level returns real
    return 1 + level * 0 // How long a unit is getting slower until total stop
endfunction

constant function Powerbash_Brakedegree takes real level returns real
    return 0.98 // This is the value with that the movement gets multiplied 100 times a second to get
endfunction     // a smooth-brake effect. If you use bigger Brake Times, you should also set this
                // higher, like 9.85 or 9.955

constant function Powerbash_Movementdamage takes real level returns real
    return 0 + level * 0 // The damage a target suffers each move, not used yet
endfunction

constant function Powerbash_Treedamage takes real level returns real
    return 5 + level * 5 // The damage a target suffers when crashing through a tree
endfunction
//===============================================================================
function Trig_Powerbash_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == Powerbash_SpellId() ) ) then
        return false
    endif
    return true
endfunction

function Powerbash_GetUnit takes timer t returns unit
    return GetHandleHandle(t,"target")
endfunction

function Powerbash_GetUnit2 takes timer t returns unit
    return GetHandleHandle(t,"caster")
endfunction

function Powerbash_GetAngle takes timer t returns real
    return GetHandleReal(t,"angle")
endfunction

function TreeCheck takes nothing returns boolean
    return ( IsDestructableAliveBJ(GetEnumDestructable()) == true )
endfunction

function CountDestructablesInRect_Enum takes nothing returns nothing
    if ( TreeCheck() ) then
        set bj_randomSubGroupWant = bj_randomSubGroupWant + 1
    else
        call DoNothing( )
    endif
endfunction

function CountDestructablesInCircle takes location where, real radius returns integer
    local integer old = bj_randomSubGroupWant
    local integer new
    set bj_randomSubGroupWant = 0
    call EnumDestructablesInCircleBJ(radius, where, function CountDestructablesInRect_Enum)
    set new = bj_randomSubGroupWant
    set bj_randomSubGroupWant = old
    return new
endfunction

function Tree_Killer takes nothing returns nothing
    call KillDestructable( GetEnumDestructable() )
endfunction

function Move_Speed takes unit handletarget returns real
    return GetHandleReal(handletarget, "movement")
endfunction

function GetGroup takes location targetloc returns group
    return GetUnitsInRangeOfLocAll(200, targetloc) 
endfunction

function GetPin takes timer t2 returns unit
    return GetHandleHandle(t2,"pin")
endfunction

function bashothers takes nothing returns nothing
    local timer t2 = GetExpiredTimer()
    local real angle = GetHandleReal(t2,"angle")
    local unit pin = GetPin(t2)
    local location otherloc = GetUnitLoc(pin)
    local real movement = Powerbash_Movement(3)*1.5
    local location moveto = PolarProjectionBJ(otherloc, movement, angle)
    local integer runcounter = GetHandleInt(t2,"runcounter")
    call SetUnitPositionLoc(pin, moveto)
    call DestroyEffect(AddSpellEffectByIdLoc(Powerbash_SpellId(), EFFECT_TYPE_SPECIAL, moveto) )
    set pin = null
    call RemoveLocation(otherloc)
    set otherloc = null
    call RemoveLocation(moveto)
    set moveto = null
    set runcounter = runcounter + 1
    call SetHandleInt(t2,"runcounter",runcounter)
    if runcounter >= 15 then
        call DestroyTimer(t2)
    endif
    set t2 = null
endfunction    

function Trig_ConditionA takes nothing returns boolean
    return ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_GROUND) == true )
endfunction

function Trig_ConditionB takes nothing returns boolean
    return ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE) != true )
endfunction


function Trig_letsbowlevenmore_Conditions takes nothing returns boolean
    if ( not GetBooleanAnd( Trig_ConditionA(), Trig_ConditionB() ) ) then
        return false
    endif
    return true
endfunction

function letsbowl_Actions takes nothing returns nothing
    local unit pin = GetTriggerUnit()
    local location targetloc2 = GetUnitLoc(pin)
    local location targetloc = GetUnitLoc(udg_multifuncunit)
    local real angle = AngleBetweenPoints(targetloc, targetloc2)
    local timer t2 = CreateTimer()

    local trigger letsbowlevenmore = CreateTrigger()
    call TriggerRegisterUnitInRangeSimple( letsbowlevenmore, 90, pin )
    call TriggerAddCondition( letsbowlevenmore, Condition( function Trig_letsbowlevenmore_Conditions ) )
    call TriggerAddAction( letsbowlevenmore, function letsbowl_Actions )

    call SetHandleHandle(t2, "pin", pin)
    call SetHandleReal(t2, "angle", angle)
    call TimerStart(t2, 0.01, true, function bashothers)
    set pin = null
    call RemoveLocation(targetloc2)
    set targetloc2 = null

    call PolledWait(0.5)
    call TriggerClearActions(letsbowlevenmore)
    call DestroyTrigger(letsbowlevenmore)
    set letsbowlevenmore = null 
endfunction

function Powerbash_Move takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit target = Powerbash_GetUnit(t)
    local unit caster = Powerbash_GetUnit2(t)
    local unit handletarget = Powerbash_GetUnit(t)
    local real angle = Powerbash_GetAngle(t)
    local integer level = GetHandleInt(t,"level")
    local real movement = Move_Speed(handletarget)
    local location targetloc = GetUnitLoc(target)
    local location nextmove = PolarProjectionBJ(targetloc, movement, angle)
    local integer trees = 0
    local integer brake = GetHandleInt(t,"brake")
    if brake==1 then
        set movement = Move_Speed(handletarget)
        set movement = movement * Powerbash_Brakedegree(level)
        call SetHandleReal(handletarget,"movement",movement)
    endif
    set trees = CountDestructablesInCircle(targetloc, 150)
    call UnitDamageTargetBJ( caster, target, ( I2R(trees) * Powerbash_Treedamage(level) ), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNKNOWN )
    call EnumDestructablesInCircleBJ( 150.00, targetloc, function Tree_Killer )
    call UnitDamageTargetBJ( caster, target, Powerbash_Movementdamage(level), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNKNOWN )
    call DestroyEffect(AddSpellEffectByIdLoc(Powerbash_SpellId(), EFFECT_TYPE_SPECIAL, targetloc) )
    set nextmove = PolarProjectionBJ(targetloc, movement, angle)
    call SetUnitPositionLoc( target, nextmove )
    call RemoveLocation(targetloc)
    call RemoveLocation(nextmove)
    set t = null
    set target = null
    set targetloc = null
    set nextmove = null
    set caster = null
    set handletarget = null
    set trees = 0
endfunction

function Trig_Powerbash_Actions takes nothing returns nothing
    local unit target = GetSpellTargetUnit()
    local unit caster = GetTriggerUnit()
    local unit handletarget = GetSpellTargetUnit()
    local location a = GetUnitLoc(caster)
    local location b = GetUnitLoc(target)
    local real angle = AngleBetweenPoints(a, b)
    local timer t = CreateTimer()
    local integer level = GetUnitAbilityLevel(caster, GetSpellAbilityId() )
    local real movement = Powerbash_Movement(level)
    local integer brake = 0

    local trigger letsbowl = CreateTrigger()
    call TriggerRegisterUnitInRangeSimple( letsbowl, 90, target )
    call TriggerAddAction( letsbowl, function letsbowl_Actions )
    set udg_multifuncunit = target

    call RemoveLocation(b)
    call SetHandleHandle(t,"target",target)
    call SetHandleHandle(t,"caster",caster)
    call SetHandleReal(t,"angle", angle)
    call SetHandleInt(t,"level",level)
    call SetHandleReal(t,"movement",level)
    call SetHandleReal(handletarget,"movement",movement)
    call PauseUnitBJ( true, target )
    call SetUnitFacingTimed( target, angle, 1 )
    call UnitDamageTargetBJ( caster, target, Powerbash_Initialdamage(level), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNKNOWN )
    call TimerStart(t, 0.01, true, function Powerbash_Move)
    call PolledWait(Powerbash_Time(level))
    set brake = 1
    call SetHandleInt(t,"brake",brake)
    call PolledWait(Powerbash_Braketime(level))
    call PauseUnitBJ( false, target )
    call FlushHandleLocals(t)
    call FlushHandleLocals(handletarget)
    call DestroyTimer(t)
    call IssuePointOrderLoc( target, "patrol", a )    // This is good for creeps or AOS
    call RemoveLocation(a)                            // Spawnies. It makes "forgotten"
    set target = null                                 // Units behind trees impossible.
    set caster = null
    set a = null
    set b = null
    set t = null
    set handletarget = null

    call TriggerClearActions(letsbowl)
    call DestroyTrigger(letsbowl)
    set letsbowl = null

endfunction

//===========================================================================
function InitTrig_Powerbash takes nothing returns nothing
    set gg_trg_Powerbash = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Powerbash, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Powerbash, Condition( function Trig_Powerbash_Conditions ) )
    call TriggerAddAction( gg_trg_Powerbash, function Trig_Powerbash_Actions )
endfunction
thx a lot
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Sure, gimme a sec..... (will edit soon)

EDIT:

JASS:
constant function Powerbash_SpellId takes nothing returns integer
    return 'A02A' // Powerbash rawcode
endfunction

constant function Powerbash_Initialdamage takes real level returns real
    return 0 + level * 50 // Initial damage a unit suffers when bashed
endfunction

constant function Powerbash_Movement takes real level returns real
    return 2 + level * 0.5 // The distance per 0.01 seconds the target unit moves when bashed
endfunction

constant function Powerbash_Time takes real level returns real
    return 2 + level * 0 // How long a unit is bashed and moving
endfunction

constant function Powerbash_Braketime takes real level returns real
    return 1 + level * 0 // How long a unit is getting slower until total stop
endfunction

constant function Powerbash_Brakedegree takes real level returns real
    return 0.98 // This is the value with that the movement gets multiplied 100 times a second to get
endfunction     // a smooth-brake effect. If you use bigger Brake Times, you should also set this
                // higher, like 9.85 or 9.955

constant function Powerbash_Movementdamage takes real level returns real
    return 0 + level * 0 // The damage a target suffers each move, not used yet
endfunction

constant function Powerbash_Treedamage takes real level returns real
    return 5 + level * 5 // The damage a target suffers when crashing through a tree
endfunction

//===============================================================================

function Trig_Powerbash_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == Powerbash_SpellId() and IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO)
endfunction

function CountDestructablesInRect_Enum takes nothing returns nothing
    if GetDestructableLife(GetEnumDestructable()) > 0 then
        set bj_randomSubGroupWant = bj_randomSubGroupWant + 1
    endif
endfunction

function CountDestructablesInCircle takes location where, real radius returns integer
    local integer old = bj_randomSubGroupWant
    local integer new set bj_randomSubGroupWant = 0
    call EnumDestructablesInCircleBJ(radius, where, function CountDestructablesInRect_Enum)
    set new = bj_randomSubGroupWant
    set bj_randomSubGroupWant = old
    return new
endfunction

function Tree_Killer takes nothing returns nothing
    call KillDestructable(GetEnumDestructable())
endfunction

function GetPin takes timer t2 returns unit
    return GetHandleHandle(t2,"pin")
endfunction

function bashothers takes nothing returns nothing
    local timer t2 = GetExpiredTimer()
    local real angle = GetHandleReal(t2,"angle")
    local unit pin = GetPin(t2)
    local real movement = Powerbash_Movement(3)*1.5
    local real x1 = GetUnitX(pin)
    local real y1 = GetUnitY(pin)
    local real x2 = x1 + movement * Cos(angle)
    local real y2 = y1 + movement * Sin(angle)
    local integer runcounter = GetHandleInt(t2,"runcounter")
    call SetUnitPosition(pin, x2, y2)
    call DestroyEffect(AddSpellEffectById(Powerbash_SpellId(), EFFECT_TYPE_SPECIAL, x2, y2))
    set runcounter = runcounter + 1
    call SetHandleInt(t2,"runcounter",runcounter)
    if runcounter >= 15 then
        call DestroyTimer(t2)
    endif
    set t2 = null
    set pin = null
endfunction

function Trig_letsbowlevenmore_Conditions takes nothing returns boolean
    return IsUnitType(GetTriggerUnit(), UNIT_TYPE_GROUND) and not IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE)
endfunction

function letsbowl_Actions takes nothing returns nothing
    local unit pin = GetTriggerUnit()
    local real x1 = GetUnitX(pin)
    local real y1 = GetUnitY(pin)
    local real x2 = GetUnitX(udg_multifuncunit)
    local real y2 = GetUnitY(udg_multifuncunit)
    local real angle = Atan2(y1 - y2, x1 - x2)
    local timer t2 = CreateTimer()
    local trigger letsbowlevenmore = CreateTrigger()
    call TriggerRegisterUnitInRange(letsbowlevenmore, pin, 90, null)
    call TriggerAddCondition(letsbowlevenmore, Condition(function Trig_letsbowlevenmore_Conditions))
    call TriggerAddAction(letsbowlevenmore, function letsbowl_Actions)
    call SetHandleHandle(t2, "pin", pin)
    call SetHandleReal(t2, "angle", angle)
    call TimerStart(t2, 0.01, true, function bashothers)
    call PolledWait(0.5)
    call TriggerClearActions(letsbowlevenmore)
    call DestroyTrigger(letsbowlevenmore)
    set letsbowlevenmore = null
    set pin = null
endfunction

function Powerbash_Move takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit target = GetHandleHandle(t,"target")
    local unit caster = GetHandleHandle(t,"caster")
    local unit handletarget = GetHandleHandle(t,"target")
    local real angle = GetHandleReal(t,"angle")
    local integer level = GetHandleInt(t,"level")
    local real movement
    local real x1 = GetUnitX(target)
    local real y1 = GetUnitY(target)
    local real x2
    local real y2
    local integer trees = 0
    local integer brake = GetHandleInt(t,"brake")
    local rect r = Rect(x1 - 150, y1 - 150, x1 + 150, y1 + 150)
    if brake==1 then
        set movement = GetHandleReal(handletarget, "movement")
        set movement = movement * Powerbash_Brakedegree(level)
        call SetHandleReal(handletarget,"movement",movement)
    endif
    set trees = CountDestructablesInCircle(targetloc, 150)
    call UnitDamageTarget(caster, target, I2R(trees) * Powerbash_Treedamage(level), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNKNOWN, null)
    call EnumDestructablesInRect(r, null, function Tree_Killer)
    call RemoveRect(r)
    call UnitDamageTarget(caster, target, Powerbash_Movementdamage(level), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNKNOWN, null)
    call DestroyEffect(AddSpellEffectById(Powerbash_SpellId(), EFFECT_TYPE_SPECIAL, x1, y1))
    set x2 = x1 + movement * Cos(angle)
    set y2 = y1 + movement * Sin(angle)
    call SetUnitPosition(target, x2, y2)
    set t = null
    set target = null
    set caster = null
    set handletarget = null
    set trees = 0
endfunction

function Trig_Powerbash_Actions takes nothing returns nothing
    local unit target = GetSpellTargetUnit()
    local unit caster = GetTriggerUnit()
    local unit handletarget = GetSpellTargetUnit()
    local real x1 = GetUnitX(caster)
    local real y1 = GetUnitY(caster)
    local real x2 = GetUnitX(target)
    local real y2 = GetUnitY(target)
    local real angle = Atan2(y2 - y1, x2 - x1)
    local timer t = CreateTimer()
    local integer level = GetUnitAbilityLevel(caster, GetSpellAbilityId())
    local real movement = Powerbash_Movement(level)
    local integer brake = 0
    local trigger letsbowl = CreateTrigger()
    call TriggerRegisterUnitInRange(letsbowl, target, 90, null)
    call TriggerAddAction(letsbowl, function letsbowl_Actions)
    set udg_multifuncunit = target
    call SetHandleHandle(t,"target",target)
    call SetHandleHandle(t,"caster",caster)
    call SetHandleReal(t,"angle", angle)
    call SetHandleInt(t,"level",level)
    call SetHandleReal(t,"movement",level)
    call SetHandleReal(handletarget,"movement",movement)
    call PauseUnit(target, true)
    call SetUnitFacingTimed(target, angle, 1)
    call UnitDamageTarget(caster, target, Powerbash_Initialdamage(level), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNKNOWN, null)
    call TimerStart(t, 0.01, true, function Powerbash_Move)
    call PolledWait(Powerbash_Time(level))
    set brake = 1
    call SetHandleInt(t,"brake",brake)
    call PolledWait(Powerbash_Braketime(level))
    call PauseUnit(target, false)
    call FlushHandleLocals(t)
    call FlushHandleLocals(handletarget)
    call DestroyTimer(t)
    call IssuePointOrder(target, "patrol", x1, y1) // This is good for creeps or AOS
    call TriggerClearActions(letsbowl)
    call DestroyTrigger(letsbowl)
    set target = null // Units behind trees impossible.
    set caster = null
    set t = null
    set handletarget = null
    set letsbowl = null
endfunction

//===========================================================================
function InitTrig_Powerbash takes nothing returns nothing
    local integer i = 0
    set gg_trg_Powerbash = CreateTrigger()
    loop
        call TriggerRegisterPlayerUnitEvent(gg_trg_Powerbash, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set i = i + 1
        exitwhen i == bj_MAX_PLAYER_SLOTS
    endloop
    call TriggerAddCondition(gg_trg_Powerbash, Condition(function Trig_Powerbash_Conditions))
    call TriggerAddAction(gg_trg_Powerbash, function Trig_Powerbash_Actions)
endfunction


That would be it. If there are any errors in the code, please let me know (I couldn't check myself because of personal reasons)

Btw, it's coded in a weird way, I wonder who is it from....

Whoops, I thought I was supposed to optimize it so it doesn't lag, my bad......anyways, edited so it only knockbacks heroes (like you requested)
 
Last edited:
Level 19
Joined
Aug 24, 2007
Messages
2,888
umm I use them in spells for publishing
so I like making one code no globals no map header things
skip the global and optimizer for short ^^

why would I need constants in spells of my map anyway xD
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
This code is crappy, I can write you a new fancy one, but you need to have Jass NewGen Pack (find it at wc3campaigns later, because it's down atm) implemented, that's all.

Just tell me what you want this spell to do and why do you need it so badly if you don't have a clue what it means?
 
Level 5
Joined
May 27, 2007
Messages
144
well it is a knockback spell witch deals extra damage per tree.


Edit: i have Jass NewGen Pack downloaded.
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Can you be a little more specific? That description is very vague, I can't get anything from it.

Example of a spell definition:

Code:
Name: Thunder Blast
Type: Instant (meaning no target unit/area, like Thunder Clap)
Description: Each enemy unit in 600/700/800 range of the caster gets hit by a lightning bolt, dealing 100/200/300 damage to it.

Another example:

Code:
Name: Fire Fury
Type: Single Target (like Storm Bolt)
Description: A fire bolt blasts the targeted enemy unit, dealing 200/400/600 damage and stunning it for 1/2/3 seconds.

Now gimme a nice explanation. If you don't know English well enough to explain, ask someone from your state who knows English well to type the description for you, and you just post it.
 
Level 5
Joined
May 27, 2007
Messages
144
okey so

Name : Powerbash
Type: Single (hero) Target
Spell Range: Melee
Special: 5/10/15/20 damage by hiting a tree while knockbacking
Description:Hero attacks a units with such a power that it will be knockbacked (100/150/200/250 straight from the caster) dealing 70/130/190/230 damge and deals bonus damage when a target crushes against a tree.


Is it enough ?
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Put this in a trigger called Knockback (or name it whatever you want):

JASS:
library Knockback initializer Init_Knockback

public struct Data
    unit u
    real d1
    real d2

    real sin
    real cos

    real r
    
    string s = ""
    effect e = null
    
    real l = 0
    unit a = null
    
    method BonusDmg takes nothing returns real
        return 5 * .l
    endmethod
endstruct

globals
    private timer Tim = CreateTimer()
    private Data array Ar
    private integer Total = 0

    private item I = CreateItem('ciri', 0, 0)
    private boolexpr Cond
    private boolean B
endglobals

private function CheckPathabilityTrickGet takes nothing returns nothing
    set bj_rescueChangeColorUnit = bj_rescueChangeColorUnit or GetEnumItem() != I
endfunction

private function CheckPathabilityTrick takes real x, real y returns boolean
    local integer i = 30
    local real X
    local real Y
    local rect r
    call SetItemPosition(I, x, y)
    set X = GetItemX(I) - x
    set Y = GetItemY(I) - y
    if X * X + Y * Y <= 100 then
        return true
    endif
    set r = Rect(x - i, y - i, x + i, y + i)
    set bj_rescueChangeColorUnit = false
    call EnumItemsInRect(r, null, function CheckPathabilityTrickGet)
    call RemoveRect(r)
    set r = null
    return bj_rescueChangeColorUnit
endfunction

private function CheckPathability takes real x, real y returns boolean
    local boolean b = CheckPathabilityTrick(x, y)
    call SetItemVisible(I, false)
    return b
endfunction

public function TreeFilter takes nothing returns boolean
    local integer d = GetDestructableTypeId(GetFilterDestructable())
    return d == 'ATtr' or d == 'BTtw' or d == 'KTtw' or d == 'YTft' or d == 'JTct' or d == 'YTst' or d == 'YTct' or d == 'YTwt' or d == 'JTwt' or d == 'JTwt' or d == 'FTtw' or d == 'CTtr' or d == 'ITtw' or d == 'NTtw' or d == 'OTtw' or d == 'ZTtw' or d == 'WTst' or d == 'LTlt' or d == 'GTsh' or d == 'Xtlt' or d == 'WTtw' or d == 'Attc' or d == 'BTtc' or d == 'CTtc' or d == 'ITtc' or d == 'NTtc' or d == 'ZTtc'
endfunction

private constant function Interval takes nothing returns real
    return 0.04
endfunction

private function KillTree takes nothing returns nothing
    call KillDestructable(GetEnumDestructable())
    set B = true
endfunction

private function Execute takes nothing returns nothing
    local Data kd
    local integer i = 0
    local real x
    local real y
    local rect r

    loop
        exitwhen i >= Total
        set kd = Ar[i]

        if kd.s != null and kd.s != null then
            set x = GetUnitX(kd.u)
            set y = GetUnitY(kd.u)

            call DestroyEffect(AddSpecialEffect(kd.s, x, y))

            set x = x + kd.d1 * kd.cos
            set y = y + kd.d1 * kd.sin
        else
            set x = GetUnitX(kd.u) + kd.d1 * kd.cos
            set y = GetUnitY(kd.u) + kd.d1 * kd.sin
        endif

        if kd.r != 0 then
            set r = Rect(x - kd.r, y - kd.r, x + kd.r, y + kd.r)
            set B = false
            call EnumDestructablesInRect(r, Cond, function KillTree)
            
            if B and kd.a != null then
                call UnitDamageTarget(kd.a, kd.u, kd.BonusDmg(), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
            endif
            
            call RemoveRect(r)
            set r = null
        endif

        if CheckPathability(x, y) then
            call SetUnitX(kd.u, x)
            call SetUnitY(kd.u, y)
        endif

        set kd.d1 = kd.d1 - kd.d2


        if kd.d1 <= 0 or not CheckPathability(x, y) then
            if kd.e != null then
                call DestroyEffect(kd.e)
            endif
            call PauseUnit(kd.u, false)
            set Ar[i] = Ar[Total - 1]
            set Total = Total - 1
            call kd.destroy()
        endif

        set i = i + 1
    endloop

    if Total == 0 then
        call PauseTimer(Tim)
    endif
endfunction

function KnockbackEx takes unit u, real d, real a, real w, real r, integer t, string s, string p returns Data
    local Data kd = Data.create()
    local integer q = R2I(w / Interval())

    set kd.u = u
    set kd.d1 = 2 * d / (q + 1)
    set kd.d2 = kd.d1 / q
    
    set kd.sin = Sin(a)
    set kd.cos = Cos(a)

    set kd.r = r

    if s != "" and s != null then
        if t == 2 then
            if p != "" and p != null then
                set kd.e = AddSpecialEffectTarget(s, u, p)
            else
                set kd.e = AddSpecialEffectTarget(s, u, "chest")
            endif
        elseif t == 1 then
            set kd.s = s
        endif
    endif

    call SetUnitPosition(u, GetUnitX(u), GetUnitY(u))
    call PauseUnit(u, true)

    if Total == 0 then
        call TimerStart(Tim, Interval(), true, function Execute)
    endif

    set Total = Total + 1
    set Ar[Total - 1] = kd

    return kd
endfunction

function Knockback takes unit u, real d, real a, real w returns Data
    return KnockbackEx(u, d, a, w, 0, 0, "", "")
endfunction

//==================================

function Init_Knockback takes nothing returns nothing
    set Cond = Filter(function TreeFilter)
endfunction

endlibrary


Then put this in a trigger called Powerbash:

JASS:
scope Powerbash

globals
    private constant integer SPELL_ID = 'A000'
    private constant string SPELL_SFX = ""
    private constant real KNOCK_DUR = 1
    private constant real KNOCK_RADIUS = 50
    private constant integer KNOCK_TYPE = 1
endglobals

constant function KnockbackDist takes real lev returns real
    return 50 + 50 * lev
endfunction

function Powerbash_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELL_ID
endfunction

function Powerbash_Actions takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local unit t = GetSpellTargetUnit()
    local real x1 = GetUnitX(c)
    local real y1 = GetUnitY(c)
    local real x2 = GetUnitX(t)
    local real y2 = GetUnitY(t)
    local real a = Atan2(y2 - y1, x2 - x1)
    local real lev = I2R(GetUnitAbilityLevel(c, SPELL_ID))
    local Knockback_Data kd = KnockbackEx(t, KnockbackDist(lev), a, KNOCK_DUR, KNOCK_RADIUS, KNOCK_TYPE, SPELL_SFX, "")
    
    set kd.l = lev
    set kd.a = c
    
    set c = null
    set t = null
endfunction

//====================================================
function InitTrig_Powerbash takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    
    loop
        exitwhen i == bj_MAX_PLAYER_SLOTS
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set i = i + 1
    endloop
    
    call TriggerAddCondition(t, Condition(function Powerbash_Conditions))
    call TriggerAddAction(t, function Powerbash_Actions)
    
    set t = null
endfunction

endscope


The only thing you have to do is put the rawcode of your spell in the SPELL_ID constant. You know what a rawcode, do you? And you can also put the special effect you want in the knockback in the SPELL_SFX constant. Just make a GUI special effect, convert it to JASS, copy the part inside "" and replace it with the "" in SPELL_SFX constant. Example of rawcodes/special effect:

JASS:
private constant integer SPELL_ID = 'A005'
private constant string SPELL_SFX = "Units\\Abilities\\Spells\\ThunderClap\\ThunderClap.mdl"


Everything clear?

P.S. If you have trouble CnPing the code (because everything will be pasted in one line), then you can quote me (with the button in the right-foot corner of my post) and you can CnP it inside.

P.S.2 If you leave SPELL_SFX the way it is, no special effect will appear.
 
Last edited:
Level 5
Joined
May 27, 2007
Messages
144
@Silvenon: Wc3 world editor error. i can only close world editor and report it to blizzard.

@PurplePoot: How can i fix the last one ?
 
Level 5
Joined
May 27, 2007
Messages
144
do i need new veriables or sth ? I get syntax error, Statement outside of function, undeclared function Knockbackex, comparing two variables of different primitive types. when i check the spell using syntax check
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
No! You don't need new variables!

Did you do exactly as I said? You should have two triggers:

1st:

Trigger Name: Knockback
Code:

JASS:
library Knockback initializer Init_Knockback

public struct Data
    unit u
    real d1
    real d2

    real sin
    real cos

    real r
    
    string s = ""
    effect e = null
    
    real l = 0
    unit a = null
    
    method BonusDmg takes nothing returns real
        return 5 * .l
    endmethod
endstruct

globals
    private timer Tim = CreateTimer()
    private Data array Ar
    private integer Total = 0

    private item I = CreateItem('ciri', 0, 0)
    private boolexpr Cond
    private boolean B
endglobals

private function CheckPathabilityTrickGet takes nothing returns nothing
    set bj_rescueChangeColorUnit = bj_rescueChangeColorUnit or GetEnumItem() != I
endfunction

private function CheckPathabilityTrick takes real x, real y returns boolean
    local integer i = 30
    local real X
    local real Y
    local rect r
    call SetItemPosition(I, x, y)
    set X = GetItemX(I) - x
    set Y = GetItemY(I) - y
    if X * X + Y * Y <= 100 then
        return true
    endif
    set r = Rect(x - i, y - i, x + i, y + i)
    set bj_rescueChangeColorUnit = false
    call EnumItemsInRect(r, null, function CheckPathabilityTrickGet)
    call RemoveRect(r)
    set r = null
    return bj_rescueChangeColorUnit
endfunction

private function CheckPathability takes real x, real y returns boolean
    local boolean b = CheckPathabilityTrick(x, y)
    call SetItemVisible(I, false)
    return b
endfunction

public function TreeFilter takes nothing returns boolean
    local integer d = GetDestructableTypeId(GetFilterDestructable())
    return d == 'ATtr' or d == 'BTtw' or d == 'KTtw' or d == 'YTft' or d == 'JTct' or d == 'YTst' or d == 'YTct' or d == 'YTwt' or d == 'JTwt' or d == 'JTwt' or d == 'FTtw' or d == 'CTtr' or d == 'ITtw' or d == 'NTtw' or d == 'OTtw' or d == 'ZTtw' or d == 'WTst' or d == 'LTlt' or d == 'GTsh' or d == 'Xtlt' or d == 'WTtw' or d == 'Attc' or d == 'BTtc' or d == 'CTtc' or d == 'ITtc' or d == 'NTtc' or d == 'ZTtc'
endfunction

private constant function Interval takes nothing returns real
    return 0.04
endfunction

private function KillTree takes nothing returns nothing
    call KillDestructable(GetEnumDestructable())
    set B = true
endfunction

private function Execute takes nothing returns nothing
    local Data kd
    local integer i = 0
    local real x
    local real y
    local rect r

    loop
        exitwhen i >= Total
        set kd = Ar[i]

        if kd.s != null and kd.s != null then
            set x = GetUnitX(kd.u)
            set y = GetUnitY(kd.u)

            call DestroyEffect(AddSpecialEffect(kd.s, x, y))

            set x = x + kd.d1 * kd.cos
            set y = y + kd.d1 * kd.sin
        else
            set x = GetUnitX(kd.u) + kd.d1 * kd.cos
            set y = GetUnitY(kd.u) + kd.d1 * kd.sin
        endif

        if kd.r != 0 then
            set r = Rect(x - kd.r, y - kd.r, x + kd.r, y + kd.r)
            set B = false
            call EnumDestructablesInRect(r, Cond, function KillTree)
            
            if B and kd.a != null then
                call UnitDamageTarget(kd.a, kd.u, kd.BonusDmg(), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
            endif
            
            call RemoveRect(r)
            set r = null
        endif

        if CheckPathability(x, y) then
            call SetUnitX(kd.u, x)
            call SetUnitY(kd.u, y)
        endif

        set kd.d1 = kd.d1 - kd.d2


        if kd.d1 <= 0 or not CheckPathability(x, y) then
            if kd.e != null then
                call DestroyEffect(kd.e)
            endif
            call PauseUnit(kd.u, false)
            set Ar[i] = Ar[Total - 1]
            set Total = Total - 1
            call kd.destroy()
        endif

        set i = i + 1
    endloop

    if Total == 0 then
        call PauseTimer(Tim)
    endif
endfunction

function KnockbackEx takes unit u, real d, real a, real w, real r, integer t, string s, string p returns Data
    local Data kd = Data.create()
    local integer q = R2I(w / Interval())

    set kd.u = u
    set kd.d1 = 2 * d / (q + 1)
    set kd.d2 = kd.d1 / q
    
    set kd.sin = Sin(a)
    set kd.cos = Cos(a)

    set kd.r = r

    if s != "" and s != null then
        if t == 2 then
            if p != "" and p != null then
                set kd.e = AddSpecialEffectTarget(s, u, p)
            else
                set kd.e = AddSpecialEffectTarget(s, u, "chest")
            endif
        elseif t == 1 then
            set kd.s = s
        endif
    endif

    call SetUnitPosition(u, GetUnitX(u), GetUnitY(u))
    call PauseUnit(u, true)

    if Total == 0 then
        call TimerStart(Tim, Interval(), true, function Execute)
    endif

    set Total = Total + 1
    set Ar[Total - 1] = kd

    return kd
endfunction

function Knockback takes unit u, real d, real a, real w returns Data
    return KnockbackEx(u, d, a, w, 0, 0, "", "")
endfunction

//==================================

function Init_Knockback takes nothing returns nothing
    set Cond = Filter(function TreeFilter)
endfunction

endlibrary

function InitTrig_Knockback takes nothing returns nothing
endfunction


2nd:

Trigger Name: Powerbash
Code:

JASS:
scope Powerbash

globals
    private constant integer SPELL_ID = 'A000'
    private constant string SPELL_SFX = ""
    private constant real KNOCK_DUR = 1
    private constant real KNOCK_RADIUS = 50
    private constant integer KNOCK_TYPE = 1
endglobals

constant function KnockbackDist takes real lev returns real
    return 50 + 50 * lev
endfunction

function Powerbash_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELL_ID
endfunction

function Powerbash_Actions takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local unit t = GetSpellTargetUnit()
    local real x1 = GetUnitX(c)
    local real y1 = GetUnitY(c)
    local real x2 = GetUnitX(t)
    local real y2 = GetUnitY(t)
    local real a = Atan2(y2 - y1, x2 - x1)
    local real lev = I2R(GetUnitAbilityLevel(c, SPELL_ID))
    local Knockback_Data kd = KnockbackEx(t, KnockbackDist(lev), a, KNOCK_DUR, KNOCK_RADIUS, KNOCK_TYPE, SPELL_SFX, "")
    
    set kd.l = lev
    set kd.a = c
    
    set c = null
    set t = null
endfunction

//====================================================
function InitTrig_Powerbash takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    
    loop
        exitwhen i == bj_MAX_PLAYER_SLOTS
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set i = i + 1
    endloop
    
    call TriggerAddCondition(t, Condition(function Powerbash_Conditions))
    call TriggerAddAction(t, function Powerbash_Actions)
    
    set t = null
endfunction

endscope


This SHOULD work!

Are you sure something isn't wrong with your NewGen? Perhaps you have cracked wc3? Check if the editor opened by NewGen Editor.exe is the real NewGen editor, look if there are any toolbars after HELP (there should be EXTENSIONS, GRIMOIRE......)

P.S. Where do you get errors? Can you give me some error returns? I mean what error was returned on which line.
 
Last edited:
Level 5
Joined
May 27, 2007
Messages
144
I have the 2 and yes it is original wc3! and the newgen works fine coz when i start it i get new toolbars with 3 neew field full of options.
Edit:
Powerbash errors
Line 1: syntax error
Line 1:Statement outside of function 2 times same line same mistake
Line 3:Statement outside of function 2 times same line same mistake
Line 4:Statement outside of function 7 times same line same mistake
Line 5:Statement outside of function 6 times same line same mistake
Line 6-9 : Statement outside of function
Line 16: Undeclared variable SPELL_ID
Line 17:Comparing two variables of different primitive types (except real and integer) is not allowed
Line 27: Undeclared variable SPELL_ID
Line28:Undefined type Knockback_Data
Line28:undefined variable KNOCK_DUR
Line28:undefined variable KNOCK_RADIUS
Line28:undeclared variable KNOCK_TYPE
Line28:Undeclared variable SPELL_SFX
Line28:Undeclared function KnockbackEx
Line30,31.54: syntax error
Line 54: Statement outside of function 2 times same line same mistake
Knockback
Line1: syntax error
line1-19: statement outside of function
line20:syntax error
line 20-34: statement outside of function
line34: Missing linebreak before function declaration
Line35: undeclared variable I
Line36: Comparing two variables of different primitive types (except real and integer) is not allowed
Line38: syntax error
Line38: statement outside of function
Line38:missing linebreak before function declaration
Line43: Undeclared variable I
Line57: syntax error
Line57: Missing linebreak before function declaration
Line57: statement outside of function
Line59: Undeclared variable I
Line63: syntax error
Line63: statement outside of function
line 63:Missing linebreak before function declaration
Line68: syntax error
Line68:Statement outside of function
Line68:missing linebreak before function declaration
Line72: syntax error
Line72:statement outside of function
Line72 missing linebreak before function declaration
Line74: Undeclared variable B
Line77: syntax error
Line77:statement outside of function
Line77:missing linebreak before function declarartion
Line78:Undefined type Data
Line85:Undeclared variable Total
Line86:undeclared variable Ar
Line88-90,92: syntax error
Line 94: Bad types for binary opferator
Line94: syntax error
Line95:Bad types for binary operator
Line95: syntax error
Line96:Missing endloop
Line96:Missing endfunction
Line96:Statement outside of function
Line97:undeclared variable kd
Line97: syntax error
line97:Statement outside of function 12 times same mistake in this line
Line98:syntax error
Line98:Statement outside of function 12 times same mistake
Line99:Statement outside of function
Line101:syntax error
Line101:Statement outside of function
Line102:Undeclared variable x
Line102: syntax error
Line102:Statement outside of function 22 times same mistake
Line103: Undeclared variable B
Line104: Undeclared variable r
Line104: undeclared variable Cond.
Line105:Statement outside of function
Line106: syntax error
Line106:Statement outside of function
Line107: syntax error
Line107:statement outside of function 24 times same mistake
Line108,111,112:Statement outside of function
Line112: syntax error
Line114: Undeclared variable y
Line115,116: syntax error
Line118:Statement outside of function
Line119: syntax error
Line119:Statement outside of function 11 times
Line122: syntax error
Line122:Statement outside of function 13 times
Line123:syntax error
Line123:Statement outside of function
Line124: syntax error
Line124,125: Statement outside of function
line126: syntax error
Line126:Statement outside of function
Line127: Undeclared variable i, Total, Ar
Line128-130,133:Statement outside of function
Line129: syntax error
Line 133: syntax error
Line135: Comparing two variables of different primitive types (except real and integer) is not allowed
Line136: Undeclared variable Tim
line138:Statement outside of function
Line138,141: syntax error
Line140,141: Undefined type Data
Line141: undeclared variable Data
Line141: Local declaration after first statement
Line144-146,148-149,151,156,158,161: syntax error
Line168:Comparing two variables of different primitive types (except real and integer) is not allowed
Line178:Undefined type Data
Line188:statement outside of function
Line188:syntax error
at last finshed
 
Last edited:
Level 13
Joined
Nov 22, 2006
Messages
1,260
I know, I fucking changed it because you said this:

I think public only uses a prefix outside of the scope.

I seem to have misunderstood you.

Silvenon, InitTrigs are unneeded in the newer JNGP versions.

I know, I'm just used to having them, they make company to the libraries, otherwise the libraries would be lonely and sad.

Fixed it (again) to what it was before. But since Mateus already tried that code before and it still returned errors like it has never seen vJass..........So I'm outta ideas and I don't feel like making a regular JASS spell.

And also, I forgot how to code in regular JASS.
 
Status
Not open for further replies.
Top