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 haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Rubbed the right way, the genie is out of its lamp! The 12th Concept Art Contest Results have been announced.
    Dismiss Notice
  4. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  5. 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.

Pack and unpack an item structure

Discussion in 'World Editor Help Zone' started by Marcell, Feb 19, 2018.

  1. Marcell

    Marcell

    Joined:
    Jan 17, 2018
    Messages:
    112
    Resources:
    0
    Resources:
    0
    Hi all,

    I'd like to make an item that can be placed as a building, then you can click an icon and pack the building up again turning it into an item after a delay of say 5 seconds.

    How I would go about it, and let me know if this is correct:
    Create a dummy ability icon for the tower with the description of what it does.
    I don't know how to add the delay with the "construction loading hourglass" (if you can call it that)
    Then use a trigger where if the ability is cast, the building is removed and then replaced with the item at the same point on the map.

    I already have the item into building as this is "create ivory tower" if I'm not mistaken on the name.
     
  2. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,260
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Yep, sounds good. Have you a demo attempt / problems? For timeout you can use timer, wait, or periodically running trigger that counts down.
     
  3. millzy

    millzy

    Joined:
    Jul 9, 2008
    Messages:
    1,540
    Resources:
    6
    Maps:
    5
    Spells:
    1
    Resources:
    6
    heres the trigger your after make sure to use triggering unit not casting unit since it uses a wait other wise ull run into issues of it not being MUI

    pausing the unit is optinal note that if not paused the tower will still be able to atk ect during the wait time

    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to dummy
    • Actions
      • Unit - Pause (Triggering unit)
      • Wait 5.00 seconds
      • Unit - Remove (Triggering unit) from the game
      • Set point = (Position of (Triggering unit))
      • Item - Create Your item at point
      • Custom script: call RemoveLocation(udg_point)
     
  4. Marcell

    Marcell

    Joined:
    Jan 17, 2018
    Messages:
    112
    Resources:
    0
    Resources:
    0
    I haven't tried to put it into a script yet, I didn't want to do the hassle only to find out I'm doing it wrong, so first wanted confirmation of the process.

    Thanks for doing it for me :D, @IcemanBo so the wait he added into his script will show the same way as, eg. building construction progress?
     
  5. Marcell

    Marcell

    Joined:
    Jan 17, 2018
    Messages:
    112
    Resources:
    0
    Resources:
    0
    • Dismantle
      • Events
        • Unit - A unit Starts the effect of an ability
      • Conditions
        • (Ability being cast) Equal to Dismantle
      • Actions
        • Unit - Pause (Triggering unit)
        • Wait 5.00 seconds
        • Unit - Remove (Triggering unit) from the game
        • Set Ivory = (Position of (Triggering unit))
        • Item - Create Ivory Tower at Ivory
        • Custom script: call RemoveLocation(udg_Ivory)


    So I've created this trigger provided by millzy. I just encountered a few issues:
    - How do I make it that when I pack up the structure and place it again, it will spawn with the same hp as when it was a structure and got damaged? I'm thinking, and this will actually be perfect for the unit as the unit is rendered useless when the towers die. Add a spirit link-type spell to the unit and both structures and if the structures get damaged, the unit gets damage and when both structures dies the unit dies, and when placing the structure, it will read the hp of the unit and adjust the structure's hp accordingly. And how would I do this taking into consideration, the unit might only place 1 of the 2 structures?
    - Second issue, when I dismantle the structure, the item spawns with 2 charges as I've set it. A quick "fix" I thought of, I created a copy of the item with 1 charge, but I'm sure this won't stack with the original item, or would it? Didn't test yet, otherwise how would I fix this issue?
    - Third, and not really a biggy, but how do I make it so that it's like a construction progress? Like if you place, eg. an Altar of darkness, there's a construction bar that fills up and at some point you can cancel removing the structure and returning your resources, but for the tower, the other way around, clicking cancel and the tower would actually continue shooting instead of turning into an item.
     
  6. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,260
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    1. With hashtable you can bind data to objects. You might need to read tutorials about it.

    2. Not sure I understand the issue. I guess you know the action to manipulate an item's charges? Or I misunderstand something?

    3. Maybe you could move from "Starts effect" to "Finished training a unit" ? Like you simulate the tower removal with a building progress of a tech, or a unit, so then you also can cancel it, plus you see the progress.
     
  7. Marcell

    Marcell

    Joined:
    Jan 17, 2018
    Messages:
    112
    Resources:
    0
    Resources:
    0
    2) No, how would I manipulate charges of dropped items in the above script? I tried making the charge 1 and giving my spawned unit 2 of the items, but for some reason he only gets 1.

    1/3) I'll give those a look/try. Thanks.
     
  8. millzy

    millzy

    Joined:
    Jul 9, 2008
    Messages:
    1,540
    Resources:
    6
    Maps:
    5
    Spells:
    1
    Resources:
    6
    u can set the amount of charges in the item to what ever u wont

    • Item - Set charges remaining in (Last created item) to 1


    3. for this u can simply instead of using a dummy ability use a building upgrade to a dummy unit and removing it and giving the item. or use training of the dummy unit. remove the wait
     
  9. Marcell

    Marcell

    Joined:
    Jan 17, 2018
    Messages:
    112
    Resources:
    0
    Resources:
    0
    Here's my best attempt with hashtables:
    • Create hashtable
      • Events
        • Map initialization
      • Conditions
      • Actions
        • Hashtable - Create a hashtable
        • Set IvoryHash = (Last created hashtable)

    • Ivory Hash
      • Events
        • Unit - A unit Starts the effect of an ability
      • Conditions
        • (Ability being cast) Equal to Dismantle
      • Actions
        • Hashtable - Save (Percentage life of (Triggering unit)) as 0 of (Point-value of (Triggering unit)) in IvoryHash
    • Unit - Pause (Triggering unit)
      • Wait 5.00 seconds
      • Unit - Remove (Triggering unit) from the game
      • Set Ivory = (Position of (Triggering unit))
      • Item - Create Ivory Tower at Ivory
      • Item - Set charges remaining in (Last created item) to 1
      • Custom script: call RemoveLocation(udg_Ivory)

    • Ivory hash 2
      • Events
        • Unit - A unit Finishes construction
      • Conditions
        • (Unit-type of (Triggering unit)) Equal to Scout Tower
      • Actions
        • Set IvoryHp = (Load 0 of (Point-value of (Triggering unit)) from IvoryHash)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • IvoryHp Not equal to 0.00
          • Then - Actions
            • Do nothing
          • Else - Actions
            • Unit - Set life of (Triggering unit) to IvoryHp%


    I haven't gotten to testing the whole script as I get stuck on "Ivory hash 2" so I don't even know if I did it correctly. On Ivory hash 2, when I place the structure for the first time, it is automatically destroyed which makes sense from a script perspective, I guess. So I tried adding in If, Then, Else, but the structure still dies.

    Also, on the charges remaining script, when I try to pick the item up again, it says "inventory full" but I still have 1 charge spot available on my currently held version of the item.

    Whatdo :<?
     
  10. Marcell

    Marcell

    Joined:
    Jan 17, 2018
    Messages:
    112
    Resources:
    0
    Resources:
    0
    Oh my, I changed "IvoryHp Not equal to 0.00" to "equal" so it places the structure. But it doesn't load the hp value when I place the structure, so I'm sure the hashtable should be more complex and I should somehow store the value of the hp of the structure in the last created item, how to do this?
     
  11. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,260
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    It's not the best beginner task, I realized. But see attached demo.

    It works currently similar like you want, but instead of binding the life percentage dynamically through a building, I just assign all items with "10" on map load.

    Then some steps are used to bring the "10" finaly to constructed building, with help of imported system.

    What needs to be done is to change the init config in a dynamic config when buildings cast the spell.
     

    Attached Files:

    • aa.w3x
      File size:
      34.8 KB
      Views:
      50
    Last edited: Feb 27, 2018
  12. SAUS

    SAUS

    Joined:
    May 22, 2015
    Messages:
    1,050
    Resources:
    0
    Resources:
    0
    Just a little nitpick. Waiting via triggers is generally not so nice. It is not always accurate and, if you have too many waits at the same time, it can lag the hell out of your game.

    A better solution would be to set the channel time on the spell to 5 seconds. This will prevent the need for the wait and pausing the unit and all of that.

    You may also be able to do it with a building upgrade (like the human tower or a town hall upgrade) but I don't know the trigger functions around that as well and I think it will show the construction animation while upgrading (which might be good). The big benefit there is that you can see the progress bar before it finishes.
     
  13. Marcell

    Marcell

    Joined:
    Jan 17, 2018
    Messages:
    112
    Resources:
    0
    Resources:
    0
    Dismantle Animation.png
    I've done as you said, since I don't want lag in my game, but now the wisp detonate animation doesn't play anymore, what value needs to be modified for this? +1

    This whole system just seems complicated, so I've tied the hp of the structure to the unit building the structure, thanks for the effort though. +1

    Edit: OH, before I forget, when I dismantle the structure and place the item, this version of the item doesn't go into a stack with the rest, instead it goes 1/1/1/1/1 into the inventory, how do I fix this?
     
  14. SAUS

    SAUS

    Joined:
    May 22, 2015
    Messages:
    1,050
    Resources:
    0
    Resources:
    0
    You need to make a trigger for this. I forget exactly what it will look like since I wrote 1 function for it a long time ago in JASS and never looked at it again but it is the only way to make items stack that I know of. You basically check when a unit gets an item. If that item is a type that stacks, then, loop through the unit's inventory and check if they have 2 of them. Then you remove the one that was picked up and add however many charges were on it to the other item.

    As for the animation thing, that might not be as simple as using the wait. I guess you can trigger the animation when the unit starts casting the spell. Use the event "a unit starts casting a spell" then create the wisp detonate special effect (and destroy it to prevent leaks).
     
  15. Marcell

    Marcell

    Joined:
    Jan 17, 2018
    Messages:
    112
    Resources:
    0
    Resources:
    0
    Lol, it has not even been an hour and this trigger has been bothering me. Digging around I found:
    • Dismantle
      • Events
        • Unit - A unit Starts the effect of an ability
      • Conditions
        • (Ability being cast) Equal to Dismantle
      • Actions
        • Unit - Remove (Triggering unit) from the game
        • Set Ivory = (Position of (Triggering unit))
        • Item - Create Ivory Tower at Ivory
        • Item - Set charges remaining in (Last created item) to 1
        • Item - Set life of (Last created item) to (Life of (Triggering unit))
        • Custom script: call RemoveLocation(udg_Ivory)


    This does properly save the life of the structure into the item as I've used an unit to attack it and it kills the item if the tower was damaged, but doesn't if it's a fresh tower. Now:

    • Create Ivory
      • Events
        • Unit - A unit Uses an item
      • Conditions
        • (Item-type of (Item being manipulated)) Equal to Ivory Tower
      • Actions
        • Unit - Set life of (Constructing structure) to (Current life of (Item being manipulated))


    How would I then modify this trigger to then build the structure with the hp of the item :S?

    Thanks, I'll dig around a bit.
     
  16. SAUS

    SAUS

    Joined:
    May 22, 2015
    Messages:
    1,050
    Resources:
    0
    Resources:
    0
    That's a cool solution you have for the building HP with the item HP. Here's what I think is the problem: the item is gone by the time you check its HP for the building.

    My guess is that, if you make it so the item is not a normal charged item (make it have charges but not destroy when you use the last charge) then it will know what the HP is. Either way, I say try testing it with 2 charges first to see if your trigger then works (make buildings with first item, attack building, then turn building into new item, then make a new building with the new item).

    The only way I think it will not work is if picking up an item heals it or something like that. That should also be something you can test.

    Anyway, if it works like this, then making it so it has charges but does not expire after using all charges might fix the problem. Then, in your trigger, you just remove the item from the user's inventory (so, in your trigger, just call "remove (item being manipulated) from the game" after you set the building HP).

    One problem I foresee is that adding code to stack the item will conflict with the building HP code. Stacking the items together will leave you with only the HP of the item you keep so it will likely cause problems. I don't see a clean way around that problem so you might need to go all the way to make this work how you want (some kind of hashtable solution so you can keep track of the HP properly).
     
  17. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,260
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    I think wait 0 seconds is good solution in here, could you show me your altered solution in demo? (I also kind of doubt wait 0 seconds will cause any lag problem, why do you think it?)
     
  18. Marcell

    Marcell

    Joined:
    Jan 17, 2018
    Messages:
    112
    Resources:
    0
    Resources:
    0
    I've tried changing it around a bit to no avail.

    I've made it a non-charged item that doesn't stack and removing it from inventory when constructing.

    I believe the issue is "Set life of (Constructing unit)" is the issue, since reading the fine print, the Event should be "Starts constructing" and the same for "Constructed unit"
     

    Attached Files:

  19. Marcell

    Marcell

    Joined:
    Jan 17, 2018
    Messages:
    112
    Resources:
    0
    Resources:
    0
    Awww, I was hoping for a solution when I got back from work :(
     
  20. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,260
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Well yes, I believe it can't work like this, and what I made in my demo is:
    1. value X gets binded to an item
    2. unit uses item on a point
      -> here we bind item's value X to the unit
    3. building starts construction
      -> here we bind unit's value X to the building itself using the GetBuilder function
    4. building finished construction
      -> here we use the building's value X to properly set its life
    The problem is we maybe don't have a other good way to bring the correct value from item to the building, as there is the unit as medium.