System UnitLock

Cohadar

master of fugue
Reaction score
209
JASS:

//==============================================================================
//                    UnitLock --  by Cohadar -- v1.0
//==============================================================================
//
//  PURPOUSE:
//       * Preventing multiple spells from moving the unit at the same time,
//         thus preventing spell interference bugs.
//       
//       * Orders spells by priority which has 2 effects:
//           * Stronger spells can overtake the weaker ones.
//           * Weaker spells will not work on units affected by stronger spell.
//
//  FUNCTIONS:
//       * UnitLock_Set(whichUnit, priority, overtakeIfSame) -> lockId
//       * UnitLock_Get(whichUnit) -> lockId
//       * UnitLock_Release(whichUnit, lockId)
//
//  HOW TO USE:
//       * The Set function creates a lock on the unit and returns the lockId
//         lockId can be any number different from zero
//
//       * priority field determines what to do if there already exists a lock on the unit
//         Some spells can have higher priority than others so they can overtake the unit
//
//       * There are 3 lock types: weak, normal, strong
//           * [weak] (priority <= 0.0)
//                 Weak locks will always be overtaken even if new lock is of lower priority
//                 All weak locks are equal
//           * [normal] (0.0 < priority <= 1.0)
//                 Normal locks can be overtaken only by a lock of higher priority 
//                 or if overtakeIfSame is true for a lock of same priority
//                 If overtaking fails Set function returns zero
//           * [strong] (1.0 < priority)
//                 Strong locks cannot be overtaken
//                 All strong locks are equal
//
//       * Get function returns the lockId, or zero if no lock is set.
//         You should use this function inside a spell loop to check if your spell
//         stil has lock on the unit.
//
//       * Release function must provide a valid lockId.
//         Spell instance can unlock only it's own locks.
//
//  DETAILS:
//       * The release method will restore the unit's default fly height.
//
//       * Units that get close to map borders will have their lock broken.
//         This will prevent the spell from taking the unit beyond border.
//
//       * There is no GetPriority function, this is on purpose.
//
//  REQUIREMENTS: 
//       * PUI
//
//  HOW TO IMPORT:
//       * Just create a trigger named UnitLock
//       * convert it to text and replace the whole trigger text with this one
//
//==============================================================================


library UnitLock initializer Init uses PUI
//! runtextmacro PUI_PROPERTY("private", "integer", "LockId", "0")
//! runtextmacro PUI_PROPERTY("private", "real", "LockPriority", "0.0")

globals
    public  constant real HEIGHT_RESTORATION_SPEED = 400.
    private integer lockCounter = 0
endglobals

//===========================================================================
//  Returns zero if lock could not be set
//===========================================================================
public function Set takes unit whichUnit, real priority, boolean overtakeIfSame returns integer
    local boolean overtake = false
    
    if (LockId[whichUnit] == 0) or (LockPriority[whichUnit] <= 0.0) then
        set overtake = true
    else
        if (LockPriority[whichUnit] <= 1.0) then
            if LockPriority[whichUnit] < priority then
                set overtake = true
            elseif LockPriority[whichUnit] == priority then
                set overtake = overtakeIfSame
            endif
        endif
    endif

    if overtake then
        set lockCounter = lockCounter + 1
        set LockId[whichUnit] = lockCounter
        set LockPriority[whichUnit] = priority
        return lockCounter
    else
        return 0
    endif
endfunction

//===========================================================================
//  Use this inside a spell loop to check if your spell stil has lock on the unit.
//===========================================================================
public function Get takes unit whichUnit returns integer
    return LockId[whichUnit]
endfunction

//===========================================================================
//  Spell instance can only release it's own lock.
//===========================================================================
public function Release takes unit whichUnit, integer lockId returns nothing
    if LockId[whichUnit] == lockId then
        set LockId[whichUnit] = 0
        set LockPriority[whichUnit] = 0.0
        call SetUnitFlyHeight(whichUnit, GetUnitDefaultFlyHeight(whichUnit), HEIGHT_RESTORATION_SPEED)
    endif
endfunction

//===========================================================================
private function BorderStop takes nothing returns nothing
    local unit whichUnit = GetTriggerUnit()
    set LockId[whichUnit] = 0
    set LockPriority[whichUnit] = 0.0
    call SetUnitFlyHeight(whichUnit, GetUnitDefaultFlyHeight(whichUnit), HEIGHT_RESTORATION_SPEED)
    set whichUnit = null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterLeaveRectSimple( trig, GetPlayableMapRect() )
    call TriggerAddAction( trig, function BorderStop )
endfunction

endlibrary


It might not look that way at first but this little script is actually a physics system. The biggest lol about this is that it is actually the most powerfull wc3 physics system ever created.

Try out the spells from demo map and be amazed :)
 

Attachments

  • UnitLock v1.0.w3x
    36.7 KB · Views: 278

Azlier

Old World Ghost
Reaction score
461
It's a vJass script. All it needs is a vJass preprocessor and PUI. Nothing else special.

Now THAT'S a good idea for a script!
 

Hatebreeder

So many apples
Reaction score
380
It would be cool, if the spells of same priority would nullify each other ^.^
Other than that, this seems VERY usefull to me.
+REP =)
EDIT: Damn, mus spread rep around before i can give you again =/
 

Prometheus

Everything is mutable; nothing is sacred
Reaction score
589
Pretty cool, but the levitate spell is kinda jumpy. Then again, this isn't a spell pack. :D

Edit: Typo?

JASS:
//           * [normal] (0.0 < priority <= 1.0)


Should be...

JASS:
//           * [normal] (0.0 > priority <= 1.0)
 

Cohadar

master of fugue
Reaction score
209
What happens if I overtake units 2^31-1 times? Will LockCounter overflow then?

LoL, no it won't.
Negative id's are also valid, the only invalid one is zero so if by any chance you manage to waste all 4294967295 available id's one of your spells will fail and than it will continue normally.

Of course by the time you finish that epic game our galaxy will collapse into a black hole, so in order to use this system properly you need to be on a spaceship located beyond the time-horizon and flying the hell out of what used to be Milky Way.

Fixed:
JASS:

library UnitLock initializer Init uses PUI, FTLDrive
 

emjlr3

Change can be a good thing
Reaction score
395
why do you reset units flyheight?
 

Cohadar

master of fugue
Reaction score
209
why do you reset units flyheight?

Well ground units would be hovering in air for no reason if I didn't and air units would be flying on bad height.

You can thing of it as "gravitation" for ground units and for air units it is simply default fly height.
 

emjlr3

Change can be a good thing
Reaction score
395
there is no documentation anywhere that suggests this would be used for fly height manipulating spells (which there are not many of in the first place) - I figured it would be more for buffs/debuffs, knockbacks, etc.
 

SerraAvenger

Cuz I can
Reaction score
234
Demo Map > Documentation

Only if there's a docu : )
Perhaps I want to see what It does but don't want to test out the demo map? Perhaps I can't?
Also you might want to catch the readers interest before he actually WANTS to see the demo map ; )
 

BRUTAL

I'm working
Reaction score
118
this will work with like, regular warcraft spells also correct? like if you make the trigger for when it is used
also, if i want to like, stop all spells from being casted while a hero is already in effect of a spell (lets say a slide spell) would that mean id have to use the event for all my spells? and doesnt that event serve to be glitchy ><
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top