wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Warcraft III Modding > Developer's Corner > Triggers & Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 04-26-2009, 10:01 AM   #1
wraithseeker
User
 
Join Date: Feb 2009
Posts: 406

wraithseeker is on a distinguished road (17)

Default Stun system not working

Collapse JASS:

library CustomStun uses PUI

    globals
        private constant real       INTERVAL    = 0.3       //Interval of the timer, thus, delta value
        private constant integer    Dummy_Id    = 'n000'    //Dummy ID
        private constant real       Dummy_Dur   = 1.        //Dummy duration
        private constant integer    Bolt_Id     = 'STUN'    //Storm bolt ID
        private constant integer    Buff_Id     = 'BPSE'    //Stun buff ID
        private constant boolean    True_Stack  = false //Complete stack or no
    endglobals
    
private struct stun
    //! runtextmacro PUI()
    real Stunned = 0.
    unit target
    real duration
   private static timer Timer = CreateTimer()
   private static stun array D
   private static integer Count
   private static stun array a
        
    static method create takes unit target returns stun
        local stun d = stun.allocate()
        set d.target = target
        set d.duration = 0.
        if d.Count == 0 then
            call TimerStart(d.Timer,INTERVAL,true,function stun.Periodic)
        endif
        set d.Count = d.Count + 1
        return d
    endmethod
    
    private static method Periodic takes nothing returns nothing
        local integer i = 0
        loop
            exitwhen i >= .Count
            if .a[i].action() then
                set .Count = .Count - 1
                if .Count > 0 then
                    set .D[i] = .D[.Count]
                    set i = i - 1
                else
                    call PauseTimer(.Timer)
                endif
                endif
            set i = i + 1
            endloop
        endmethod
        
    method action takes nothing returns boolean
        if .duration >= .Stunned or GetWidgetLife(.target) < 0.405 then
            call .release()
            return true
        endif
        set .duration = .duration + INTERVAL
        return false
    endmethod
    
    private method onDestroy takes nothing returns nothing
        set .Stunned = 0 //Reset duration
        call UnitRemoveAbility(.target, Buff_Id ) 
        call BJDebugMsg("STOP")//Remove buff, stopping stun
    endmethod
endstruct
    
function StunUnit takes unit target, unit source, real duration returns nothing
    local stun d
    local unit dummy = CreateUnit(GetOwningPlayer(source),DUMMY,GetUnitX(target),GetUnitY(target),0)
        call BJDebugMsg("RAN")
    set d = stun[target]
    if d.Stunned == 0. then  //Checking if there is already a timer running for that unit
        if True_Stack then
            set d.Stunned = d.Stunned + duration  //Stacking duration
        elseif duration > d.Stunned then
            set d.Stunned = d.duration  //War3 way of stacking
        endif
    call UnitAddAbility( dummy,Bolt_Id )
    call IssueTargetOrder(dummy, "thunderbolt", target )
   // call UnitApplyTimedLife(dummy, 'BTLF',1)
    set d = stun.create(target)
    set stun[target] = d
    endif
        set dummy = null
    endfunction

endlibrary

Initially it was made by Joker[Div] but I saw how unefficient it was so I decided to rewrite it completely from scratch.

Right now the problem is that the stun gets applied but the stun stays there forever. I debugged it and found that the destroy method never ran at all.

Sorry if the method syntax I used were abit un...readable..
wraithseeker is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 04-26-2009, 10:13 AM   #2
ToukoAozaki
extends net.wc3c.Jasser
 
Join Date: Jun 2008
Posts: 336

Submissions (5)

ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)

Send a message via MSN to ToukoAozaki
Default

Well, I can't find any .destroy() calls from your code.
Edit: I think I should take a look at PUI.

Last edited by ToukoAozaki : 04-26-2009 at 10:16 AM.
ToukoAozaki is offline   Reply With Quote
Old 04-26-2009, 10:18 AM   #3
wraithseeker
User
 
Join Date: Feb 2009
Posts: 406

wraithseeker is on a distinguished road (17)

Default

PUI removes the need to do d.destroy but makes us use .release on a PUI struct for some whatever reasons in the system it gave.


Here's a updated code.

Collapse JASS:
library CustomStun uses PUI

    globals
        private constant real       INTERVAL    = 0.3       //Interval of the timer, thus, delta value
        private constant integer    Dummy_Id    = 'n000'    //Dummy ID
        private constant real       Dummy_Dur   = 1.        //Dummy duration
        private constant integer    Bolt_Id     = 'STUN'    //Storm bolt ID
        private constant integer    Buff_Id     = 'BPSE'    //Stun buff ID
        private constant boolean    True_Stack  = false //Complete stack or no
    endglobals
    
private struct stun
    //! runtextmacro PUI()
    real Stunned = 0.
    unit target
    real duration
   private static timer Timer = CreateTimer()
   private static stun array D
   private static integer Count
        
    static method create takes unit target returns stun
        local stun d = stun.allocate()
        set d.target = target
        set d.duration = 0.
        if d.Count == 0 then
            call TimerStart(d.Timer,INTERVAL,true,function stun.Periodic)
        endif
        set d.Count = d.Count + 1
        return d
    endmethod
    
    private static method Periodic takes nothing returns nothing
        local integer i = 0
        loop
            exitwhen i >= .Count
            if .D[i].action() then
                set .Count = .Count - 1
                if .Count > 0 then
                    set .D[i] = .D[.Count]
                    set i = i - 1
                else
                    call PauseTimer(.Timer)
                endif
                endif
            set i = i + 1
            endloop
        endmethod
        
    method action takes nothing returns boolean
        if .duration >= .Stunned or GetWidgetLife(.target) < 0.405 then
            call .release()
            return true
        endif
        set .duration = .duration + INTERVAL
        return false
    endmethod
    
    method onDestroy takes nothing returns nothing
        set .Stunned = 0 //Reset duration
        call UnitRemoveAbility(.target, Buff_Id ) 
        call BJDebugMsg("STOP")//Remove buff, stopping stun
    endmethod
endstruct
    
function StunUnit takes unit target, unit source, real duration returns nothing
    local stun d
    local unit dummy = CreateUnit(GetOwningPlayer(source),DUMMY,GetUnitX(target),GetUnitY(target),0)
        call BJDebugMsg("RAN")
    set d = stun[target]
    if d == 0. then  //Checking if there is already a timer running for that unit
        if True_Stack then
            set d.Stunned = d.Stunned + duration  //Stacking duration
        elseif duration > d.Stunned then
            set d.Stunned = d.duration  //War3 way of stacking
        endif
    call UnitAddAbility( dummy,Bolt_Id )
    call IssueTargetOrder(dummy, "thunderbolt", target )
   // call UnitApplyTimedLife(dummy, 'BTLF',1)
    set d = stun.create(target)
    set stun[target] = d
    endif
        set dummy = null
    endfunction

endlibrary
wraithseeker is offline   Reply With Quote
Old 04-26-2009, 10:38 AM
Litany
This message has been deleted by Litany.
Old 04-26-2009, 10:39 AM   #4
wraithseeker
User
 
Join Date: Feb 2009
Posts: 406

wraithseeker is on a distinguished road (17)

Default

SOLVED THE DEVILISH CODE! *takes a cold drink to cool myself*

Last edited by wraithseeker : 04-26-2009 at 02:29 PM.
wraithseeker is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 04:52 PM.


Donate

Affiliates
The Hubb http://bylur.com - Warcraft, StarCraft, Diablo and DotA Blog & Forums The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2014, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services