• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

How can I store several values whitin a unit?

Status
Not open for further replies.
Level 11
Joined
Oct 9, 2015
Messages
721
I'm making a missile system which has several different missiles, those missiles will stick to the target and when the target dies it will "drop" all projectiles on the ground, I needed to for example: unit is hit with an throwing axe, store 1 throwing axe whithin the unit, then it is also hit by an arrow, store 1 arrow whitin the unit, then it is again hit by an axe, now there should be 2 axes stored whitin the unit. So when it dies it will drop 2 axes and 1 arrow. Can anyone help?

PS: this is just a example, I'll have to store about 15-20 different projectiles
 
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
5,031
This is the basic use of hashtables. If JASS there are a variety of data systems like Table to use; if GUI:
  • Hashtable - Create new hashtable
  • Set YourMainHashTable = (Last created hashtable)
  • -------- Do at map init. Try to use as few different hashtables as possible because afaik there is a limit (maybe that was game caches tho). --------
  • -------- You'll be able to store things with a name that is a string of your choice so you can in effect store an arbitrary number of things each with a unique name ON each object (unit in your case) --------
  • Hash table - Save Projectile_Unit as (Key Projectile_1) of (Key (Triggering Unit)) in MainHash
  • -------- You'll save them like that; first key is a name that describes it, second is the [I]Hashtable - Get Handle ID[/I] function on whatever it is you want to attach the data (in this case the projectile unit) to. --------
  • -------- Here, triggering unit is the unit getting hit by the projectile --------
  • Set Unit_Variable = Load (Key Projectile_1) of (Key (Triggering Unit)) in MainHash
  • -------- Loading is logically the reverse of saving --------
  • -------- Here Triggering Unit is the unit presumably dying and we are using it to load the data --------
  • -------- This would actually be in some sort of loop and would be loading (Key (Projectile_ + I2S(CounterVariable))) instead --------
If you're not gonna save the unit projectiles themselves you can save any kind of data in a hashtable so pick int, real, boolean, whatever. You'll need to attach a few things to the unit getting hit by projectiles, namely: how many different types of projectiles it has and how many there are of each kind. If you try to load a key that you haven't yet saved anything to, it will return null, 0, or '' (the blank character string) depending on its type.

How you should do it depends on what data you actually want to store and what you're going to do with the data when you load it. Describe your process a little more (are they going to become items, units, sfx, etc.?) and we might be able to suggest something.
 
Level 11
Joined
Oct 9, 2015
Messages
721
when the unit dies, the projectiles on it's body will be dropped on the ground, but there won't be any itens on the ground, instead I'll create an unit with the model of the item and when a unit passes over it, he will pick up the item, here's what happens now: if unit has no projectiles on it's inventory, it will pick up the projetile, if the unit has a different projectile than the one on the ground it will ignore it, if the projectile on the grund if the same as the one owned by the player on it's inventory, then it will pick up and add the charges to the player's item. Cut short: the player will only take the projectiles that he can use, the only exception is if he has no projectiles at all. I've done all the triggering on how to pick the items, you see if your projectile hits the ground it will be placed on the spot and you can get it, I've already triggered the obatining method, the only problem I was having was on storing the data of the number of projectiles a unit has stacked on itself and it's type. I'm open to suggestions, I also can post the triggers. I'm making my project for about two years now and don't even know how to use hashtables yet lol
 
Level 39
Joined
Feb 27, 2007
Messages
5,031
Okay so assuming the projectiles you would put on the ground are the same as are hitting the units are the same as the ones flying through the air... then all you need to do is:

When the projectile hits, hide it (optional: play its death animation first) but don't kill/remove. Save it attached to the impacted unit in a hashtable in the manner I described so you can get it back later. When the unit dies, load each projectile and place it randomly somewhere nearby. Use the Point - Polar Offset with a random degree offset (0-360) and random distance from 0 to <some smallish radius>. This will bias towards the middle but that shouldn't matter here.

Forgot to mention that when you're done with the information you've stored in a hashtable there's a Hashtable - Clear all child hashtables of child (Key (Triggering Unit)) in YourHash you can use.
 
Status
Not open for further replies.
Top