System Simple Stun System

Matrix

New Member
Reaction score
5
Simple Stun System v1.02b
Pros:

1) Allow to stun for any amount of secs
2) 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

JASS:
//***************************************************************
//*                Simple Stun System v1.02
//* -------------------by Matrix---------------------------------
//*           Latest version on <a href="http://www.thehelper.net" class="link link--internal">http://www.thehelper.net</a> 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&#039;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&#039;t it yet)
//3) copy Ability &amp; Buff &quot;Simple Stun&quot;
//4) Change the buff of the ability to the buff &quot;Simple Stun&quot;
//5) Change the variables in the system DummyId; AbilId; BuffId (See below<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile    :)" loading="lazy" data-shortname=":)" />
//=============================================================
//***************************************************************
//**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 = &#039;h000&#039;        
//Set this to the raw data value of the dummy stun ability that must be used by this system.        
private constant integer ID_ABILL = &#039;A000&#039;        
//Set this to the raw data value of the stun buff that must be used by this system.        
private constant integer ID_BUFF  = &#039;B000&#039;        
//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 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&gt;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&lt;.01 then
          set d =.01
       endif
       loop
           exitwhen U<i>==u or i&gt;Total
           set i = i+1
       endloop
       if  i&lt;=Total then
          if TimerGetRemaining(T<i>)&lt;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, &#039;BTLF&#039;, 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 true
endif
set u = null
return false
endfunction
endlibrary</i></i></i></i></i></i></i></i>


Download

Simple Stun System v1.02b
 

Flare

Stops copies me!
Reaction score
662
Can you post the code? And why don't you just attach the map file to your post instead of using download link from elsewhere?

I have a few questions:

I stun a unit for 10 seconds, then stun the same unit for 5 seconds
(a) Will the second stun overwrite the first stun?
(b) If the stuns were reversed (first stun for 5s, second for 10s), does the buff get removed after 5 seconds (since I can't check the code myself at the moment unless you post it)

JASS:
    set Total=Total-1
    loop
        exitwhen i&gt;Total
        set T<i>=T[i+1]
        set U<i>=U[i+1]
        set i = i+1
    endloop
</i></i>


Shouldn't you be doing
JASS:
//this isn&#039;t part of the loop
set T<i> = T[Total]
set U<i>=U[Total]
set Total = Total - 1</i></i>


And, judging by the code, your system will fail for (b) i.e. even though you applied a 10 second stun, the 5 second stun expiration will remove the buff, nullifying your 10 second stun (regardless of whether it was cast before or after the 5sec one) - you need to check if the unit should still be stunned (i.e. a second stun spell affecting the same unit) before removing the buff
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Post the code? Makes it a lot easier to check it out rather than having to download it and look through the editor.

Edit:

1) Is there really any need for 1 timer per instance? Answer would be no.

2) StunUnit() is a useless function since it does nothing but calling the StunUnitEx().

3) Have you tried that recycling of arrays with multiple instances running at the same time at all?

4) What's the purpose of this? Cast a stunning spell (such as storm bolt) and then instead of setting a duration in t he object editor you have to trigger it?

5)

Q: Why did u do this shit?
A: I'm cr8ing an AoS map and I was searching for a simple recipe sytem but I didn't find=(
That's why I decided to cr8 my own =)

What? Oh and please write correct words, no one wants to read something like "Omg I cr8ed thid 4 u guys so u can use in ur map".
 

Flare

Stops copies me!
Reaction score
662
2) StunUnit() is a useless function since it does nothing but calling the StunUnitEx().

StunUnit [del]checks for[/del] ignores immunity, but StunUnitEx has the option of [del]ignoring[/del] checking for it

And you need to fix your documentation
JASS:
//The system requires a global game cache variable
//called &#039;udg_cache&#039; (or just &#039;cache&#039; in the variable
//editor).


There's no udg_ gamecache variable
 

Matrix

New Member
Reaction score
5
yeah i know. I forgot to copy the right version. I have it on my pc.
and it doesnt overrides other stuns Ive tested few times. However tommorrow at the morning I'll test it more times and give u the 1.01 version
 

Tukki

is Skeleton Pirate.
Reaction score
29
Maybe you should consider using structs instead of multiple timers..

like; (Huray for notepad scripting :p)

JASS:
//----------------------------------
// Struct for storing data.
private struct StunData
	unit Target
	real Duration

	static StunData array PUI
	static group Pivot
	static integer counter = 0

	static method create takes unit whichUnit, real whichDuration returns StunData
	 local StunData d

		if (IsUnitInGroup(whichUnit, StunData.Pivot)) then
			debug call BJDebugMsg(SCOPE_PREFIX + &quot;Error: &quot; + GetUnitName(whichUnit) + &quot; is already being stunned!&quot;)
			return 0
		endif

		set d = StunData.allocate()
		set d.Target = whichUnit
		set d.Duration = whichDuration
		
		set StunData.counter = StunData.counter + 1
		set StunData.PUI[StunData.counter] = d
		call GroupAddUnit(whichUnit, StunData.Pivot)
	return d
	endmethod
endstruct

//-----------------------------------------------
// Function for checking if stun duration is over.
private function Periodic takes nothing returns nothing
 local integer iterator = 1
 local StunData d 

	loop
		exitwhen iterator &gt;= StunData.counter
		set d = StunData.PUI[iterator]
		if (d.Duration &lt;= 0) then
			call RemoveAbility(&lt;YourAbility&gt;)
			call d.destroy()
		else
			set d.Duration = d.Duration - &lt;YourTimerInterval&gt;
		//etc..


And run that function every <YourTimerInterval> second.
 

Hatebreeder

So many apples
Reaction score
381
Well...
I am pretty sure, that if you stun 2 times in a row with some ability. there will be some Bug...
Like, Stun for 2 Secs and Stun again after 1.5 Secs, the Stun will only last for 2 Secs?
Thats the only problem I see with this...
Buuuuuuuuuuuuuuuuuuuuuuuuuuuuuut, you can adjust the whole thing by:
Add all units that are effected into a unit Group. then, have a Timer run through the group, and have a real array for each unit in the Group. If a Unit is stunned again, and IsInGroup(..) == true then you increase that ammount.
This way, you can keep track of the Unit, and you only have one timer running at once.

Basically it's the same as Tukki said. Just a bit different =P Shouldn't use PUI or something...
 

Tukki

is Skeleton Pirate.
Reaction score
29
No bug will occur, only that the units stun will not be updated :) BUT as Hatebreeder said ppl will most likely have it the updating-way..so add a global! And let the user decide.

EDIT: Right now (as the system currently are) it will freak out when you use multiple stun on folks :) [Like my would..(duh!!)]
 

Hatebreeder

So many apples
Reaction score
381
May I, like make a new Version of this System? It's pretty Kewl, and proberbly much more usefull than a lvl 100 Stormbolt xD
 

Tukki

is Skeleton Pirate.
Reaction score
29
Well, you musn't have a lvl 100 Stormbolt :) Just make the duration 0 :p. Then remove it when the stun duration is over. I'll post when I get home.
 

Artificial

Without Intelligence
Reaction score
326
JASS:
set T[Total]=T<i>
set U[Total]=U<i>
set Total=Total-1</i></i>
Did you possibly try that out, btw? That kinda like shouldn't work as you probably want it to...

Also this system at the moment seems to have some leaks. First of all, you're not nulling s in StunUnit. And second of all, this is bad:
JASS:
set T[Total]=null
It will cause a new timer to be created, and the old one wasn't destroyed. And you don't need to null globals, anyway.
And btw, is there a reason to pause the timer after it has expired?
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
The way you attach things in the posted code isn't efficient at all.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
You messed up the array recycling totally. I suggest taking a look at Flare's first post and compare that to yours, see if you find something wrong.
 

Matrix

New Member
Reaction score
5
You messed up the array recycling totally. I suggest taking a look at Flare's first post and compare that to yours, see if you find something wrong.

I thought that moving 1 unit & timer will take less time that moving all stuff down. I mean if u have 100 issues and 3 is expired if I use loop it will makes 97 objects down a stage. And in my method it only makes the last to 3rd.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
JASS:
    set T[Total]=T<i>
    set U[Total]=U</i>


Should be
JASS:
    set T<i>=T[Total]
    set U<i>=U[Total]</i></i>


You are currently setting the max value to the values you just removed, leaving a gap in the arrays. If you do it the opposite way around, you will fill the caps with the max value.

Example:

Instance 1, 2, 3, 4 and 5 is running. Then instance 2 finishes and must be recycled.

In your example:

Instance 2 is cleared and everything, then it's added in instance 6 since that's the total value. Afterwards it looks like this:

Instance / Status
1 Running
2 Cleared
3 Running
4 Running
5 Running

In my example it would look like this:

Instance 2 is cleared like always, then the values of instance 5 (Total) is added to instance 2 and everything looks like this:

Instance / Status
1 Running
2 Cleared/Now using instance 5's values
3 Running
4 Running
5 Values moved to instance 2

Notice the difference?

Edit: Not even this wouldn't work since you're doing something really dumb when you increase the Total after all the value-settings in your calling function. Increase it before setting values in the variables, which will leave slot 0 without values and will allow you to properly recycle your arrays.
 
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