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

[JASS] Grav Pull

Status
Not open for further replies.
Anyone know what's wrong with my script?

JASS:
        local real angleTowards=angleBetweenXY(GetUnitX(GetFilterUnit()),GetUnitY(GetFilterUnit()),GetUnitX(tempBomb),GetUnitY(tempBomb))
        local real distance=SquareRoot(((GetUnitX(GetFilterUnit())-GetUnitX(tempBomb))*(GetUnitX(GetFilterUnit())-GetUnitX(tempBomb)))+((GetUnitY(GetFilterUnit())-GetUnitY(tempBomb))*(GetUnitY(GetFilterUnit())-GetUnitY(tempBomb))))
        if GetOwningPlayer(GetFilterUnit())!=tempOwner then
            call SetUnitX(GetFilterUnit(),GetUnitX(GetFilterUnit())+(tempGravPull-distance)/20*Cos(angleTowards*bj_DEGTORAD))
            call SetUnitY(GetFilterUnit(),GetUnitY(GetFilterUnit())+(tempGravPull-distance)/20*Sin(angleTowards*bj_DEGTORAD))
        endif
        return false

Somehow units are being affected by the pull when they don't meet the conditions. I'm confused TT
 
gravPull:
JASS:
scope gravityBomb initializer i

    private function c takes nothing returns boolean

        local unit u

        if GetSpellAbilityId()=='A003' then

            set u=CreateUnit(GetOwningPlayer(GetSpellAbilityUnit()),'h003',GetUnitX(GetSpellAbilityUnit()),GetUnitY(GetSpellAbilityUnit()),GetUnitFacing(GetSpellAbilityUnit()))

            call SetUnitExploded(u,true)

            call SetUnitMoveSpeed(u,1)

            call UnitApplyTimedLife(u,'BHav',3)

            call SetUnitPathing(u,false)

            call knockb(GetSpellTargetUnit(),GetUnitFacing(GetSpellAbilityUnit()),5,false,false,350)

        endif

        return false

    endfunction

    

    private function i takes nothing returns nothing

        local trigger t=CreateTrigger()

        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)

        call TriggerAddCondition(t,Condition(function c))

    endfunction

endscope

kb:
JASS:
scope knockback

    private struct kData

        unit u

        real direction

        integer power

        integer gravPull

        boolean friction

        boolean killsTouchees

    endstruct

    

    globals

        private timer time=CreateTimer()

        private kData array kDB

        private integer dbIndex=-1

        private group GROUP=CreateGroup()

        private unit tempBomb

        private real tempGravPull

        private player tempOwner

    endglobals

    

    private function f takes nothing returns boolean

        if GetUnitTypeId(GetFilterUnit())=='h000' then

            call SetUnitExploded(GetFilterUnit(),true)

            call KillUnit(GetFilterUnit())

        endif

        return false

    endfunction



    private function f2 takes nothing returns boolean

        local real angleTowards=angleBetweenXY(GetUnitX(GetFilterUnit()),GetUnitY(GetFilterUnit()),GetUnitX(tempBomb),GetUnitY(tempBomb))

        local real distance=SquareRoot(((GetUnitX(GetFilterUnit())-GetUnitX(tempBomb))*(GetUnitX(GetFilterUnit())-GetUnitX(tempBomb)))+((GetUnitY(GetFilterUnit())-GetUnitY(tempBomb))*(GetUnitY(GetFilterUnit())-GetUnitY(tempBomb))))

        if GetOwningPlayer(GetFilterUnit())!=tempOwner then

            call SetUnitX(GetFilterUnit(),GetUnitX(GetFilterUnit())+(tempGravPull-distance)/20*Cos(angleTowards*bj_DEGTORAD))

            call SetUnitY(GetFilterUnit(),GetUnitY(GetFilterUnit())+(tempGravPull-distance)/20*Sin(angleTowards*bj_DEGTORAD))

        endif

        return false

    endfunction

    

    private function p takes nothing returns nothing

        local integer index=0

        local kData tempDat

        local real x

        local real y

        loop

            exitwhen index>dbIndex

            set tempDat=kDB[index]

            set x=GetUnitX(tempDat.u)+tempDat.power*Cos(tempDat.direction*bj_DEGTORAD)

            set y=GetUnitY(tempDat.u)+tempDat.power*Sin(tempDat.direction*bj_DEGTORAD)

            if IsTerrainWalkable(x,y) then

                call SetUnitX(tempDat.u,x)

                call SetUnitY(tempDat.u,y)

            else

                set tempDat.direction=0-tempDat.direction

                set x=GetUnitX(tempDat.u)+tempDat.power*Cos(tempDat.direction*bj_DEGTORAD)

                set y=GetUnitY(tempDat.u)+tempDat.power*Sin(tempDat.direction*bj_DEGTORAD)

                if IsTerrainWalkable(x,y) then

                    call SetUnitX(tempDat.u,x)

                    call SetUnitY(tempDat.u,y)

                else

                    set tempDat.direction=tempDat.direction-180

                endif

                if tempDat.friction then

                    set tempDat.power=tempDat.power*3/4

                endif

            endif

            if tempDat.killsTouchees then

                call GroupEnumUnitsInRange(GROUP,GetUnitX(tempDat.u),GetUnitY(tempDat.u),70,Filter(function f))

            endif

            if tempDat.friction then

                set tempDat.power=tempDat.power-1

            endif

            if GetUnitState(tempDat.u,UNIT_STATE_LIFE)<1 then

                set tempDat.power=tempDat.power-1

            endif

            if tempDat.gravPull>0 then

                set tempBomb=tempDat.u

                set tempGravPull=tempDat.gravPull

                set tempOwner=GetOwningPlayer(tempDat.u)

                call GroupEnumUnitsInRange(GROUP,GetUnitX(tempDat.u),GetUnitY(tempDat.u),tempDat.gravPull,Filter(function f2))

            endif

            if tempDat.power<0 then

                call tempDat.destroy()

                set kDB[index]=kDB[dbIndex]

                set dbIndex=dbIndex-1

                if dbIndex==-1 then

                    call PauseTimer(time)

                endif

            endif

            set index=index+1

        endloop

    endfunction

    

    function knockb takes unit u, real direction, integer power, boolean friction, boolean killsTouchees, integer gravPull returns nothing

        local kData tempDat=kData.create()

        set tempDat.u=u

        set tempDat.direction=direction

        set tempDat.power=power

        set tempDat.friction=friction

        set tempDat.killsTouchees=killsTouchees

        set tempDat.gravPull=gravPull

        set dbIndex=dbIndex+1

        set kDB[dbIndex]=tempDat

        if dbIndex==0 then

            call TimerStart(time,.03,true,function p)

        endif

    endfunction

endscope

edit3: no fuckin clue where all the spaces came from.. i had to copy the script from another computer.
 
Level 8
Joined
Feb 15, 2009
Messages
463
save GetSpellAbilityUnit in a variable

the trigger should look like

JASS:
scope GravityBomb initializer Init

    private function Conditions takes nothing returns boolean

        local unit u
        local unit t
        local unit d
        local real a

        if GetSpellAbilityId()=='A003' then
            set u = GetTriggerUnit()
            set t = GetSpellTargetUnit()
            set a = GetUnitFacing(u)
            set d = CreateUnit(GetOwningPlayer(u),'h003',GetUnitX(u),GetUnitY(u), a)

            call SetUnitExploded(u,true)
            call UnitApplyTimedLife(u,'BHav',3)
            call SetUnitPathing(u,false)

            call knockb(t, a ,5,false,false,350)
//i think this should be in radians so put a *bj_DEGTORAD 
//after the variable a if still wrong direction knock
        endif

        return false

    endfunction



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

also be sure that the scope's name is the same then the Trigger Name(space is also forbidden)
 
Level 8
Joined
Feb 15, 2009
Messages
463
i mean a wait through timers like :

JASS:
struct dummy
unit d
endstruct

function RemoveDummy takes nothing returns nothing
    local dummy d = GetTimerData(GetExpiredTimer())

    call RemoveUnit(d.d)
    set d.d = null
    call d.destroy
endfunction

function a takes nothing returns nothing
    local dummy d = dummy.create()
    local timer t = NewTimer()

    set d.d = CreateUnit(blabla)
    call SetTimerData( t , d)
    call TimerStart(t , ... , false , function RemoveDummy)
    endfunction

requires TimerUtils
it's freehand but i hope it's clear what i meant
 
Level 8
Joined
Feb 15, 2009
Messages
463
JASS:
local unit u = GetFilterUnit()
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local real tx = GetUnitX(tempBomb)
local real ty = GetUnitY(tempBomb)
local real angle = Atan2( ty - y , tx - x)
local real distance = SquareRoot((x - tx)*(x - tx) + (y - ty) * (y - ty))

        if GetOwningPlayer(u)!=tempOwner then
            call SetUnitX(u , x + (tempGravPull-distance)/20*Cos(angle))
            call SetUnitY(u ,y + (tempGravPull-distance)/20*Sin(angle))
        endif
        return false


saved a lot of function calls and should work now for you =D
 
Status
Not open for further replies.
Top