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 > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 06-11-2011, 10:13 PM   #1
BBQ
User
 
Join Date: May 2011
Posts: 85

Submissions (2)

BBQ will become famous soon enough (30)BBQ will become famous soon enough (30)

Default PauseUtils

Introduction
PauseUtils is written in Zinc and requires the Jass NewGen Pack along with the latest version of JassHelper.

This is just a simple snippet that is meant to prevent units from being unpaused prematurely due to the lack of multi-instanceability of the native function. It also provides the user with responses that are evaluated when a unit is effectively paused or unpaused and allows pausing units for a specified duration.
CreditsLimitations
Unfortunately, you must abide to a few limitations in order to use this snippet to its fullest. All your PauseUnit(unit, true) calls should be replaced with Pause(unit) and all your PauseUnit(unit, false) calls should be replaced with Unpause(unit). The natives would still work normally, but there would be no safety and no responses would be evaluated. With that being said, one can easily conclude that this snippet is best used in a fresh new map.
The snippet
Requirements:
Expand PauseUtils:

Available functions
This snippet provides the following functions to the user:
  • function Pause takes unit whichUnit returns nothing
  • function Unpause takes unit whichUnit returns nothing
  • function TimedPause takes unit whichUnit, real duration returns nothing
  • function OnUnitPaused takes response whichResponse returns nothing
  • function OnUnitUnpaused takes response whichResponse returns nothing
response is either a function or a static method that takes unit (the unit that was paused or unpaused) and returns nothing.

Last edited by BBQ : 07-01-2011 at 11:55 PM.
BBQ is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 06-11-2011, 11:27 PM   #2
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

As far as I'm aware it is preferable to disable units instead of pausing them, as disabling does not clear the unit's command card and queued orders like pausing does. This is not a small problem - I've tried pausing units before when making certain spells and the inability to issue or queue new orders while the spell is running was very frustrating for the player.

With this in mind, I would always prefer using UnitStatus over PauseUtils, unless there's some advantage pausing has over disabling that I am not aware of.
__________________
Anitarf is offline   Reply With Quote
Old 06-12-2011, 12:10 AM   #3
BBQ
User
 
Join Date: May 2011
Posts: 85

Submissions (2)

BBQ will become famous soon enough (30)BBQ will become famous soon enough (30)

Default

Well, if we're talking about game balance, then pausing units has much more impact on the gameplay than simply stunning them.

For example, pause disables evasion, permanent invisibility, true sight, hardened skin and building damage aura, while a stun would do none of that.

Moreover, most of the hardcoded buffs have their duration "frozen" by pause. Sure, if you handle all those durations via softcoded means, such thing wouldn't happen, but the above point would still stand true.

Generally, I see nothing wrong with pausing units. For example, DotA (yes, I know that DotA is horribly coded and everything) uses it quite commonly, and I am yet to see anyone complain about that.

Last edited by BBQ : 06-12-2011 at 06:26 AM.
BBQ is offline   Reply With Quote
Old 06-12-2011, 01:10 AM   #4
Captain Griffen
Dread Lord of the Cookies
 
Captain Griffen's Avatar


Content Director
 
Join Date: Sep 2003
Posts: 5,375

Submissions (2)

Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)

Approved Map: Warlords[Quicksilver #2] - 1st Place

Default

Pause also pauses spell effects. Might be useful for maps which use pause though.
__________________
Quote:
Originally Posted by Earth-Fury
Griffen is correct, you are not.
Quote:
[13:32] <Akolyt0r> hmm.. stil i want to have some unused women
Captain Griffen is offline   Reply With Quote
Old 06-13-2011, 07:06 PM   #5
BBQ
User
 
Join Date: May 2011
Posts: 85

Submissions (2)

BBQ will become famous soon enough (30)BBQ will become famous soon enough (30)

Default

Added TimedPause(unit, real).

With that came along an additional requirement, TimerUtils.
BBQ is offline   Reply With Quote
Old 06-14-2011, 01:00 AM   #6
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

While I do not wish to encourage people to pause units when making spells (I would recommend the disable functionality of UnitStatus in those cases), there can be other uses for pausing where this would be a very helpful library. Approved.

You should perhaps point out in the documentation that users who use this in their map should only use this library's functions and not the PauseUnit native.
__________________
Anitarf is offline   Reply With Quote
Old 06-14-2011, 11:09 AM   #7
Captain Griffen
Dread Lord of the Cookies
 
Captain Griffen's Avatar


Content Director
 
Join Date: Sep 2003
Posts: 5,375

Submissions (2)

Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)

Approved Map: Warlords[Quicksilver #2] - 1st Place

Default

Quote:
You should perhaps point out in the documentation that users who use this in their map should only use this library's functions and not the PauseUnit native.

PauseUnit directly should still be fine for the pause/order/unpause trick (so long as you set 'paused' to a variable), though in general you are right.
__________________
Quote:
Originally Posted by Earth-Fury
Griffen is correct, you are not.
Quote:
[13:32] <Akolyt0r> hmm.. stil i want to have some unused women
Captain Griffen is offline   Reply With Quote
Old 06-14-2011, 03:01 PM   #8
BBQ
User
 
Join Date: May 2011
Posts: 85

Submissions (2)

BBQ will become famous soon enough (30)BBQ will become famous soon enough (30)

Default

Quote:
Originally Posted by Captain Griffen
PauseUnit directly should still be fine for the pause/order/unpause trick (so long as you set 'paused' to a variable), though in general you are right.
Perhaps I could also add something like:
Collapse Zinc:
public function Interrupt(unit whichUnit) {
    if (pauseCounter[GetUnitId(whichUnit)] == 0 && !IsUnitPaused(whichUnit)) {
        PauseUnit(whichUnit, true);
        IssueImmediateOrderById(whichUnit, 851972);
        PauseUnit(whichUnit, false);
    }
}

Is the pause/order/unpause trick used with any order other than "stop"? I've only used it (and only seen others using it) with "stop" for interrupting purposes.

Quote:
Originally Posted by Anitarf
You should perhaps point out in the documentation that users who use this in their map should only use this library's functions and not the PauseUnit native.
Done.

Quote:
Originally Posted by Anitarf
While I do not wish to encourage people to pause units when making spells (I would recommend the disable functionality of UnitStatus in those cases), there can be other uses for pausing where this would be a very helpful library. Approved.
Hooray! Thanks a lot.

Last edited by BBQ : 06-14-2011 at 03:09 PM.
BBQ is offline   Reply With Quote
Old 06-14-2011, 04:32 PM   #9
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Quote:
Originally Posted by BBQ
Perhaps I could also add something like:
Collapse Zinc:
public function Interrupt(unit whichUnit) {
    if (pauseCounter[GetUnitId(whichUnit)] == 0 && !IsUnitPaused(whichUnit)) {
        PauseUnit(whichUnit, true);
        IssueImmediateOrderById(whichUnit, 851972);
        PauseUnit(whichUnit, false);
    }
}
Well, as Griffen pointed out, this can be done without the need for PauseUtils and is in fact already provided by LastOrder in the form of the AbortOrder function:
Expand JASS:
This is then further expanded by the AbortSpell library. It doesn't really seem fitting to replicate that functionality here as this is not the point of this library.
__________________
Anitarf is offline   Reply With Quote
Old 06-27-2011, 01:15 PM   #10
BBQ
User
 
Join Date: May 2011
Posts: 85

Submissions (2)

BBQ will become famous soon enough (30)BBQ will become famous soon enough (30)

Default

  1. Updated the documentation a bit.
  2. Made the response evaluation loop backwards instead of forwards.
  3. Added IsUnitIndexed(unit) checks.
BBQ is offline   Reply With Quote
Old 06-27-2011, 01:46 PM   #11
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Quote:
Originally Posted by BBQ
Made the response evaluation loop backwards instead of forwards.
Any other reason to do this besides speed? A variable read seems insignificant compared to the trigger evaluation being done inside the loop and considering how often these events are likely to run it seems like a meaningless optimization. On the other hand, when it comes to event callbacks, a library could depend on the callbacks being evaluated in the order they were registered so that the callbacks of required libraries run before the callbacks of the libraries that require them, similarly to how it is important that the initializers of required libraries run first. I can't think of an example right now so you could argue that no one will ever need this, but considering the insignificant speed difference (unless you have a different reason for doing it this way) I still think looping forward is more sensible.
__________________
Anitarf is offline   Reply With Quote
Old 06-27-2011, 06:03 PM   #12
BBQ
User
 
Join Date: May 2011
Posts: 85

Submissions (2)

BBQ will become famous soon enough (30)BBQ will become famous soon enough (30)

Default

Quote:
Originally Posted by Anitarf
Any other reason to do this besides speed?
Nope, sadly, I only did it for the marginal speed gain. If you think it makes more sense to loop forwards, then I'll be happy to change it back.

I'll also include a version that will use Table instead of AutoIndex. Even though array reading is much faster than hashtable reading, I don't think there would be any noticeable difference in the speed, mainly because using a hashtable has its own advantages over unit indexing, at least in this case.

Also, if you feel like the code needs more comments, let me know.

Last edited by BBQ : 06-27-2011 at 06:40 PM.
BBQ is offline   Reply With Quote
Old 06-27-2011, 07:46 PM   #13
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Yes, I think looping forward is better. Even if the functionality gain is marginal, it's still worth a lot more than a marginal speed gain. The only reasonable alternative I see is to loop forward on one event but backwards on the other to get a first-in-last-out setup similar to AutoIndex, although I don't really think pause/unpause events need the same strict FILO hierarchy as index/deindex events do - I just brought it up as a rare example of looping backwards being sensible.

AutoIndex can already use a hashtable instead of unit custom values, so in this regard a separate Table version of the library is not strictly needed, but Table is a somewhat lighter requirement so if you want to also make a Table version I see nothing wrong with that.

The documentation is adequate - note that the library has already been approved as is. If you want to improve it further, however, there is nothing wrong with that.
__________________
Anitarf is offline   Reply With Quote
Old 06-27-2011, 09:24 PM   #14
BBQ
User
 
Join Date: May 2011
Posts: 85

Submissions (2)

BBQ will become famous soon enough (30)BBQ will become famous soon enough (30)

Default

Okay, I totally overestimated hashtables. I don't think that I will be posting a version that uses Table instead of AutoIndex.

Anyway,
  1. Reverted the way in which the responses are evaluated.
  2. Optimized the Unpause(unit) function by a little bit.
If you see any possible quirks that could cause the snippet to fail, then do let me know.
BBQ 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 08:34 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

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