Is this script MUI?

Tukki

is Skeleton Pirate.
Reaction score
29
Just a question, here
JASS:
        set d.speed = Startspeed

if the input is like 600 (normal speed) then it won't work (Speed * Interval for correct) and I think the same applies to Deceleration.

The error should not appear when you use ">=" but it will when you only use ">" as there is no struct for Total + 1.
Also you should check your input values if they are appropriate, in your function from which you call KBS_Begin.

EDIT: I'm off. GL.
 

Kenny

Back for now.
Reaction score
202
if the input is like 600 (normal speed) then it won't work (Speed * Interval for correct) and I think the same applies to Deceleration.

I have like a description above the library. It kinda says that to use this library you use small numbers, like 20.00 startspeed with a 0.25 deceleration. Giving it like 600 startspeed would make it go beserk.

The error should not appear when you use ">=" but it will when you only use ">" as there is no struct for Total + 1.

Yeah thats wot happens. But with the >= the error message doesnt appear, but the unit doesnt move and the special effect is added but never destroyed.

Oh and i checked the spell in which i use it, everything is fine.

PS: I just found Dusk's knockback system at wc3campaigns.net. And i saw something that upset me. He hada function in which units that collide with the already moving unit would start getting knockbacked too. Which is weird because only a few hours ago i was talking with my little bro about ways to make mine "look" different to his, and he suggested that exact same idea. So now thats one idea down the drain.

But i gotta get this working first.

*EDIT*

Okay i got it working, after a lengthy night, but im back on track. However i seem to be leaking handles, but i can't see where. Can anyone help?

Current script:

JASS:
library KBS initializer Init

globals
    // CONFIGURABLES:
    private constant integer Dummy_id = 'u000'           // This is the dummy unit.
    private constant real Period = 0.04                  // Recommended Interval.
    private constant real Radius = 150.00                // Radius for killing trees.
    private constant string Attachment_point = "origin"  // Attachment point for effects.
    private constant string Water_SFX = "SlideWater.mdx" // Water slide effect.
    private constant string Dirt_SFX = "Dust.mdx"        // Ground slide effect.
endglobals

//***************************************************************************************
//**                                                                                   ** 
//**          DO NOT TOUCH BELOW HERE UNLESS YOU KNOW WHAT YOUR ARE DOING!             **
//**                                                                                   **
//***************************************************************************************     

private keyword Data

globals
    private integer Total = 0
    private Data array DataArray
    private real Game_maxX = 0.00
    private real Game_minX = 0.00
    private real Game_maxY = 0.00
    private real Game_minY = 0.00
    private rect Rect1 = null
    private timer Timer = null
    private boolexpr Treefilt = null
endglobals

private function KillEnumDestructables takes nothing returns nothing
    call KillDestructable(GetEnumDestructable())
endfunction

// Thanks to PitzerMike for this function.
private function TreeCheck takes nothing returns boolean
    local destructable dest = GetFilterDestructable()
    local boolean bool = IsDestructableInvulnerable(dest)
    local unit dummy = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),Dummy_id,GetDestructableX(dest),GetDestructableY(dest),0.00)
    local boolean result = false

    call UnitAddAbility(dummy,'Ahrl')
    if bool then
        call SetDestructableInvulnerable(dest,false)
    endif
    set result = IssueTargetOrder(dummy,"harvest",dest)
    call RemoveUnit(dummy)
    if bool then
        call SetDestructableInvulnerable(dest,true)
    endif

    set dest = null
    set dummy = null
    return result
endfunction

private function IsPointOutside takes real x, real y returns boolean
    return (x > Game_maxX or y > Game_maxY or x < Game_minX or y < Game_minY)
endfunction

private struct Data
    unit targ
    
    real speed
    real decrease
    real sin
    real cos
    
    effect SFX
    integer sfxmode
    boolean killdest
    
    static method TerrainType takes unit u, string sfx returns integer
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        
        if sfx != "" and sfx != null then
            return 0
        elseif IsTerrainPathable(x,y,PATHING_TYPE_FLOATABILITY) then
            return 1
        elseif not IsTerrainPathable(x,y,PATHING_TYPE_WALKABILITY) then
            return 2
        endif
        
        return 3
    endmethod
    
    static method create takes unit Target, real Startspeed, real Deceleration, real Angle, string Specialeffect, boolean Killtrees returns Data
        local Data d 
        
        if Target == null or Startspeed <= 0.00 or Deceleration <= 0.00 then
            call BJDebugMsg("Error: Invalid input in KBS_Begin")
            return 0
        endif
        
        set d = Data.allocate()
        set d.targ = Target
        set d.speed = Startspeed
        set d.decrease = Deceleration
        set d.sin = Sin(Angle)
        set d.cos = Cos(Angle)
        set d.killdest = Killtrees
        set d.sfxmode = d.TerrainType(d.targ,Specialeffect)
        
        if d.sfxmode == 0 then
            set d.SFX = AddSpecialEffectTarget(Specialeffect,d.targ,Attachment_point)
        elseif d.sfxmode == 1 then
            set d.SFX = AddSpecialEffectTarget(Dirt_SFX,d.targ,Attachment_point)
        elseif d.sfxmode == 2 then
            set d.SFX = AddSpecialEffectTarget(Water_SFX,d.targ,Attachment_point)
        endif
        
        set Total = Total + 1
        if Total == 1 then
            call TimerStart(Timer,Period,true,function Data.Execute) 
        endif
        
        set DataArray[Total] = d
        
        return d
    endmethod
    
    static method Execute takes nothing returns nothing
        local integer i = 1
        local Data d
        local real x
        local real y
        local real newx
        local real newy
        
        loop
            exitwhen i > Total
            set d = DataArray<i>
            
            set x = GetUnitX(d.targ)
            set y = GetUnitY(d.targ)
            
            if d.speed &lt;= 0 or IsPointOutside(x,y) then
                call d.destroy() 
                set DataArray<i> = DataArray[Total]
                set Total = Total - 1
            else
                set newx = x+d.speed*d.cos
                set newy = y+d.speed*d.sin
                call SetUnitPosition(d.targ,newx,newy) 
                
                if d.killdest then
                    call SetRect(Rect1,x-Radius,y-Radius,x+Radius,y+Radius)
                    call EnumDestructablesInRect(Rect1,Treefilt,function KillEnumDestructables)
                endif
                
                if d.sfxmode == 0 then
                    set d.sfxmode = d.TerrainType(d.targ,&quot;sfx&quot;)
                else
                    set d.sfxmode = d.TerrainType(d.targ,&quot;&quot;)
                endif
                
                if d.sfxmode == 1 then
                    call DestroyEffect(d.SFX)
                    set d.SFX = AddSpecialEffectTarget(Dirt_SFX,d.targ,Attachment_point)
                    set d.sfxmode = 2
                elseif d.sfxmode == 2 then
                    call DestroyEffect(d.SFX)
                    set d.SFX = AddSpecialEffectTarget(Water_SFX,d.targ,Attachment_point)
                    set d.sfxmode = 1
                endif
                
                set d.speed = d.speed - d.decrease
            endif
            
            set i = i + 1
        endloop
        if Total &lt;= 0 then
            call PauseTimer(Timer)
            set Total = 0
        endif
    endmethod
    
    private method onDestroy takes nothing returns nothing
        set .targ = null
        call DestroyEffect(.SFX)
        set .SFX = null
    endmethod
endstruct

public function BeginEx takes unit Target, real Startspeed, real Deceleration, real Angle, string SpecialEffect, boolean Killtrees returns nothing
    call Data.create(Target,Startspeed,Deceleration,(Angle*0.01745328),SpecialEffect,Killtrees)
endfunction

public function Begin takes unit Target, real Startspeed, real Deceleration, real Angle, boolean Killtrees returns nothing    
    call BeginEx(Target,Startspeed,Deceleration,Angle,&quot;&quot;,Killtrees)
endfunction                                                                                                

private function Init takes nothing returns nothing
    set Timer = CreateTimer()
    set Rect1 = Rect(0.00,0.00,1.00,1.00)
    set Treefilt = Condition(function TreeCheck)
    set Game_maxX = GetRectMaxX(bj_mapInitialPlayableArea)-64.00
    set Game_maxY = GetRectMaxY(bj_mapInitialPlayableArea)-64.00
    set Game_minX = GetRectMinX(bj_mapInitialPlayableArea)+64.00
    set Game_minY = GetRectMinY(bj_mapInitialPlayableArea)+64.00
endfunction

endlibrary</i></i>
 

Kenny

Back for now.
Reaction score
202
BUMP!

Um im in need of some serious helpage. I still cannot see the source of my handle leaks. I think i am going blind from spending too much time trying to find the handle leaks :p.

Anywho, major props for the person that helps me out with this. Im getting desperate, which is not cool.

Check my above post for the current script.
 

Kenny

Back for now.
Reaction score
202
I don't see any either, but when testing the map starts with about 600, then after about 100 seconds of spamming this system on multiple units the handles radically change from 600 - 1500 - 2800 and back and forth for a long time. So i dont know whats going on. Ive tested the handles with another system and they stay at a constant of 600. So somethings wrong.

And i thought i did null the struct members?

JASS:
private method onDestroy takes nothing returns nothing
    set .targ = null
    call DestroyEffect(.SFX)
    set .SFX = null
endmethod


What do i do with boolean? And reals and integers dont need to be nulled do they?
 

Kenny

Back for now.
Reaction score
202
Im stumped :(. I got no idea whats goin on.

If anyone was any ideas, dont hold back.

Im just putting this out there, but is it possible that my problem is my use of structs? Im going to try to convert it to functions later and see if it helps. Right now i need my sleep.
 

Viikuna

No Marlo no game.
Reaction score
265
Ey, Im too lazy to read this code fully trought, sry :( , but what exactly happens if unit that is allready knockback-sliding gets knockbacked again? Do you have some method to find out if unit is allready sliding?

EDIT. Nothing special, I see. I just somehow felt that this might be important.
 

Kenny

Back for now.
Reaction score
202
An already knockbacked unit that gets knockbacked again just gets another instance of the knockback on it. It all works out, its just hard to explain. If a unit gets knocked back in the same direction twice, almost simultaniously, then it will just go further back and faster. If it is in a different direction, i think the last instance to be started for the unit has a stronger effect, but the first will still move it. I dunno how to explain it lol.
 

Viikuna

No Marlo no game.
Reaction score
265
Well, its easier to do it like that, than trying to modify that previous knockback instance. Did you find that handle leak yet?
 

Tukki

is Skeleton Pirate.
Reaction score
29
Back. A suggestion would be that you make the Execute method a function instead, and start the timer in the KBS_Begin(Ex) function after the Data.create call.

EDIT: Since the effect is created, but not destroyed it seems like the Execute method is;

* Not being executed by the timer.
* Having some sort of failure in the struct retrieval thingey.

EDIT 2: (I'm getting tired of editing -.-')

You should consider changing the Speed argument to allow 600 and higher values, same applies to Deceleration. Since if your speed input is like 20 and deceleration 3 you wouldn't notice any movement as the method is executed every 0.03125 second and decreasing Speed by 3.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top