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

[Solved] Item-Type to Unit-Type Problem

Status
Not open for further replies.
Level 7
Joined
Jan 15, 2016
Messages
137
Hello everyone, I have a problem with a system.
To explain, I have units with icons models, which pretend to be buttons in a full-screen menu, so I need to represent the items of the hero of a particular hero, in these units-icons. I am looking for the way to be able to link or bind a type of object, so that it corresponds to a particular type of unit, such that, for example, the Mana Potion Object, is represented by a unit that is modeled on the Object icon Mana Potion.


I tried to somehow store the item in slot 1 of inventory, and by means of previously configured variables, assign a unit-icons to a number, and somehow bind them but I can not solve it. I tried the following method but I am looking for some alternative form that does not occupy the Item Level:

Code:
function Trig_SET_SLOT_1_Actions takes nothing returns nothing
    set udg_NAME_SLOT1 = GetItemLevel(UnitItemInSlotBJ(udg_HERO, 1))
    set udg_UNIT_ITEMTYPE[1] = 'Hpal'
    set udg_UNIT_ITEMTYPE[2] = 'Hamg'
    set udg_UNIT_ITEMTYPE[3] = 'Hblm'
    call CreateNUnitsAtLoc( 1, udg_UNIT_ITEMTYPE[udg_NAME_SLOT1], Player(0), GetRectCenter(GetPlayableMapRect()), bj_UNIT_FACING )
endfunction

//===========================================================================
function InitTrig_SET_SLOT_1 takes nothing returns nothing
    set gg_trg_SET_SLOT_1 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_SET_SLOT_1, function Trig_SET_SLOT_1_Actions )
endfunction
 
You could use Hashtables this ones allows to save/Load by using any Numbers including Unit Handles or Item/Unit Types.

  • Initialisierung
    • Ereignisse
      • Map initialization
    • Bedingungen
    • Aktionen
      • Hashtabelle - Create a hashtable
      • Set Hashtabel = (Last created hashtable)
      • Set Item_Type = Klauen des Angriffs +15
      • Set Unit_Type = Soldat
      • Custom script: call SaveIntegerBJ( udg_Item_Type, 0, udg_Unit_Type, udg_Hashtabel )
      • Custom script: call SaveIntegerBJ( udg_Unit_Type, 0, udg_Item_Type, udg_Hashtabel )
  • Load UnitType by ItemType
    • Ereignisse
    • Bedingungen
    • Aktionen
      • Set Item_Type = (Item-type of (Item carried by Paladin 0000 <gen> in slot 1))
      • Custom script: set udg_Unit_Type = LoadIntegerBJ(0, udg_Item_Type, udg_Hashtabel)
      • Unit - Create 1 Unit_Type for Spieler 1 (Rot) at Loc facing Vorgabe 270 degrees
If you use the GUI Hashtable access you need to convert Unit/Item Types to Integer and than can use the provided Hastable actions.

  • Initialisierung with Converting
    • Events
      • Map initialization
    • Bedingungen
    • Actions
      • Hashtabelle - Create a hashtable
      • Set Hashtabel = (Last created hashtable)
      • Set Item_Type = Claws of Attack +15
      • Custom script: set udg_Item_Type_ID = udg_Item_Type
      • Set Unit_Type = Footmen
      • Custom script: set udg_Unit_Type_ID = udg_Unit_Type
      • -------- Bothsided, but would not be needed. --------
      • Hashtabelle - Save Unit_Type_ID as 0 of Item_Type_ID in Hashtabel
      • Hashtabelle - Save Item_Type_ID as 0 of Unit_Type_ID in Hashtabel
  • Load UnitType by ItemType with converting
    • Ereignisse
    • Bedingungen
    • Actions
      • Set Item_Type = (Item-type of (Item carried by Hero in slot 1))
      • Custom script: set udg_Item_Type_ID = udg_Item_Type
      • Set Unit_Type_ID = (Load 0 of Item_Type_ID from Hashtabel)
      • Custom script: set udg_Unit_Type = udg_Unit_Type_ID
      • Unit - Create 1 Unit_Type for Player 1 (Rot) at Loc facing Vorgabe 270 degrees
Edit: Here a Testmap showing this with two items, Press Esc to Summon an unit, depending on the item in slot 1. Claws summon Footmen Kelens dagger summons Knights
 

Attachments

  • WorldEditTestMap.w3x
    17.2 KB · Views: 15
Last edited:
Status
Not open for further replies.
Top