|
|
#1 |
|
User
Join Date: Feb 2009
Posts: 406
|
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.. |
|
|
|
| Sponsored Links - Login to hide this ad! |
|
|
|
|
#2 |
|
extends net.wc3c.Jasser
|
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. |
|
|
|
|
|
#3 |
|
User
Join Date: Feb 2009
Posts: 406
|
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. 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 |
|
|
|
|
|
#4 |
|
User
Join Date: Feb 2009
Posts: 406
|
SOLVED THE DEVILISH CODE! *takes a cold drink to cool myself*
Last edited by wraithseeker : 04-26-2009 at 02:29 PM. |
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
|
|
Donate |