• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Spell] Inventory Switching

Status
Not open for further replies.
Level 11
Joined
Oct 31, 2010
Messages
1,057
So... was making a ability that allows you to switch your inventory with a "stash" aka dummy unit and could not get it to work because if you have 6 items and you switch to the other unit's inventory and the other unit has your inventory with 6 items, it would conflict with each other o.o. So anyone got a idea how to go about doing this?
 
Level 11
Joined
Oct 31, 2010
Messages
1,057
Um... i kinda deleted the code and i visualized the code in my head and i got the error from that o.o.....If you could give me a solution to how to fix the 6 items conflicting because you cant pass 6 items to a unit that already has 6 items in his inventory
 
Level 9
Joined
Aug 7, 2009
Messages
380
That's true, no, you can't
But sure, we can in this way or other way. Like: At the start of a unit order an inventory switch, we will set all of its item type as item type variable. Do the same thing with the stash.
Once we've done that, you'll delete all of those items and create, give the item to the opposite unit.
And there you go
 
First, drop all the items from the hero on the floor and store them into a variable :
  • For each (Integer A) from 1 to 6 - do
    • Loop - Actions
      • Set HeroItem[(Integer A)] = Item in HERO's slot (Integer A)
      • Hero - Drop HeroItem[(Integer A)] from HERO
Then you give all the items from your secondary unit to the hero.
And finally give the hero's droped items to the secondary unit :
  • For each (Integer A) from 1 to 6 - do
    • Loop - Actions
      • Hero - Give HeroItem[(Integer A)] to UNIT
Not sure about the actions precise names, but the idea is here.
 
Level 11
Joined
Oct 31, 2010
Messages
1,057
what am i doing wrong :C i dont see what is wrong with this trigger
the problem : the item from the casting unit is removed but does not get sended to the inventory dummy :C
attachment.php
 

Attachments

  • switching inventory.PNG
    switching inventory.PNG
    93.4 KB · Views: 396
Level 28
Joined
Jan 26, 2007
Messages
4,789
Here's a really easy system.
It's wanna-be-GUI, but I have a reason! D:

It's really easy to store integers in hashtables, and item types are basically integers.
The thing is that GUI doesn't know this (I think?), so basically what the system does is this:

1) Loop through all slots.
2) Variable -> Item in Current Slot
3) Remove Item in Current Slot
4) Load previous item (the one in the other inventory).
5) SaveCurrentSlot -> Save 'Variable' ( = Item in Current Slot )

I hope you kind-of understood that :S


I can enhance this system by making the items appear in the correct order when there's a blank space (now, if you re-arrange the items so you skip over a slot, it will fill that up next time the inventory loads).

Edit: Wait. Did I forget charges? I always do that >_>.
Give me 1 minute :)

Edit 2: Okay, done. So do you care about the position the items were in?
 

Attachments

  • Switch Inventory.w3x
    18.5 KB · Views: 65
Apocalypse, there is a flaw in your trigger (besides it doesn't seem to work for darkzxx but I guess it's not your system's fault ^^) :
When you create an item that has both passive and active abilities with charges and that doesn't destroy itself on the last use (DotA's Diffusal Blade, for instance), it bugs. You see, when you set the amount of charge to 0 by trigger, it doesn't disable the active abilities so you end up with an item with infinite charges.

That's why you shouldn't destroy/recreate items but store them in a safety area or in a bag unit (for what I understood, darkzxx wants that last one solution).
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
I do :)
So the problem was that, let's say you've got an item which does 2 things:
1) Give you +10 damage
2) Give you the ability to summon a demon (2 charges)

If you summon the demon twice (no charges left), then the item will still be in your inventory (because of the +10 damage bonus), but you cannot summon anything.
If you switch inventories, then the system will save "0 charges". In the trigger editor, 0 charges means infinite charges. This isn't right, because then you can summon infinitely many demons.
I've changed the system so the item drops (and thus is never destroyed), which solves that problem.

The next problem I had is that you can't save "null" in a hashtable (it won't overwrite the previous value, at least not for me). So I had to introduce a dummy item that functions as null, which is a roundabout way and I don't really like it, but I couldn't see another easy option (don't want to stretch the code).


New version attached

Setup:
  1. Copy the category "Inventory" to your map (be sure that "automatically create variables" is checked).
  2. In your map, place an item (any item, doesn't matter which type) on the map.
  3. In the trigger "Init", change the value for "set hiddenItem" to the item you just placed on the map.
  4. In the trigger "Switch Inventory", change the condition to your ability.

It should work then.
 

Attachments

  • Switch Inventory V2.w3x
    18.2 KB · Views: 96
Level 11
Joined
Oct 31, 2010
Messages
1,057
I do :)
So the problem was that, let's say you've got an item which does 2 things:
1) Give you +10 damage
2) Give you the ability to summon a demon (2 charges)

If you summon the demon twice (no charges left), then the item will still be in your inventory (because of the +10 damage bonus), but you cannot summon anything.
If you switch inventories, then the system will save "0 charges". In the trigger editor, 0 charges means infinite charges. This isn't right, because then you can summon infinitely many demons.
I've changed the system so the item drops (and thus is never destroyed), which solves that problem.

The next problem I had is that you can't save "null" in a hashtable (it won't overwrite the previous value, at least not for me). So I had to introduce a dummy item that functions as null, which is a roundabout way and I don't really like it, but I couldn't see another easy option (don't want to stretch the code).


New version attached

Setup:
  1. Copy the category "Inventory" to your map (be sure that "automatically create variables" is checked).
  2. In your map, place an item (any item, doesn't matter which type) on the map.
  3. In the trigger "Init", change the value for "set hiddenItem" to the item you just placed on the map.
  4. In the trigger "Switch Inventory", change the condition to your ability.

It should work then.

you mean i gotta set the value hiddenitem to every item i have in my map ?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
you mean i gotta set the value hiddenitem to every item i have in my map ?
No :O Only to the item you just placed in the map (as said in the instructions).
Look at how I did it in the map: I placed an undead flag (I think?) in the top-left corner of the map.
That undead flag will be the "hidden item" (that item cannot be seen for the rest of the game). It only serves some system-specific job.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
it does not work O:, i kept spamming the skills again and i dont get back my fishing rod, heres the map , did i do anything wrong :c
Problem 1: you haven't changed the condition, so it never really activates :p

Problem 2: you haven't deleted the old inventory-system.

Problem 3: this one was actually a bit harder to pinpoint what exactly was going wrong.
It seems that the "Integer A"-loop was overused already, so it got overwritten and messed everything up.
The solution is simply to use "Integer (variable)" instead, which is what I did.

Updated map attached.
 

Attachments

  • RPG(LALALA.w3x
    1.9 MB · Views: 82
Level 11
Joined
Oct 31, 2010
Messages
1,057
is this mui ? :C, i tried it with the player teal and it did not work :C, it allowed me to switch but whatever i switch to, i still get the same item O: and if i leave the item at the floor and press switch, the item comes to my inventory :O
 
Level 11
Joined
Oct 31, 2010
Messages
1,057
strange then :C, when i used a (teal) hero to pick up a helmet and used switch inventory to a inventory with no items , the next inventory has the helmet too......then when i drop the helmet and used switch inventory , the helmet at the ground disappears and i get one back at my inventory :C
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Honestly? It's weird.
So I tested the system as teal and you were right, switching inventory got a bit bugged.

So I opened the trigger editor and added debug messages and after that the system worked just fine. No bugs to be found.
So I removed the debug messages to see if it would still work, and it did. No problems anymore.
I haven't changed anything, just added messages.
I have no idea what's going on anymore :p

So I'm sorry... it works for me right now :/
I can advise you to go to Scenario -> Force Properties and check "Fixed Player Settings" though, not that it would change anything :p
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
So i made a demo map, check the screenshot, i made it extendable with buying and useing the ''bag'' item, from 10 slot till 100 slot (so at start u start with 10 bag slot and can extend 9 times each time +10 item)

easy to put to bag with simple 1 click after u clicked to bag ability and restore item on multiboard with simple pressing escape :p

-------------------------------------------------------------------------------------------
yes this isn't like you said with 2 unit and 6*2 inventory but this also a solution for store your items and this way also pretty fast too and the storeing limit could be huge not just 11-12
 

Attachments

  • bag.w3x
    30.4 KB · Views: 61
  • 03.jpg
    03.jpg
    165.3 KB · Views: 108
  • 02.jpg
    02.jpg
    180.1 KB · Views: 110
  • 01.jpg
    01.jpg
    165.2 KB · Views: 157
Level 17
Joined
Nov 13, 2006
Messages
1,814
I was actually trying to make it simple to implement and use.
When you use a dialog, the system suddenly becomes heavy on the player (he has to do stuff in order to store items). I don't really like that to be honest.

i made the demo map for this

hmm regarding that, i plan to implant it on my map but i don't know which triggers to copy and paste :C, wait... do you mind if i just take some triggers that i need?

coz in demo that is mostly copy paste thing

also, he is making a multiplayer map. saving/load with these bag systems would be too much complicated.
_______________

sorry i dont readed that, where he want save every item via save load code from bag.

personally i am not sure u must save everything in multiplayer game, i save like 10 item with my load code or 16 and i dont planing save more because i dont feel it is needed but during game play the space is needed, mainly if u do craft/quest item things, you can consider about useless save this kinda items if u can get again via quests in game, ofc depend on map style
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
O:!!! yeah was having another question, how do i save hashtables O: since apocalyse system uses hashtables, and i don't know how to save hashtables and load them O:

my example also use but that dont must touch it because system where store what but anyway here few helpfull site

(german but i guess if u use chrome then this good site because also visualize how it is look like)
http://warcraft.ingame.de/cms.php?section=mapping&id=93528

http://www.hiveworkshop.com/forums/trigger-gui-editor-tutorials-279/hashtables-mui-133407/
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
a very basic switch is like this, this dont ened hashtable or dialog or multiboard or anything if u mean like this

for demo i created stash and hero at mape init where i declare hero[1] is player 1 hero and same with stash[1] etc
  • Switch inventory
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Inventory switch
    • Actions
      • Set i = 0
      • Set pl = (Player number of (Triggering player))
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set i = ((Integer A) + 6)
          • Set Items[(Integer A)] = (Item carried by Hero[pl] in slot (Integer A))
          • Hero - Drop the item from slot (Integer A) of Hero[pl]
          • Set Items[i] = (Item carried by Stash[pl] in slot (Integer A))
          • Hero - Drop the item from slot (Integer A) of Stash[pl]
          • Hero - Give Items[i] to Hero[pl]
          • Hero - Give Items[(Integer A)] to Stash[pl]
 

Attachments

  • invetory switch demo.w3x
    20.2 KB · Views: 50
Status
Not open for further replies.
Top