1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Travel to distant realms and encounter scenes unknown to the common folk. The Greatest of Adventures is upon us with the 8th Cinematic Contest. Join in on a fun ride.
    Dismiss Notice
  4. The 18th Icon Contest is ON! Choose any ingame unit and give him/her Hero abilities. Good luck to all.
    Dismiss Notice
  5. Contestants are to create a scene set in the Stone Age. Come and see what you can come up with. We wish you the best of luck!
    Dismiss Notice
  6. Colour outside the lines! Techtree Contest #13 is a go. The contest is optionally paired.
    Dismiss Notice
  7. Greetings cerebrates, our Swarm needs new spawners that will have numerous children. Join the HIVE's 31st Modeling Contest - Spawners and Spawned! The contest is optionally paired.
    Dismiss Notice
  8. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Snippet] ReviveUnit

Discussion in 'JASS Resources' started by PurgeandFire, Jan 7, 2011.

  1. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Updated. Now it will return a boolean whether or not the unit was revived. I still haven't updated the test map to your suggestion though, yet. xP
     
  2. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Lol updated again. I had to resort back to my old technique of moving the dummy to the unit, instead of all the units to the dummy. It requires WorldBounds again.

    The reason why is because of creeps. (arghh) When I move them to the dummy and then revive them, and then move them back, it works fine. But if I say attack them and then run, they will run back to the dummy. (After they are revived, that kind of "changes" their start position to wherever they were revived) So they run back and that is their new home. Thus, I had to change it again. :ogre_icwydt:

    EDIT: Nvm, not creeps. Units in general. If you attack them and then run away, they'll run back to the position of the reviver.
     
  3. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,007
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    There's a "reset guard position" native that cancels just that. Skim through the common.j native API and you'll find it :)
     
  4. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Hmm... I forgot about those natives. Thanks. :)

    Anyway, I am not encountering the error anymore, so I am updating it back for now unless I encounter that problem again.
     
  5. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Found a problem ;D

    private constant integer UNITS_REVIVE_UNIT_DUMMY = 'dumy'



    That would create a null unit, unless you just happen to have a unit using the 'dumy' id. You should fix as that'll shadow the correct UNITS_REVIVE_UNIT_DUMMY variable.
     
  6. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Whoops, fixed.

    Also fixed a LUA error. I changed this:
    Code (vJASS):
            //! i makechange(current,"uabi","'" .. rez .. "',Aloc,Avul")

    To this:
    Code (vJASS):
            //! i makechange(current,"uabi","" .. rez .. ",Aloc,Avul")


    Because otherwise it wouldn't add the ability to the unit. (It would look for 'A!! rawcode)
     
  7. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    //! i makechange(current,"uabi","" .. rez .. ",Aloc,Avul")
    is still wrong. Notice your "" ; P

    It should be current,"uabi", rez .. ",Aloc,Avul"


    Obviously doesn't matter as "" is just an empty string, but it's silly to have the "" in there ;P.
     
  8. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    You can try that if you want but it doesn't seem to work. (the one I posted works fine though) The data for abilities is inclusive of rez, so it would be " A , B , C " and then the " .. var .. " is just to read it. ;P
     
  9. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Uh?

    //! i makechange(current,"uabi",rez .. ",Aloc,Avul")
    ???

    That should work just fine ;P. It's the same as what you are doing without the empty string at the start.
     
  10. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Oh, okay. I mistyped it. I'll update the first post in a sec.
     
  11. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Delete this line and it will be good to go.

    private constant integer UNITS_REVIVE_UNIT_DUMMY = 'u!!!'



    Remember that the id is dynamic, so it could be anything. Just because it happens to be 'u!!!' in your map doesn't mean that it'll be the same in another map.

    Furthermore, the variable is automatically imported into the map >.>. All this line does is overshadow the variable that contains the right value.
     
  12. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Whoops. I must've had that left over from before. Removed. Thanks. :D
     
  13. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Your script is so small, I love it ;D.

    Bribe should be approving this when he gets back online.
     
  14. watermelon_1234

    watermelon_1234

    Joined:
    Nov 18, 2007
    Messages:
    1,066
    Resources:
    10
    Spells:
    9
    JASS:
    1
    Resources:
    10
    Looks like it works good. ^_^

    Unfortunately I can't save the demo map. It says something about not being able to find the file luajass.ReviveUnit.j. Am I supposed to have something else other than the demo map?
    (Sorry, I'm not too familiar with LUA stuff)
     
  15. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    It has to do with the lua links above it. When JASS or variables are generated (as is the case here), the stuff has to be installed for the map. Purge should probably not be using the lua scripts in the demo map, but rather just have some arbitrary id and a pre-gen'd object. The demo map should be able to be run immediately w/o having to install stuff.

    Here that Purge? : P
     
  16. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Lol, sorry. I ignore updating the demo map at times. I saved with the header in it and I was too lazy to remove it. :p I'll update it in a little bit.

    EDIT: Okay, I updated it. It is still the boring old test map though. :p However, now once all the units are alive, it will kill them all again. So spam ESC to your heart's delight. :D
     
  17. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,007
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Sick library is full of win. Approval is necessary.
     
  18. TriggerHappy

    TriggerHappy

    Code Moderator

    Joined:
    Jun 23, 2007
    Messages:
    3,654
    Resources:
    22
    Spells:
    11
    Tutorials:
    2
    JASS:
    9
    Resources:
    22
    What do you think of changing the script to this:

    Code (vJASS):

    library ReviveUnit initializer Init
        //***********************************************
        //       REVIVE UNIT
        //***********************************************
        //  - This library allows you to revive units in a similar fashion to heroes.
        //  - This library retains the unit's previous handle ID
        //  - This library retains the unit's facing
        //  - It will fail if the unit has decayed already
        //  - It will fail if the unit has exploded
        //  - It will fail on ethereals. (essentially anything that doesn't leave a corpse)
        //  - It will fail on buildings
       
        //  Automatic Generation:
        //      - Save your map and restart it, then uncomment the object merger line below.
        //  Manual Implementation:
        //    - Copy the spell named "Resurrection"
        //    - Paste it in your map
        //    - Copy this trigger and its contents, and paste it in your map
        //    - Modify UNITS_REVIVE_UNIT_DUMMY to the rawcode of the dummy unit your are using
       
        //  Function:
        //      Revive.Unit(whichUnit)
        //          - Revives some dead corpse. Returns whether or not the unit was revived.
       
        //***********************************************    

        globals
            // Configuration
            private constant integer UNITS_REVIVE_UNIT_DUMMY            = 'e000' // any dummy (preferably xebasic's)
            private constant integer ABILITIES_REVIVE_UNIT_RESURRECTION = 'URez'
           
            //! external ObjectMerger w3a AHre URez anam "Dummy Resurrection" ansf "(ReviveUnit)" acat "" arac 0 atat "" amcs 1 0 acdn 1 0 aher 0 Hre1 1 1 aare 1 0 aran 1 0 atar 1 "Air, Dead, Enemy, Friend, Ground, Neutral"
               
            // Don't edit below this line
            private unit reviver
            private real rx
            private real ry
        endglobals
       
        struct Revive extends array
       
            static method Hero takes unit whichHero returns boolean
                return ReviveHero(whichHero, GetUnitX(whichHero), GetUnitY(whichHero), false)
            endmethod
           
            static method Unit takes unit whichUnit returns boolean
                local real x = GetUnitX(whichUnit)
                local real y = GetUnitY(whichUnit)
                local boolean bb = true
                if IsUnitType(whichUnit,UNIT_TYPE_HERO) == true then
                    call ReviveHero(whichUnit,x,y,false)
                else
                    call SetUnitX(whichUnit,rx)
                    call SetUnitY(whichUnit,ry)
                    set bb = IssueImmediateOrderById(reviver,852094)
                    call SetUnitX(whichUnit,x)
                    call SetUnitY(whichUnit,y)
                endif
                return bb
            endmethod
           
        endstruct
       
        function ReviveUnit takes unit whichUnit returns boolean
            return Revive.Unit(whichUnit) // unfortunately doesn't inline
        endfunction
       
        private function Init takes nothing returns nothing
            set rx = GetRectMaxX(bj_mapInitialPlayableArea)-1
            set ry = GetRectMaxY(bj_mapInitialPlayableArea)-1
            set reviver = CreateUnit(Player(15),UNITS_REVIVE_UNIT_DUMMY,rx,ry,0)
            call UnitAddAbility(reviver, ABILITIES_REVIVE_UNIT_RESURRECTION)
        endfunction

    endlibrary
     

    and if not, you might want to at least utilize the object merger line
     
  19. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Updated to 2.0.0.0. The API was changed. Now it just has a function API
    call ReviveUnit(unit)
    . A struct API doesn't make much sense since it isn't really an object.

    As for the method: now the dummy moves to the unit's position, and then back. Pro: now the unit won't fire enter/leave region events (the dummy still will, but that is easier to filter out), and he'll maintain the same position when resurrected. Con: there is a chance that the wrong unit will be resurrected iff (1) there are > 1 units on the same exact coordinates (2) they both have no pathing. The chances of that are very small, so I figure it isn't worth even addressing. I'd rather prevent firing external events due to the system.
     
  20. BPower

    BPower

    Joined:
    Mar 18, 2012
    Messages:
    1,741
    Resources:
    21
    Spells:
    15
    Tutorials:
    1
    JASS:
    5
    Resources:
    21
    I see! Back to the roots where
    IsUnitType(u, UNIT_TYPE_HERO)
    was
    IsUnitType(u, UNIT_TYPE_HERO) == true
    .

    Dalvengyr submitted a system with the same functionality in the spell section 2 weeks ago. I guess he wasn't aware of the JASS section back then.
    I'm going to pm him and discuss what we're gonna do with his submission.

    I required more savety checks before moving the reviver and asked him to add:
    • IsUnitType(toRevie, UNIT_TYPE_DEAD)
      --> Is the unit you attempt to revive actually dead (debug only)
    • GetUnitTypeId(toRevive) != 0
      --> Does this corpse actually rot somewhere or is it removed. Does filter out invalid units. (debug only)
    Those checks are not important, because it doesn't minimize the chance of reviving the wrong unit. (The chance of reviving the wrong unit is close to zero.)
    I'm already waiting for his wave of anger towards me :/.

    The dummy doesn't need 'Avul' since you already use 'Aloc', but it's not a big deal.