• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Pack and unpack an item structure

Status
Not open for further replies.
Level 4
Joined
Jan 17, 2018
Messages
112
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.
 
Level 15
Joined
Jul 9, 2008
Messages
1,552
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)
 
Level 4
Joined
Jan 17, 2018
Messages
112
Yep, sounds good. Have you a demo attempt / problems? For timeout you can use timer, wait, or periodically running trigger that counts down.

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.

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)

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?
 
Level 4
Joined
Jan 17, 2018
Messages
112
  • 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.
 
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.
 
Level 4
Joined
Jan 17, 2018
Messages
112
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.

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.
 
Level 15
Joined
Jul 9, 2008
Messages
1,552
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
 
Level 4
Joined
Jan 17, 2018
Messages
112
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.

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 :<?
 
Level 4
Joined
Jan 17, 2018
Messages
112
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?
 
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.
 

Attachments

  • aa.w3x
    34.8 KB · Views: 60
Last edited:
Level 12
Joined
May 22, 2015
Messages
1,051
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.
 
Level 4
Joined
Jan 17, 2018
Messages
112
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.

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

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.

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?
 
Level 12
Joined
May 22, 2015
Messages
1,051
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?

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).
 
Level 4
Joined
Jan 17, 2018
Messages
112
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?

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).

Thanks, I'll dig around a bit.
 
Level 12
Joined
May 22, 2015
Messages
1,051
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).
 
Level 4
Joined
Jan 17, 2018
Messages
112
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"
 

Attachments

  • Tower health.w3x
    14.1 KB · Views: 45
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.
 
Level 4
Joined
Jan 17, 2018
Messages
112
Can you explain more accurately what do you need actually? I thought you just need create a system which can pack/unpack buildings into items.

Yea, the replace building with item was sorted out, it took like 3 lines of code. It has been explained in the thread, but I'd like the structure to be built with the same hp as when I dismantled it. So say someone deals 100 damage to it, I dismantle it and rebuild it somewhere else, it will have 100hp less. But, the unit that can build this structure is spammable so there isn't like one of this unit per player.
 
Level 11
Joined
May 16, 2016
Messages
730
Yea, the replace building with item was sorted out, it took like 3 lines of code. It has been explained in the thread, but I'd like the structure to be built with the same hp as when I dismantled it. So say someone deals 100 damage to it, I dismantle it and rebuild it somewhere else, it will have 100hp less. But, the unit that can build this structure is spammable so there isn't like one of this unit per player.
 

Attachments

  • Build and Dismantle.w3x
    23 KB · Views: 20
Status
Not open for further replies.
Top