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

KB3D - Knock back 3D

Status
Not open for further replies.
Level 16
Joined
Jul 31, 2012
Messages
2,217
Lol malhorne, how old are you?
image.jpg
 
Level 16
Joined
Jul 31, 2012
Messages
2,217
malhorne, i got confused ....
here is what i've got
i need to find the time taken for the knockback in the condtions:
JASS:
    if ( udg_KB3D_Accel == 0.00 ) then
        set Time = udg_KB3D_Range / udg_KB3D_Speed
    else
        if ( udg_KB3D_Accel > 0 ) then
            set Time = ( -2*udg_KB3D_Speed + SquareRoot(4*udg_KB3D_Speed*udg_KB3D_Speed + 4*udg_KB3D_Accel*2*udg_KB3D_Range ) ) / 2*udg_KB3D_Accel
        endif
        if ( udg_KB3D_Accel < 0 ) then
            set R = ( - 1 * udg_KB3D_Speed / udg_KB3D_Accel )
            set R1 = 0.5 * udg_KB3D_Accel * R * R
            if R1 < udg_KB3D_Range then
                set Time = R
            else
                ////////////////Stuck
        endif
    endif
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
[jass=unnecessary operations]
set Fx = ""
set Attach = ""

set udg_KB3D_Fx = ""
set udg_KB3D_Fx_Attach = ""
[/code]
You really don't need to do this, strings are stored on an internal string table, and we can't tell that internal table to remove the string you just used. It just wastes processing time.
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
I see you've improved your scripting skills.
JASS:
    set udg_KB3D_Loop = CreateTrigger(  )
    call TriggerRegisterTimerEvent( udg_KB3D_Loop, 0.031250000, true )
    call TriggerAddCondition( udg_KB3D_Loop, function KB3D_Loop_Actions )
    call DisableTrigger( udg_KB3D_Loop )
So, you've optimized your triggers by using a TriggerCondition to fire your main loop. If you've bothered to do this then I predict that the moderators who will review this will suggest you to use timers instead.
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
Instead of using triggers to execute a periodic event, you use timers.
i.e.
DisableTrigger -> PauseTimer
Finish the project first and optimize later, when the system is perfectly functional.
 
Level 16
Joined
Jul 31, 2012
Messages
2,217
quick help plz :S
here is the one i am working on right now
i have a missing endblock, prob, i can't find it :S
JASS:
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//           Knock-Back 3D  v. 1.0.0.0   [JASS - GUI]                      //
//                                                by JAD aka DotCa         //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//           System Informations:                                          //
//                                                                         //
//  The System is a well performing, ultra-purpose knockback (see uses     //
//  below ) Coded in JASS making it possible for all users to take         //
//  advantage of it, and GUI friendly to use, see Examples in the triggers //
//  above                                                                  //
//               Configurations have default values:                       //
//                                                                         //
//     - KB3D_DestroyTree      == FALSE by defalut                         //
//     - KB3D_DisableUnit      == FALSE by defalut                         //
//     - KB3D_UnpathaableStop  == TRUE by defalut                          //
//                                                                         //
//  The System also uses Always positive values for some configurations    //
//  to not make the knockback go worng, those configurations are:          //
//                                                                         //
//         "KB3D_Range"  -  "KB3D_Speed"  -  "KB3D_ZOffset"                //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//           System Requirements:   Basic WE - (NONE)                      //
//                                                                         //
//  The System uses implemented CheckWalkability System by PurgeandFire    //
//  You "can" remove the initialization trigger of PnF's System since      //
//  it is directly implemented in the System, all will work fine with or   //
//  without removing your Initializer trigger                              //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//           Credits:                                                      //
//                                                                         //
//    *Chobibo for helping in Script Fixes                                 //
//    *Malhorne for helping in main codes and fixes                        //
//    *PurgeandFire for his CheckWalkability System                        //
//    *Nestharus for his GetCollision function                             //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//           How to Import?                                                //
//                                                                         //
//  1. Check that Create Unkown Variables is ticked in your WE Settings    //
//  2. Copy the Paste this Trigger                                         //
//  3. Congratulations, the System is now implemented in your map          //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//           How to Use?                                                   //
//                                                                         //
//  1. There are 3 Examples of use in the KB3D Example Folder              //
//  2. Documentations are there in each of the 3 examples to help you      //
//  3. The KB3D System is an Ultra-Purpose System where you can use it for://
//     -Projectiles, the system supports homming so a projectile is easy   //
//     -Jump, the System's smoothness in the fly is useful for a jump spell//
//     -And of course, a 2D Knock-Back                                     //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//           Bug Reports - Feedbacks                                       //
//                                                                         //
//  * We count on you to report bugs in the system, also telling the source//
//  * Feedbacks about the system are much appreciated                      //
//  * We mostly hope suggestions about enhancements for the System         //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////

function KB3D_AlwaysNeg takes real R returns real
    if R > 0 then
        set R = R * -1
    endif
    return R
endfunction

function KB3D_AlwaysPos takes real R returns real
    if R < 0 then
        set R = R * -1
    endif
    return R
endfunction

function KB3D_InBetween takes real Min, real Max, real R returns real
    if R < Min then
        set R = Min
    endif
    if R > Max then
        set R = Max
    endif
    return R
endfunction

function KB3D_RegisterUnitCollision takes unit u, real x, real y, integer i returns real
    local real l = 0
    local real h = 300
    local real m = 150
    local real nm  
    loop
        if (IsUnitInRangeXY(u, x+m, y, 0)) then
            set l = m
        else
            set h = m
        endif
        set nm = (l+h)/2
        exitwhen nm+.001 >  m and nm-.001 < m
        set m = nm
    endloop
    set m = R2I(m*10)/10.
    call SaveReal( udg_KB3D_HA, 16, GetUnitTypeId(u), m )
    return m
endfunction

function KB3D_GetUnitCollision takes unit u returns real
    local integer i = GetUnitTypeId(u)
    if HaveSavedReal( udg_KB3D_HA, 16, i) then
        return LoadReal(udg_KB3D_HA, 16, i)
    endif
    return KB3D_RegisterUnitCollision(u, GetUnitX(u), GetUnitY(u), i)
endfunction

function KB3D_Registration takes nothing returns boolean
    local real Time
    local real R
    local real R1
    set udg_KB3D_Speed = KB3D_AlwaysPos(udg_KB3D_Speed)
    set udg_KB3D_Range = KB3D_AlwaysPos(udg_KB3D_Range)
    set udg_KB3D_Counter = udg_KB3D_Counter + 1
    set udg_KB3D_Instances = udg_KB3D_Instances + 1
    set udg_KB3D_Zoffset = 2 * KB3D_AlwaysPos(udg_KB3D_Zoffset)
    call SaveUnitHandle( udg_KB3D_HA, 0, udg_KB3D_Counter, udg_KB3D_Unit )
    call SaveReal( udg_KB3D_HA, 1, udg_KB3D_Counter, udg_KB3D_Range )
    call SaveReal( udg_KB3D_HA, 2, udg_KB3D_Counter, udg_KB3D_Speed )
    call SaveReal( udg_KB3D_HA, 4, udg_KB3D_Counter, udg_KB3D_Accel )
    if ( udg_KB3D_Targeted_Unit == null ) then
        call SaveReal( udg_KB3D_HA, 5, udg_KB3D_Counter, udg_KB3D_Angle * 3.14159 / 180 )
    else
        call SaveUnitHandle( udg_KB3D_HA, 5, udg_KB3D_Counter, udg_KB3D_Targeted_Unit )
    endif
    call SaveBoolean( udg_KB3D_HA, 6, udg_KB3D_Counter, udg_KB3D_DisableUnit )
    call SaveBoolean( udg_KB3D_HA, 7, udg_KB3D_Counter, udg_KB3D_UnpathableStop )
    call SaveBoolean( udg_KB3D_HA, 8, udg_KB3D_Counter, udg_KB3D_DestroyTree )
    call SaveStr( udg_KB3D_HA, 9, udg_KB3D_Counter, udg_KB3D_Fx )
    call SaveStr( udg_KB3D_HA, 10, udg_KB3D_Counter, udg_KB3D_Fx_Attach )
    if ( udg_KB3D_Accel == 0.00 ) then
        set Time = udg_KB3D_Range / udg_KB3D_Speed
    else
        if ( udg_KB3D_Accel > 0 ) then
            set Time = (( -2*udg_KB3D_Speed + SquareRoot((4*udg_KB3D_Speed) + (8*udg_KB3D_Accel*udg_KB3D_Range) ) ) / (2*udg_KB3D_Accel) )
        endif
        if ( udg_KB3D_Accel < 0 ) then
            set R = ( - 1 * udg_KB3D_Speed / udg_KB3D_Accel )
            set R1 = (0.5 * udg_KB3D_Accel * R * R) + (udg_KB3D_Speed * R)
            if R1 < udg_KB3D_Range then
                set Time = R
            else
                set Time = KB3D_AlwaysPos(( -2*udg_KB3D_Speed + SquareRoot(KB3D_AlwaysPos((4*udg_KB3D_Speed*udg_KB3D_Speed) + (8*udg_KB3D_Accel*udg_KB3D_Range) )) ) / (2*udg_KB3D_Accel) )
            endif
        endif
    endif
    call SaveReal( udg_KB3D_HA, 11, udg_KB3D_Counter, Time )
    call SaveBoolean( udg_KB3D_HA, 15, udg_KB3D_Counter, true )
    if UnitAddAbility(udg_KB3D_Unit, 'Amrf') then
        call UnitRemoveAbility(udg_KB3D_Unit, 'Amrf')
    endif
    if ( udg_KB3D_Counter == 1 ) then
        call EnableTrigger(udg_KB3D_Loop)
    endif
    call SaveReal( udg_KB3D_HA, 3, udg_KB3D_Counter, udg_KB3D_Zoffset )
    call SaveReal( udg_KB3D_HA, 12, udg_KB3D_Counter, udg_KB3D_Zoffset / ( Time / 2) )
    call SaveReal( udg_KB3D_HA, 13, udg_KB3D_Counter, KB3D_AlwaysNeg(( -1 * udg_KB3D_Zoffset / ( Time / 2) ) / ( Time / 2)) )
    //Nulling
    set udg_KB3D_Accel = 0.00
    set udg_KB3D_Angle = 0.00
    set udg_KB3D_DestroyTree = false
    set udg_KB3D_DisableUnit = false
    set udg_KB3D_Range = 0.00
    set udg_KB3D_Speed = 0.00
    set udg_KB3D_Targeted_Unit = null
    set udg_KB3D_Unit = null
    set udg_KB3D_UnpathableStop = true
    set udg_KB3D_Zoffset = 0.00
    return false
endfunction

function KB3D_Tree_Check takes destructable D returns boolean
    local boolean B = false
    call IssueTargetOrder( udg_KB3D_Harvester, "harvest", D )
    if ( GetUnitCurrentOrder(udg_KB3D_Harvester) == OrderId("harvest") ) then
        set B = true
    endif
    call IssueImmediateOrder(udg_KB3D_Harvester, "stop")
    return B
endfunction

function KB3D_KillifTree takes destructable D returns nothing
    if ( KB3D_Tree_Check(D) ) then
        call KillDestructable(D)
    endif
endfunction

function KB3D_KillEnumDest takes nothing returns nothing
    call KB3D_KillifTree(GetEnumDestructable())
endfunction

function KB3D_CircleTreeKill takes real radius, real x, real y returns nothing
    local rect r
    set r = Rect(x-radius, y-radius, x+radius, y+radius)
    call EnumDestructablesInRect(r, null, function KB3D_KillEnumDest)
    call RemoveRect(r)
    set r = null
endfunction

function KB3D_CW_Loop takes nothing returns nothing
    if IsItemVisible(GetEnumItem()) then
        set udg_CP_HiddenItems[udg_CP_HiddenItemsIndex] = GetEnumItem()
        call SetItemVisible(udg_CP_HiddenItems[udg_CP_HiddenItemsIndex], false)
        set udg_CP_HiddenItemsIndex = ( udg_CP_HiddenItemsIndex + 1 )
    endif
endfunction

function KB3D_CW takes real x, real y returns boolean
    local real x2 = 0
    local real y2 = 0
    call MoveRectTo(udg_CP_Rect, x, y)
    call EnumItemsInRect(udg_CP_Rect, null, function KB3D_CW_Loop ) 
    call SetItemPosition(udg_CP_Item, x, y)
    set x2 = GetItemX(udg_CP_Item)
    set y2 = GetItemY(udg_CP_Item)
    call SetItemVisible(udg_CP_Item, false)
    loop
        exitwhen udg_CP_HiddenItemsIndex <= 0
        set udg_CP_HiddenItemsIndex = udg_CP_HiddenItemsIndex - 1
        call SetItemVisible(udg_CP_HiddenItems[udg_CP_HiddenItemsIndex], true)
        set udg_CP_HiddenItems[udg_CP_HiddenItemsIndex] = null
    endloop
    set udg_CP_PointIsWalkable = ((x2-x)*(x2-x) + (y2-y)*(y2-y) <= 100) and (not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY)) 
    return udg_CP_PointIsWalkable
endfunction

function KB3D_Deindex takes integer index returns nothing
    call SaveUnitHandle( udg_KB3D_HA, 0, index, LoadUnitHandle(udg_KB3D_HA, 0, udg_KB3D_Counter) )
    call SaveReal( udg_KB3D_HA, 1, index, LoadReal(udg_KB3D_HA, 1, udg_KB3D_Counter) )
    call SaveReal( udg_KB3D_HA, 2, index, LoadReal(udg_KB3D_HA, 2, udg_KB3D_Counter) )
    call SaveReal( udg_KB3D_HA, 3, index, LoadReal(udg_KB3D_HA, 3, udg_KB3D_Counter) )
    call SaveReal( udg_KB3D_HA, 4, index, LoadReal(udg_KB3D_HA, 4, udg_KB3D_Counter) )
    if ( LoadUnitHandle(udg_KB3D_HA, 5, udg_KB3D_Counter) == null ) then
        call SaveReal( udg_KB3D_HA, 5, index, LoadReal(udg_KB3D_HA, 5, udg_KB3D_Counter) )
    else
        call SaveUnitHandle( udg_KB3D_HA, 5, index, LoadUnitHandle(udg_KB3D_HA, 5, udg_KB3D_Counter) )
    endif
    call SaveBoolean( udg_KB3D_HA, 6, index, LoadBoolean(udg_KB3D_HA, 6, udg_KB3D_Counter) )
    call SaveBoolean( udg_KB3D_HA, 7, index, LoadBoolean(udg_KB3D_HA, 7, udg_KB3D_Counter) )
    call SaveBoolean( udg_KB3D_HA, 8, index, LoadBoolean(udg_KB3D_HA, 8, udg_KB3D_Counter) )
    call SaveStr( udg_KB3D_HA, 9, index, LoadStr(udg_KB3D_HA, 9, udg_KB3D_Counter) )
    call SaveStr( udg_KB3D_HA, 10, index, LoadStr(udg_KB3D_HA, 10, udg_KB3D_Counter) )
    call SaveReal( udg_KB3D_HA, 11, index, LoadReal(udg_KB3D_HA, 11, udg_KB3D_Counter) )
    call SaveReal( udg_KB3D_HA, 12, index, LoadReal(udg_KB3D_HA, 12, udg_KB3D_Counter) )
    call SaveReal( udg_KB3D_HA, 13, index, LoadReal(udg_KB3D_HA, 13, udg_KB3D_Counter) )
    call SaveBoolean( udg_KB3D_HA, 15, index, true)
    set udg_KB3D_Counter = udg_KB3D_Counter - 1
endfunction

function KB3D_Group_Loop takes integer Loop returns nothing
    local unit U = LoadUnitHandle(udg_KB3D_HA, 0, Loop)
    local real X = GetUnitX(U)
    local real Y = GetUnitY(U)
    local real Z = GetUnitFlyHeight(U)
    local real x
    local real y
    local real z
    local real Range = LoadReal(udg_KB3D_HA, 1, Loop)
    local real Speed = LoadReal(udg_KB3D_HA, 2, Loop)
    local real Zoffset = LoadReal(udg_KB3D_HA, 3, Loop)
    local real Accel = LoadReal(udg_KB3D_HA, 4, Loop)
    local real Angle
    local real ZSpeed = LoadReal(udg_KB3D_HA, 12, Loop)
    local real ZAccel = LoadReal(udg_KB3D_HA, 13, Loop)
    local real ZTot = LoadReal(udg_KB3D_HA, 14, Loop)
    local unit Target = LoadUnitHandle(udg_KB3D_HA, 5, Loop)
    local boolean DisableUnit = LoadBoolean(udg_KB3D_HA, 6, Loop)
    local boolean UnpathableStop = LoadBoolean(udg_KB3D_HA, 7, Loop)
    local boolean DestroyTree = LoadBoolean(udg_KB3D_HA, 8, Loop)
    local string Fx = LoadStr(udg_KB3D_HA, 9, Loop)
    local string Attach = LoadStr(udg_KB3D_HA, 10, Loop)
    if ( Target == null ) then
        set Angle = LoadReal(udg_KB3D_HA, 5, Loop)
    else
        set Angle = Atan2(GetUnitY(Target) - Y, GetUnitX(Target) - X)
    endif
    set Speed = Speed + ( 0.031250000 * Accel )
    set Range = Range - ( Speed * 0.031250000 )
    set ZSpeed = ZSpeed + ( 0.031250000 * ZAccel )
    set x = X + ( Speed * 0.031250000 * Cos(Angle) )
    set y = Y + ( Speed * 0.031250000 * Sin(Angle) )
    set z = Z + ( ZSpeed * 0.031250000 )
    set ZTot = ZTot + ( ZSpeed * 0.031250000 )
    if (DestroyTree) then
        call KB3D_CircleTreeKill( 5 * KB3D_GetUnitCollision(U), x, y )
    endif
    if ( z < 1250 ) then
        call SetUnitFlyHeight(U, KB3D_InBetween(GetUnitDefaultFlyHeight(U), 99999, z), 9999)
    endif
    if ( z > 0 ) then
        call DestroyEffect(AddSpecialEffectTarget(Fx, U, Attach))
    else
        call DestroyEffect(AddSpecialEffect(Fx, x, y))
    endif
    if ( not(UnpathableStop) or ( KB3D_CW(x, y) ) ) then
        if ( DisableUnit ) then
        else
            call SetUnitX(U, x)
            call SetUnitY(U, y)
        endif
    endif
    ////// Stop All
    if ( (Speed <= 0) or ( Range <= 0 ) or ( GetWidgetLife(U) <= 0 ) ) then
        call SaveBoolean(udg_KB3D_HA, 17, Loop, false)
        call KB3D_Deindex(Loop)
        set udg_KB3D_Instances = udg_KB3D_Instances - 1
        call SaveReal(udg_KB3D_HA, 0, -1 * GetHandleId(U), LoadReal(udg_KB3D_HA, 0, -1 * GetHandleId(U))-1)
        if ( GetWidgetLife(U) <= 0 ) then
            call SetUnitFlyHeight(U, GetUnitDefaultFlyHeight(U), (GetUnitFlyHeight(U) - GetUnitDefaultFlyHeight(U)) / 0.25 )
        endif
    endif
    if 
    ////// Save Changes
    call SaveReal(udg_KB3D_HA, 1, Loop, Range)
    call SaveReal(udg_KB3D_HA, 2, Loop, Speed)
    call SaveReal(udg_KB3D_HA, 12, Loop, ZSpeed)
    call SaveReal(udg_KB3D_HA, 14, Loop, ZTot)
    ////// Clear All
    set U = null
    set Target = null
endfunction

function KB3D_Loop_Actions takes nothing returns boolean
    local integer x = 0
    loop
        exitwhen x >= udg_KB3D_Counter
        set x = x + 1
        if ( LoadBoolean(udg_KB3D_HA, 15, x) ) then
            call KB3D_Group_Loop(x)
        endif
    endloop
    if ( udg_KB3D_Instances == 0 ) then
        set udg_KB3D_Counter = 0
        call DisableTrigger(GetTriggeringTrigger())
    endif
    return false
endfunction

//===========================================================================
function InitTrig_KB3D takes nothing returns nothing
    ////////LOOP
    set udg_KB3D_Loop = CreateTrigger(  )
    call TriggerRegisterTimerEvent( udg_KB3D_Loop, 0.031250000, true )
    call TriggerAddCondition( udg_KB3D_Loop, function KB3D_Loop_Actions )
    call DisableTrigger( udg_KB3D_Loop )
    ////////REGISTRATION
    set udg_KB3D_Registration = CreateTrigger(  )
    call TriggerAddCondition( udg_KB3D_Registration, function KB3D_Registration )
    set udg_KB3D_Harvester = CreateUnit(Player(15), 'hpea', 0, 0, 0)
    call ShowUnit(udg_KB3D_Harvester, false)
    call UnitAddAbility(udg_KB3D_Harvester, 'Aloc')
    set udg_KB3D_HA = InitHashtable()
    ////////Check Walkability System by PnF
    set udg_CP_Rect = Rect(0, 0, 128.00, 128.00)
    set udg_CP_Item = CreateItem('wtlg', 0, 0)
    call SetItemVisible( udg_CP_Item, false )
endfunction
 
Level 16
Joined
Jul 31, 2012
Messages
2,217
oh yeah forgot to ask you...
1. found the missing endblock
2. how to disable a unit without using pauseunit ?

Changed it:
JASS:
    if ( not(UnpathableStop) or ( KB3D_CW(x, y) ) ) then
        call SetUnitX(U, x)
        call SetUnitY(U, y)
        if ( DisableUnit ) then
            
        endif
    endif
the void place is to disable the unit
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
JASS:
    if @Hi!@
    ////// Save Changes
    call SaveReal(udg_KB3D_HA, 1, Loop, Range)
    call SaveReal(udg_KB3D_HA, 2, Loop, Speed)
    call SaveReal(udg_KB3D_HA, 12, Loop, ZSpeed)
    call SaveReal(udg_KB3D_HA, 14, Loop, ZTot)
EDIT: Late.
 

Rheiko

Spell Reviewer
Level 26
Joined
Aug 27, 2013
Messages
4,214
but note that setunitpropwindow will only disable unit's movement, it works like ensnare ability
so even that unit's movement is disabled, it's facing is still active
if i'm right maker say something about disabling it's facing
i don't know, maybe i'll check 'em later

Edit: Forgot this is a knockback, so facing won't be a problem then
 
Level 16
Joined
Jul 31, 2012
Messages
2,217
I guess we're out, final Version of the map and scripts are here:

Please, ALL Helpers of the group, TEST it and track problems/bad points, in other words REVIEW/MODERATE it

Dowload

JASS:
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//           Knock-Back 3D  v. 1.0.0.0   [JASS - GUI]                      //
//                                                by JAD aka DotCa         //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//           System Informations:                                          //
//                                                                         //
//  The System is a well performing, ultra-purpose knockback (see uses     //
//  below ) Coded in JASS making it possible for all users to take         //
//  advantage of it, and GUI friendly to use, see Examples in the triggers //
//  above                                                                  //
//               Configurations have default values:                       //
//                                                                         //
//     - KB3D_DestroyTree      == FALSE by defalut                         //
//     - KB3D_DisableUnit      == FALSE by defalut                         //
//     - KB3D_UnpathaableStop  == TRUE by defalut                          //
//                                                                         //
//  The System also uses Always positive values for some configurations    //
//  to not make the knockback go worng, those configurations are:          //
//                                                                         //
//         "KB3D_Range"  -  "KB3D_Speed"  -  "KB3D_ZOffset"                //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//           System Requirements:   Basic WE - (NONE)                      //
//                                                                         //
//  The System uses implemented CheckWalkability System by PurgeandFire    //
//  You "can" remove the initialization trigger of PnF's System since      //
//  it is directly implemented in the System, all will work fine with or   //
//  without removing your Initializer trigger                              //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//           Credits:                                                      //
//                                                                         //
//    *Chobibo for helping in Script Fixes                                 //
//    *Malhorne for helping in main codes and fixes                        //
//    *PurgeandFire for his CheckWalkability System                        //
//    *Nestharus for his GetCollision function                             //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//           How to Import?                                                //
//                                                                         //
//  1. Check that Create Unkown Variables is ticked in your WE Settings    //
//  2. Copy the Paste this Trigger                                         //
//  3. Congratulations, the System is now implemented in your map          //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//           How to Use?                                                   //
//                                                                         //
//  1. There are 3 Examples of use in the KB3D Example Folder              //
//  2. Documentations are there in each of the 3 examples to help you      //
//  3. The KB3D System is an Ultra-Purpose System where you can use it for://
//     -Projectiles, the system supports homming so a projectile is easy   //
//     -Jump, the System's smoothness in the fly is useful for a jump spell//
//     -And of course, a 2D Knock-Back                                     //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//           Bug Reports - Feedbacks                                       //
//                                                                         //
//  * We count on you to report bugs in the system, also telling the source//
//  * Feedbacks about the system are much appreciated                      //
//  * We mostly hope suggestions about enhancements for the System         //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////

function KB3D_AlwaysNeg takes real R returns real
    if R > 0 then
        set R = R * -1
    endif
    return R
endfunction

function KB3D_AlwaysPos takes real R returns real
    if R < 0 then
        set R = R * -1
    endif
    return R
endfunction

function KB3D_RegisterUnitCollision takes unit u, real x, real y, integer i returns real
    local real l = 0
    local real h = 300
    local real m = 150
    local real nm  
    loop
        if (IsUnitInRangeXY(u, x+m, y, 0)) then
            set l = m
        else
            set h = m
        endif
        set nm = (l+h)/2
        exitwhen nm+.001 >  m and nm-.001 < m
        set m = nm
    endloop
    set m = R2I(m*10)/10.
    call SaveReal( udg_KB3D_HA, 16, GetUnitTypeId(u), m )
    return m
endfunction

function KB3D_GetUnitCollision takes unit u returns real
    local integer i = GetUnitTypeId(u)
    if HaveSavedReal( udg_KB3D_HA, 16, i) then
        return LoadReal(udg_KB3D_HA, 16, i)
    endif
    return KB3D_RegisterUnitCollision(u, GetUnitX(u), GetUnitY(u), i)
endfunction

function KB3D_Registration takes nothing returns boolean
    local real Time
    local real R
    local real R1
    set udg_KB3D_Range = KB3D_AlwaysPos(udg_KB3D_Range)
    set udg_KB3D_Speed = KB3D_AlwaysPos(udg_KB3D_Speed)
    set udg_KB3D_Counter = udg_KB3D_Counter + 1
    set udg_KB3D_Instances = udg_KB3D_Instances + 1
    set udg_KB3D_Zoffset = 2 * KB3D_AlwaysPos(udg_KB3D_Zoffset)
    call SaveUnitHandle( udg_KB3D_HA, 0, udg_KB3D_Counter, udg_KB3D_Unit )
    call SaveReal( udg_KB3D_HA, 1, udg_KB3D_Counter, udg_KB3D_Range )
    call SaveReal( udg_KB3D_HA, 2, udg_KB3D_Counter, udg_KB3D_Speed )
    call SaveReal( udg_KB3D_HA, 4, udg_KB3D_Counter, udg_KB3D_Accel )
    if ( udg_KB3D_Targeted_Unit == null ) then
        call SaveReal( udg_KB3D_HA, 5, udg_KB3D_Counter, udg_KB3D_Angle * 3.14159 / 180 )
    else
        call SaveUnitHandle( udg_KB3D_HA, 5, udg_KB3D_Counter, udg_KB3D_Targeted_Unit )
    endif
    call SaveBoolean( udg_KB3D_HA, 6, udg_KB3D_Counter, udg_KB3D_DisableUnit )
    call SaveBoolean( udg_KB3D_HA, 7, udg_KB3D_Counter, udg_KB3D_UnpathableStop )
    call SaveBoolean( udg_KB3D_HA, 8, udg_KB3D_Counter, udg_KB3D_DestroyTree )
    call SaveStr( udg_KB3D_HA, 9, udg_KB3D_Counter, udg_KB3D_Fx )
    call SaveStr( udg_KB3D_HA, 10, udg_KB3D_Counter, udg_KB3D_Fx_Attach )
    if ( udg_KB3D_Accel == 0.00 ) then
        set Time = udg_KB3D_Range / udg_KB3D_Speed
    else
        if ( udg_KB3D_Accel > 0 ) then
            set Time = (( -2*udg_KB3D_Speed + SquareRoot((4*udg_KB3D_Speed) + (8*udg_KB3D_Accel*udg_KB3D_Range) ) ) / (2*udg_KB3D_Accel) )
        endif
        if ( udg_KB3D_Accel < 0 ) then
            set R = ( - 1 * udg_KB3D_Speed / udg_KB3D_Accel )
            set R1 = (0.5 * udg_KB3D_Accel * R * R) + (udg_KB3D_Speed * R)
            if R1 < udg_KB3D_Range then
                set Time = R
            else
                set Time = KB3D_AlwaysPos(( -2*udg_KB3D_Speed + SquareRoot(KB3D_AlwaysPos((4*udg_KB3D_Speed*udg_KB3D_Speed) + (8*udg_KB3D_Accel*udg_KB3D_Range) )) ) / (2*udg_KB3D_Accel) )
            endif
        endif
    endif
    call SaveReal( udg_KB3D_HA, 11, udg_KB3D_Counter, Time )
    call SaveBoolean( udg_KB3D_HA, 15, udg_KB3D_Counter, true )
    if UnitAddAbility(udg_KB3D_Unit, 'Amrf') then
        call UnitRemoveAbility(udg_KB3D_Unit, 'Amrf')
    endif
    if ( udg_KB3D_Counter == 1 ) then
        call EnableTrigger(udg_KB3D_Loop)
    endif
    call SaveReal( udg_KB3D_HA, 3, udg_KB3D_Counter, udg_KB3D_Zoffset )
    call SaveReal( udg_KB3D_HA, 12, udg_KB3D_Counter, udg_KB3D_Zoffset / ( Time / 2) )
    call SaveReal( udg_KB3D_HA, 13, udg_KB3D_Counter, KB3D_AlwaysNeg(( -1 * udg_KB3D_Zoffset / ( Time / 2) ) / ( Time / 2)) )
    //Nulling
    set udg_KB3D_Accel = 0.00
    set udg_KB3D_Angle = 0.00
    set udg_KB3D_DestroyTree = false
    set udg_KB3D_DisableUnit = false
    set udg_KB3D_Fx = ""
    set udg_KB3D_Range = 0.00
    set udg_KB3D_Speed = 0.00
    set udg_KB3D_Targeted_Unit = null
    set udg_KB3D_Unit = null
    set udg_KB3D_UnpathableStop = true
    set udg_KB3D_Zoffset = 0.00
    return false
endfunction

function KB3D_Tree_Check takes destructable D returns boolean
    local boolean B = false
    call IssueTargetOrder( udg_KB3D_Harvester, "harvest", D )
    if ( GetUnitCurrentOrder(udg_KB3D_Harvester) == OrderId("harvest") ) then
        set B = true
    endif
    call IssueImmediateOrder(udg_KB3D_Harvester, "stop")
    return B
endfunction

function KB3D_KillifTree takes destructable D returns nothing
    if ( KB3D_Tree_Check(D) ) then
        call KillDestructable(D)
    endif
endfunction

function KB3D_KillEnumDest takes nothing returns nothing
    call KB3D_KillifTree(GetEnumDestructable())
endfunction

function KB3D_CircleTreeKill takes real radius, real x, real y returns nothing
    local rect r
    set r = Rect(x-radius, y-radius, x+radius, y+radius)
    call EnumDestructablesInRect(r, null, function KB3D_KillEnumDest)
    call RemoveRect(r)
    set r = null
endfunction

function KB3D_CW_Loop takes nothing returns nothing
    if IsItemVisible(GetEnumItem()) then
        set udg_CP_HiddenItems[udg_CP_HiddenItemsIndex] = GetEnumItem()
        call SetItemVisible(udg_CP_HiddenItems[udg_CP_HiddenItemsIndex], false)
        set udg_CP_HiddenItemsIndex = ( udg_CP_HiddenItemsIndex + 1 )
    endif
endfunction

function KB3D_CW takes real x, real y returns boolean
    local real x2 = 0
    local real y2 = 0
    call MoveRectTo(udg_CP_Rect, x, y)
    call EnumItemsInRect(udg_CP_Rect, null, function KB3D_CW_Loop )
    call SetItemPosition(udg_CP_Item, x, y)
    set x2 = GetItemX(udg_CP_Item)
    set y2 = GetItemY(udg_CP_Item)
    call SetItemVisible(udg_CP_Item, false)
    loop
        exitwhen udg_CP_HiddenItemsIndex <= 0
        set udg_CP_HiddenItemsIndex = udg_CP_HiddenItemsIndex - 1
        call SetItemVisible(udg_CP_HiddenItems[udg_CP_HiddenItemsIndex], true)
        set udg_CP_HiddenItems[udg_CP_HiddenItemsIndex] = null
    endloop
    set udg_CP_PointIsWalkable = ((x2-x)*(x2-x) + (y2-y)*(y2-y) <= 100) and (not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY))
    return udg_CP_PointIsWalkable
endfunction

function KB3D_Group_Loop takes integer Loop returns nothing
    local unit U = LoadUnitHandle(udg_KB3D_HA, 0, Loop)
    local real X = GetUnitX(U)
    local real Y = GetUnitY(U)
    local real Z = GetUnitFlyHeight(U)
    local real x
    local real y
    local real z
    local real Range = LoadReal(udg_KB3D_HA, 1, Loop)
    local real Speed = LoadReal(udg_KB3D_HA, 2, Loop)
    local real Zoffset = LoadReal(udg_KB3D_HA, 3, Loop)
    local real Accel = LoadReal(udg_KB3D_HA, 4, Loop)
    local real Angle
    local real ZSpeed = LoadReal(udg_KB3D_HA, 12, Loop)
    local real ZAccel = LoadReal(udg_KB3D_HA, 13, Loop)
    local real ZTot = LoadReal(udg_KB3D_HA, 14, Loop)
    local unit Target = LoadUnitHandle(udg_KB3D_HA, 5, Loop)
    local boolean DisableUnit = LoadBoolean(udg_KB3D_HA, 6, Loop)
    local boolean UnpathableStop = LoadBoolean(udg_KB3D_HA, 7, Loop)
    local boolean DestroyTree = LoadBoolean(udg_KB3D_HA, 8, Loop)
    local string Fx = LoadStr(udg_KB3D_HA, 9, Loop)
    local string Attach = LoadStr(udg_KB3D_HA, 10, Loop)
    if ( Target == null ) then
        set Angle = LoadReal(udg_KB3D_HA, 5, Loop)
    else
        set Angle = Atan2(GetUnitY(Target) - Y, GetUnitX(Target) - X)
    endif
    set Speed = Speed + ( 0.031250000 * Accel )
    set Range = Range - ( Speed * 0.031250000 )
    set ZSpeed = ZSpeed + ( 0.031250000 * ZAccel )
    set x = X + ( Speed * 0.031250000 * Cos(Angle) )
    set y = Y + ( Speed * 0.031250000 * Sin(Angle) )
    set z = Z + ( ZSpeed * 0.031250000 )
    set ZTot = ZTot + ( ZSpeed * 0.031250000 )
    if (DestroyTree) then
        call KB3D_CircleTreeKill( 4 * KB3D_GetUnitCollision(U), x, y )
    endif
    call SetUnitFlyHeight(U, z, 9999)
    if ( z > 0 ) then
        call DestroyEffect(AddSpecialEffectTarget(Fx, U, Attach))
    else
        call DestroyEffect(AddSpecialEffect(Fx, x, y))
    endif
    if ( not(UnpathableStop) or ( KB3D_CW(x, y) ) ) then
        call SetUnitX(U, x)
        call SetUnitY(U, y)
    endif
    if ( DisableUnit ) then
        call SetUnitPropWindow(U, 0)
        call SetUnitTurnSpeed(U, 0)
        
    endif
    ////// Stop All
    if ( (Speed <= 0) or ( Range <= 0 ) or ( GetWidgetLife(U) <= 0 ) ) then
        call SaveBoolean(udg_KB3D_HA, 15, Loop, false)
        set udg_KB3D_Instances = udg_KB3D_Instances - 1
        call SaveReal(udg_KB3D_HA, 0, -1 * GetHandleId(U), LoadReal(udg_KB3D_HA, 0, -1 * GetHandleId(U))-1)
        if ( GetWidgetLife(U) <= 0 ) then
            call SetUnitFlyHeight(U, GetUnitDefaultFlyHeight(U), 750 )
        endif
        if DisableUnit then
            call SetUnitPropWindow(U, GetUnitDefaultPropWindow(U))
            call SetUnitTurnSpeed(U, GetUnitDefaultTurnSpeed(U))
        endif
    else
        call SaveReal(udg_KB3D_HA, 1, Loop, Range)
        call SaveReal(udg_KB3D_HA, 2, Loop, Speed)
        call SaveReal(udg_KB3D_HA, 12, Loop, ZSpeed)
        call SaveReal(udg_KB3D_HA, 14, Loop, ZTot)
    endif
    ////// Save Changes
    call SaveReal(udg_KB3D_HA, 1, Loop, Range)
    call SaveReal(udg_KB3D_HA, 2, Loop, Speed)
    call SaveReal(udg_KB3D_HA, 12, Loop, ZSpeed)
    call SaveReal(udg_KB3D_HA, 14, Loop, ZTot)
    ////// Clear
    set U = null
    set Target = null
endfunction

function KB3D_Loop_Actions takes nothing returns boolean
    local integer x = 0
    loop
        exitwhen x >= udg_KB3D_Counter
        set x = x + 1
        if ( LoadBoolean(udg_KB3D_HA, 15, x) ) then
            call KB3D_Group_Loop(x)
        endif
    endloop
    if ( udg_KB3D_Instances == 0 ) then
        set udg_KB3D_Counter = 0
        call DisableTrigger(GetTriggeringTrigger())
    endif
    return false
endfunction

//===========================================================================
function InitTrig_KB3D takes nothing returns nothing
    ////////LOOP
    set udg_KB3D_Loop = CreateTrigger(  )
    call TriggerRegisterTimerEvent( udg_KB3D_Loop, 0.031250000, true )
    call TriggerAddCondition( udg_KB3D_Loop, function KB3D_Loop_Actions )
    call DisableTrigger( udg_KB3D_Loop )
    ////////REGISTRATION
    set udg_KB3D_Registration = CreateTrigger(  )
    call TriggerAddCondition( udg_KB3D_Registration, function KB3D_Registration )
    set udg_KB3D_Harvester = CreateUnit(Player(15), 'hpea', 0, 0, 0)
    call ShowUnit(udg_KB3D_Harvester, false)
    call UnitAddAbility(udg_KB3D_Harvester, 'Aloc')
    set udg_KB3D_HA = InitHashtable()
    ////////Check Walkability System by PnF
    set udg_CP_Rect = Rect(0, 0, 128.00, 128.00)
    set udg_CP_Item = CreateItem('wtlg', 0, 0)
    call SetItemVisible( udg_CP_Item, false )
endfunction


Gosh I'm so Excited ^^
 
Level 16
Joined
Jul 31, 2012
Messages
2,217
xD, ok, you will be given credits for testings :p

EDIT:
JASS:
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//           Credits:                                                      //
//                                                                         //
//    *Chobibo for helping in Script Fixes                                 //
//    *Malhorne for helping in main codes and fixes                        //
//    *PurgeandFire for his CheckWalkability System                        //
//    *Nestharus for his GetCollision function                             //
//    *Rheiko for Beta Stage Testings                                      //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
 
Status
Not open for further replies.
Top