|
 |   |  |  |
Submissions Submit JASS resources! If approved, they will be moved to their proper section. Please read me first. |
 |
|
08-20-2008, 01:56 AM
|
#1 (permalink)
|
User
Join Date: Jan 2007
Posts: 59
|
Simple Stun System
Simple Stun System v1.02b
Pros:
1) Allow to stun for any amount of secs
2) Consists of 49 lines
3) Timer don't expire every 0.01 sec but as u ordered which have to make it fast & furious
3) It is the simpliest system I've ever seen:)
Cons:
It's not tested a lot )
So if u find any bug post it I'll fix it!
*******************
** How to implant:**
*******************
The system is very easy. The only things you'll have to do to implement the system is to:
1) copy the SimpleStunSystem trigger into ur map
2) copy dammy Unit (if u haven't it yet)
3) copy Ability & Buff "Simple Stun"
4) Change the buff of the ability to the buff "Simple Stun"
5) Change the variables in the system DummyId; AbilId; BuffId
Note: Requires vJass
*******************
** How to use: ******
*******************
To use this system u have to have a trigger with the event unit pick up item and in the actions
just write:
function StunUnit takes unit whichunit,real duration, boolean CheckImmunity returns boolean
Arguments:
unit whichunit - Unit that must be stunned //I think it is clear
real duration - duration of the stun
boolean CheckImmunity - whether to chec kmagic immune units or not
returns boolean - returns whether it stuned the unit or not
//***************************************************************//* Simple Stun System v1.02//* -------------------by Matrix---------------------------------//* Latest version on [url]http://www.thehelper.net[/url] forums//* Function Index//*//* StunUnit(unit whichunit, real duration, boolean CheckImmunity)//*//* unit whichunit - the unit that will be stunned//* real duration - the duration of the stun//* boolean CheckImmunity means it checks if the unit is immune, a building or mechanical in which case it does not stun.//NOTE - The smallest possiable stun duration is 0.01 due to limitations with the system and so it will stun for 0.01 seconds even if u pass duration less than 0.01 but bigger then zero//NOTE - The system supports stunning the same unit twice with no problems based on the largest stun duration like WC3's stun works normally. In other words if u stun unit for 999 seconds and then for 1 second it will be stunned for 999 secs!//INTERFACES (inside library)//integer Total//The number of units currently stunned by the system.//***************************************************************//=============================================================// How to implant: (Uses Jass NewGen Pack)//1) copy this trigger into ur map//2) copy dummy Unit (if u haven't it yet)//3) copy Ability & Buff "Simple Stun"//4) Change the buff of the ability to the buff "Simple Stun"//5) Change the variables in the system DummyId; AbilId; BuffId (See below:)//=============================================================//***************************************************************//**ChangeLog v1.02//1) Now Double stun on the same unit works properly//2) Now Calling function with negative amount of sec will do nothing//3) Now calling function with less amount of sec than 0.01 will set//it to 0.01//4) A little bit optimization//=============================================================library SimpleStunSystem globals//Set this to the raw data value of the dummy unit that must be used by this system.private constant integer ID_DUMMY = 'h000'//Set this to the raw data value of the dummy stun ability that must be used by this system.private constant integer ID_ABILL = 'A000'//Set this to the raw data value of the stun buff that must be used by this system.private constant integer ID_BUFF = 'B000'//Contains the number of units stunned via the system ingame at any point in time.public integer Total=0 //Variables used by the system to store the timer used for stun duration and the unit who is stunned.private timer array T private unit array U endglobalsprivate function End takes nothing returns nothing local integer i = 0 local timer time = GetExpiredTimer () //Finds which unit the timer went with. loop exitwhen time==T [i ] set i = i + 1 endloop //Gets rid of the timer call PauseTimer (time ) call DestroyTimer (time ) set time = null //Unstuns the unit call UnitRemoveAbility (U [i ],ID_BUFF ) //Deallocates the object from the system. set Total=Total-1 set T [i ]=T [Total ] set U [i ]=U [Total ] set T [Total ]= null set U [Total ]= nullendfunctionfunction StunUnit takes unit u, real d, boolean CheckImmunity returns boolean local unit s = null local integer i = 0 //Checks if the duration is long enough for a stun to be correctly applied and if so then checks if it is to check immunity and if so does so before doing stun actions. if (not CheckImmunity or (not IsUnitType (u,UNIT_TYPE_MAGIC_IMMUNE ) and not IsUnitType (u,UNIT_TYPE_MECHANICAL ) and not IsUnitType (u,UNIT_TYPE_STRUCTURE ))) and d>0 then //Loops via a O(n) type loop to check if a unit is already stunned via the system. //If one is it uses that refference if not it then uses a blank reference. if d<.01 then set d =.01 endif loop exitwhen U [i ]==u or i>Total set i = i+1 endloop if i<=Total then if TimerGetRemaining (T [i ])<d then call PauseTimer (T [i ]) call TimerStart (T [i ],d, false, function End ) endif return true endif //Creates a dummy and prepairs it so that it can stun. set s = CreateUnit (GetOwningPlayer (u ),ID_DUMMY,GetWidgetX (u ),GetWidgetY (u ),0 ) call UnitAddAbility (s,ID_ABILL ) call UnitApplyTimedLife (s, 'BTLF', 1 ) if T [Total ]== null then set T [Total ]=CreateTimer () endif set U [Total ]=u //Stuns the unit for infinity call IssueTargetOrderById (s,852095,u ) //Cleans up local objects to null to stop leaks. set s = null set u = null call TimerStart (T [Total ],d, false, function End ) set Total=Total+1 return trueendifset u = nullreturn falseendfunctionendlibrary
Download
Simple Stun System v1.02b
Last edited by Matrix; 08-25-2008 at 08:17 AM..
|
|
|
08-21-2008, 11:04 PM
|
#2 (permalink)
|
Spell and Map Moderator
The Helpful Personage
Join Date: Jan 2005
Posts: 4,261
|
System will bug if you use it to stun the same unit twice.
If you stun a unit for 1 second and then stun it for 10 seconds, the unit will be unstunned after 1 second.
This is due to the lack of a system that checks if a unit has been stunned and if so updates the timer rather than stacking them and bugging.
CheckImmunity!=IsUnitType(u,UNIT_TYPE_MAGIC_IMMUNE)
Why not just
not IsUnitType(u,UNIT_TYPE_MAGIC_IMMUNE)
I am sure that would be faster?
You could also make your system struct based as that is basically what you do.
|
|
|
08-22-2008, 10:49 PM
|
#3 (permalink)
|
User
Join Date: Nov 2007
Posts: 94
|
theres a bug with IsUnitType which occurs when using specific values for the second parameter. This can be avoided by using ==true or ==false.
You dont cleanup s.
set T[Total]=T[i] set U[Total]=U[i] set T[Total]=null set U[Total]=null thats nonsense. First you assing T/U[Total] a value and then clean those up.
local timer tswp // initializing not necessary [...] set tswp=T[i] set Total = Total - 1 set T[i]=T[Total] set U[i]=U[Total] set T[Total]=tswp // no, resetting the unit doesnt matter [...] set tswp=null fix'd. Seriously, this should have caused some bugs, im surprised noone stumble across them already.
And there are the downsides Dr Super Good already mentioned.
EDIT: Oh and would you please start following some conventions? Especially those for naming globals and those for indenting?
Some other Edits: Corrected the script I provided.
Deaod
Last edited by Deaod; 08-23-2008 at 12:24 AM..
|
|
|
08-22-2008, 11:00 PM
|
#4 (permalink)
|
Spell and Map Moderator
The Helpful Personage
Join Date: Jan 2005
Posts: 4,261
|
He probably meant
set Total=Total-1 set T[i]=T[Total] set U[i]=U[Total] set T[Total]=null set U[Total]=null
I recomend a great revision of your code as currently it is unaxceptable.
|
|
|
08-23-2008, 12:21 AM
|
#5 (permalink)
|
User
Join Date: Nov 2007
Posts: 94
|
thats nonsense. You'd want to preserve the timer, instead of pausing and leaking it (not destroyed, but no way you could ever destroy it). Loosing reference to the unit doesnt matter, but loosing reference to a timer is painful for every player of your map.
|
|
|
08-23-2008, 01:05 AM
|
#6 (permalink)
|
Spell and Map Moderator
The Helpful Personage
Join Date: Jan 2005
Posts: 4,261
|
Did not notice he did not destroy it LOL. I was purly showing the structure of how that is normally done (like how structs do it in vJASS). Really this is just a joke.
|
|
|
08-23-2008, 09:51 PM
|
#7 (permalink)
|
User
Join Date: Jan 2007
Posts: 59
|
|
|
|
08-23-2008, 10:11 PM
|
#8 (permalink)
|
Spell and Map Moderator
The Helpful Personage
Join Date: Jan 2005
Posts: 4,261
|
It looks the same, nothing has been fixed.
|
|
|
08-23-2008, 10:42 PM
|
#9 (permalink)
|
User
Join Date: Jan 2007
Posts: 59
|
now? I just upload map and forgot to change code in thread
|
|
|
08-24-2008, 02:21 AM
|
#10 (permalink)
|
User
Join Date: Nov 2007
Posts: 94
|
1.) You still leak Timers (worst).
2.) You still dont cleanup s (pretty bad).
3.) Stacking stuns still impossible (thats a feature; its up to you if you implement it).
4.) You create a unit even when not necessary (performance problem; minor one).
5.) Your algorithm to clean U and T is broken (and thats really bad).
6.) You dont indent properly.
7.) Its common to name global constants UPPER_CASE, and Capitalize non constant globals.
|
|
|
08-24-2008, 03:09 AM
|
#11 (permalink)
|
User
Join Date: Jan 2007
Posts: 59
|
1) ???
2) ???
3) I did as in blizzard stun; it's also don't stack (if it does it was imba)
4) How I can without creating? I want a buff to be created ()
5) I don't destroy them on order not to create new
6) I know =)
7) what?
|
|
|
08-24-2008, 03:26 AM
|
#12 (permalink)
|
User
Join Date: Nov 2007
Posts: 94
|
1.) Ok, here we go:
Here is a tutorial introducing to leaks in general.
You are leaking a Timer because you may loose all references to a timer object (no variable holds a pointer to the object in the memory), yet you didnt destroy it. And because you dont have any reference to that object you cant ever destroy it in the future. Leaking one timer isnt that horrible, but within a system like this you can possibly leak hundreds of them, making the map using this system unplayable.
2.) Cleaning s means setting it to null (its a local variable of type handle referencing a unit, even after you returned true/false).
4.) cut set s = CreateUnit(GetOwningPlayer(u),DummyId,GetUnitX(u),GetUnitY(u),0) call UnitAddAbility(s,AbilId) call UnitApplyTimedLife(s, 'BTLF', 1.) and insert after if T[Total]==null then set T[Total]=CreateTimer() endif
5.) Look at my first post. Thats the way its done. Did you even bother understanding what my first post was about?
7.) Nevermind.
|
|
|
08-24-2008, 03:50 AM
|
#13 (permalink)
|
Spell and Map Moderator
The Helpful Personage
Join Date: Jan 2005
Posts: 4,261
|
How about a little comparison.
Which system is better, his revision from his old one or my revision from his old one.
library SimpleStunSystem //Simple system used to stun a unit. //The script was based on an old version of Matrix's SimpleStunSystem //Minor changes made by Dr Super Good (80%+ of credit must go to Matrix as he did most of the code) //Notes from Dr Super Good //I fixed up the code so it does not leak. //I also added support to allow a unit to be stunned twice without any problems. //I properly indented the entire script to make it easilly readable. //I fully playtested the system catching minor bugs. //Caught the bug resulting in units not getting stunned if stunned for less than 0.05 seconds (is possiable to go as low as 0.005 some times but 0.05 was the smallest safe number I could find). //Added detailed commenty to the system to make it easier to learn from or use. //FUNCTIONS ADDED (outside library) //function StunUnit takes unit u,real d, boolean CheckImmunity returns boolean //u = which unit to stun //d = stun duration (how long). //CheckImmunity means it checks if the unit is immune, a building or mechanical in which case it does not stun. //NOTE - The smallest possiable stun duration is 0.05 due to limitations with the system and so it will not stun for durations smaller than that. //NOTE - The system supports stunning the same unit twice with no problems but the strun will expire based on the last stun and any past stun duration are ignored like WC3's stun works normally. //INTERFACES (inside library) //integer Total //The number of units currently stunned by the system. globals //Set this to the raw data value of the dummy unit that must be used by this system. private constant integer ID_DUMMY = 'h000' //Set this to the raw data value of the dummy stun ability that must be used by this system. private constant integer ID_ABILL = 'A000' //Set this to the raw data value of the stun buff that must be used by this system. private constant integer ID_BUFF = 'B000' //Contains the number of units stunned via the system ingame at any point in time. public integer Total=0 //Variables used by the system to store the timer used for stun duration and the unit who is stunned. private timer array T private unit array U endglobals private function End takes nothing returns nothing local integer i=0 local timer time = GetExpiredTimer () //Finds which unit the timer went with. loop exitwhen time==T [i ] set i = i + 1 endloop //Gets rid of the timer call PauseTimer (time ) call DestroyTimer (time ) set time = null //Unstuns the unit call UnitRemoveAbility (U [i ],ID_BUFF ) //Deallocates the object from the system. set Total=Total-1 set T [i ]=T [Total ] set U [i ]=U [Total ] set T [Total ]= null set U [Total ]= null endfunction function StunUnit takes unit u, real d, boolean CheckImmunity returns boolean local integer i=0 local unit s //Checks if the duration is long enough for a stun to be correctly applied and if so then checks if it is to check immunity and if so does so before doing stun actions. if d>=0.05 and (not CheckImmunity or (not IsUnitType (u,UNIT_TYPE_MAGIC_IMMUNE ) and not IsUnitType (u,UNIT_TYPE_MECHANICAL ) and not IsUnitType (u,UNIT_TYPE_STRUCTURE ))) then //Loops via a O(n) type loop to check if a unit is already stunned via the system. //If one is it uses that refference if not it then uses a blank reference. loop exitwhen u==U [i ] or i==Total set i = i + 1 endloop //Creates a dummy and prepairs it so that it can stun. set s = CreateUnit (GetOwningPlayer (u ),ID_DUMMY,GetWidgetX (u ),GetWidgetY (u ),0 ) call UnitAddAbility (s,ID_ABILL ) call UnitApplyTimedLife (s, 'BTLF', 1 ) //Checks if it found that unit already stunned, and if not it then adds it to the system. if U [i ]== null then set T [Total ]=CreateTimer () set U [Total ]=u set Total=Total+1 endif //Stuns the unit for infinity call IssueTargetOrderById (s,852095,u ) //Cleans up local objects to null to stop leaks. set s = null set u = null //Starts the timer to expire when the stun must end. //This is done in such a way it overwrides any previous stunning for that unit like W3C normally does. call TimerStart (T [i ],d, false, function End ) return true endif //Local leak prevention. set u = null return false endfunctionendlibrary
The above was based on his 1.01 sytem code and not his newest one.
I did not make most of the code, I purly improved appon it and am thus not entitaled to much of the credits for the above.
This addressed most of the problems people were complaining about I hope.
|
|
|
08-24-2008, 04:56 AM
|
#14 (permalink)
|
User
Join Date: Jan 2007
Posts: 59
|
nice1 but in my 1.02 if second stun is smaller then first it won't override first look up at the code, u can add it
|
|
|
08-24-2008, 05:55 AM
|
#15 (permalink)
|
User
Join Date: Jan 2007
Posts: 59
|
Im going to make 1.03 so can I use ur code? :D
|
|
|
| Thread Tools |
|
|
| Display Modes |
|
| |
|
|