• 🏆 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!

[Trigger] Simple Backpack Ability

Status
Not open for further replies.
Level 1
Joined
Jan 23, 2015
Messages
160
Been looking trying to find a system with a simple backpack ability to allow 6 more spots.

This one was rejected, but I want something like this.

http://www.hiveworkshop.com/threads/simple-backpack-system-v1-1-by-xorkatoss.181742/

The error in the above system is this

1. Open backpack
2. Put item in backpack
3. Close backpack
4. Open backpack again
5. Drop item from step 2 on the floor
6. Close backpack again
7. open backpack one more time

Item from steps 2 and 5 is teleported from the ground back into backpack.

Does anyone know what in the triggers is causing this?

  • Hashtable
    • Events
    • Map initialization
    • Conditions
    • Actions
    • -------- This is the point where the saved items will be placed --------
    • -------- Does not really matter since they will be hidden anyway --------
    • Set Backpack_SavePoint = (Point(0.00, 0.00))
    • Hashtable - Create a hashtable
    • Set Backpack_Hashtable = (Last created hashtable)
  • OpenBackpack
    • Events
    • Unit - A unit Starts the effect of an ability
    • Conditions
    • (Ability being cast) Equal to Open Backpack
    • Actions
    • For each (Integer i) from 1 to 6, do (Actions)
    • Loop - Actions
    • Hashtable - Save Handle Of(Item carried by (Triggering unit) in slot i) as (Key (Triggering unit)) of i in Backpack_Hashtable
    • Item - Move (Item carried by (Triggering unit) in slot i) to Backpack_SavePoint
    • Item - Hide (Item carried by (Triggering unit) in slot i)
    • Hero - Give (Load i of (Key (Triggering unit)) in Backpack_Hashtable) to (Triggering unit)
    • Unit - Remove Open Backpack from (Triggering unit)
    • Unit - Add Close Backpack to (Triggering unit)
  • CloseBackpack
    • Events
    • Unit - A unit Starts the effect of an ability
    • Conditions
    • (Ability being cast) Equal to Close Backpack
    • Actions
    • For each (Integer i) from 1 to 6, do (Actions)
    • Loop - Actions
    • Hashtable - Save Handle Of(Item carried by (Triggering unit) in slot i) as i of (Key (Triggering unit)) in Backpack_Hashtable
    • Item - Move (Item carried by (Triggering unit) in slot i) to Backpack_SavePoint
    • Item - Hide (Item carried by (Triggering unit) in slot i)
    • Hero - Give (Load (Key (Triggering unit)) of i in Backpack_Hashtable) to (Triggering unit)
    • Unit - Remove Close Backpack from (Triggering unit)
    • Unit - Add Open Backpack to (Triggering unit)
Thanks for looking. If anyone knows a way to fix the error or a similar system around here (haven't seen a simple one like this) let me know!
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
This one isnt compatible with JNGP though...

In any case, to fix the problem, before saving into the hashtable, the value in the hashtable has to be removed.
However, this action doesnt exist in GUI iirc, so you need a custom script.

This in the open trigger:
call RemoveSavedHandle(udg_Backpack_Hasthable, udg_i, GetHandleId(GetTriggerUnit()))
And this in the close trigger:
call RemoveSavedHandle(udg_Backpack_Hasthable, GetHandleId(GetTriggerUnit()), udg_i)
 
Level 1
Joined
Jan 23, 2015
Messages
160
Why do you say it is not compatible? I'm pretty sure it is working in mine.

And thank you so much! I'll give it a shot after school
 
Level 1
Joined
Jan 23, 2015
Messages
160
Hm. Well...shoot. I'm pretty sure I am using JNGP. When I import the triggers into my map it still functions, I tried putting the lines you had at the end and it didn't seem to fix the problem of items getting sucked back into the inventory.

Don't suppose you know of any similar, working systems like this? Or perhaps could tell me how to make my own based off this system?

And by the way, if the keys of units what removed from JNGP and I'm trying to run this anyway, what would the end result be? Would it just fail to save or?
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
I tried putting the lines you had at the end
You wasnt supposed to add them to the end, read my other post again.

The thing with JNGP and keys is that you cant select units or items or whatever with it.
All you can select are handles which is the parent type of almost everything... i believe everything except the primitive types (int, float, bool, string, code)
 
Level 1
Joined
Jan 23, 2015
Messages
160
You wasnt supposed to add them to the end, read my other post again.

The thing with JNGP and keys is that you cant select units or items or whatever with it.
All you can select are handles which is the parent type of almost everything... i believe everything except the primitive types (int, float, bool, string, code)

Oh shoot! Before I save into hashtable, my bad! Will try again in morning.


-referring to custom script -

Before I do (obviously you meant hashtable, not 'hasthable' but in your code for open is there an extra ')'

and in closing is udg_i more appropriate at the end or after udg_backpack_hashtable?

You've been really helpful bro thank you so much
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
You can count the brackets.
Everytime that you open with a bracket, it also has to be closed.
So there has to be an equal amount of '(' as there are ')'.

The way how hashtables work is they store values with 2 keys.
It is like a normal table with x and y coordinates and every coordinate has its own box with stuff.

The way how this system works is that it stores the normal inventory in 1 to 6 on x and the id of the unit on y (which is a few million to billion... dunno the exact value where they start counting).
The backpack is stored on the id of the unit on x and 1 to 6 on y (which is the other way around).
That is the difference between the two custom scripts.
You can also see that difference in the save actions in the triggers you posted.

And yes, hashtable > hasthable
 
Status
Not open for further replies.
Top