[Trigger] Door Key System

Level 6
Joined
May 26, 2010
Messages
213
  • House 1
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
      • (Item-type of (Sold Item)) Equal to |cffffcc00Buy House|r
      • (Selling unit) Equal to Home Dealership [House] 0003 <gen>
    • Actions
      • Item - Remove (Sold Item)
      • Hero - Create Key and give it to (Buying unit)
      • Set Key[1] = (Last created item)
      • Unit - Hide Home Dealership [House] 0003 <gen>
  • House 1 Key
    • Events
      • Unit - A unit Uses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Key
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item being manipulated) Equal to Key[1]
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Target destructible of ability being cast) Equal to Door (Horizontal) 0315 <gen>
            • Then - Actions
              • Destructible - Open Door (Horizontal) 0315 <gen>
            • Else - Actions
        • Else - Actions
I know it is only for one house right now and I am going to fix that after I get it working. It is meant to open a certain door once a certain key is used on it. The ability variant for the item I'm using is firebolt targeting debris.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Createa Destructible Array and a ItemType Array

Match the index of the keys with their corresponding door, i mean

Key[1] opens door[1], and so on.

Then you just need to detect the index of the Key and check if the Door[Index] is the same destructible where it has been used.
 
Level 6
Joined
May 26, 2010
Messages
213
It's still not working...
  • House 1
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
      • (Item-type of (Sold Item)) Equal to |cffffcc00Buy House|r
      • (Selling unit) Equal to Home Dealership [House] 0003 <gen>
    • Actions
      • Item - Remove (Sold Item)
      • Hero - Create Key and give it to (Buying unit)
      • Set Key[1] = (Last created item)
      • Unit - Hide Home Dealership [House] 0003 <gen>
  • House Open
    • Events
      • Unit - A unit Uses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Key
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item being manipulated) Equal to Key[1]
          • (Target destructible of ability being cast) Equal to Key_Door[1]
        • Then - Actions
          • Destructible - Open Key_Door[1]
        • Else - Actions
  • Door Arrays
    • Events
      • Time - Elapsed game time is 0.01 seconds
    • Conditions
    • Actions
      • Set Key_Door[1] = Door (Horizontal) 0315 <gen>
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
  • KeySell
  • Event
    • A unit Sells an item (from shop)
  • Conditions
    • (Item-type of (Sold Item)) Equal to |cffffcc00Buy House|r
    • (Selling unit) Equal to Home Dealership [House] 0003 <gen>
  • Actions
    • Set KeyDoorIndex = KeyDoorIndex + 1
    • Item - Remove (Sold Item)
    • Hero - Create Key and give it to (Buying unit)
    • Set Key[KeyDoorIndex] = (Last created item)
    • Unit - Hide Home Dealership [House] 0003 <gen>
  • House Open
  • Events
    • Unit - A unit Uses an item
  • Conditions
    • (Item-type of (Item being manipulated)) Equal to Key
  • Actions
    • Set item = (Item Being manipulated)
    • For Each Integer A from 1 to KeyDoorIndex do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Key[(Integer A)] equal to Item
          • Then - Actions
            • Set i = (Integer A)
            • Custom script: set bj_forLoopAIndex = udg_KeyDoorIndex
          • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Target destructible of ability being cast) Equal to Key_Door[i]
      • Then - Actions
        • Destructible - Open Key_Door[i] << EDIT: This was "1" and has to be "i" as it's now. I just fixed it >>
      • Else - Actions
 
Last edited:
Level 17
Joined
Jul 17, 2011
Messages
1,864
^ that sorta works all you need to do is put all the doors and items into arrays and then just compare when:

your unit casts firebolt,

if the target door = door 1

then does the caster have a specific item? (the key)


basically just match the keys with the doors...
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Should work now :) I edited the trigger. it had a serious mistake. It had [1] and should have as now.

Be aware that your other trigger, the one that sets "Key_Door[1] = Destructible0315" was ok.

We could do a test map, but would be exactly as the shown triggers, so, no.
 
Level 6
Joined
May 26, 2010
Messages
213
What am I doing wrong??? I turned off every other trigger and it still won't work... Please help! :vw_wtf:

  • Key Sell
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
      • (Item-type of (Sold Item)) Equal to |cffffcc00Buy House|r
      • (Selling unit) Equal to Home Dealership [House] 0003 <gen>
    • Actions
      • Set KeyDoorIndex = (KeyDoorIndex + 1)
      • Item - Remove (Sold Item)
      • Hero - Create Key and give it to (Buying unit)
      • Set Key[KeyDoorIndex] = (Last created item)
      • Unit - Hide Home Dealership [House] 0003 <gen>
  • House Open
    • Events
      • Unit - A unit Uses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Key
    • Actions
      • Set Item = (Item being manipulated)
      • For each (Integer A) from 1 to KeyDoorIndex, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Key[(Integer A)] Equal to Item
            • Then - Actions
              • Set i = (Integer A)
              • Custom script: set bj_forLoopAIndex = udg_KeyDoorIndex
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Target destructible of ability being cast) Equal to Key_Door[i]
        • Then - Actions
          • Destructible - Open Key_Door[i]
        • Else - Actions
  • Door Arrays
    • Events
      • Time - Elapsed game time is 0.01 seconds
    • Conditions
    • Actions
      • Set KeyDoorIndex = 0
      • Set Key_Door[1] = Door (Horizontal) 0315 <gen>
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Well.. the problem is that There's no "Target Destructible of ability being cast" since the event is "Uses an Item". Using that item means using an ability, but the event you're using doesn't care about that.

You have to use "A unit is given an order trargeting an object", detect if the unit has the correct key (the same way we already did) and use "Target destructible of Issued ORder

Another way would be with "A unit starts the effect of an ability" detect if the unit has the correct key (The same way we already did) and use "Target destructible of ability being cast".

Now, in both cases, the unit can be using another key (Lets say, Key[20]), but holding the correct key (Key[4]), and it will open the Door[4] and so on.
 
Level 6
Joined
May 26, 2010
Messages
213
Whats wrong with this??? I tried making it like you said.

  • House Open
    • Events
      • Unit - A unit Finishes casting an ability
    • Conditions
      • (Ability being cast) Equal to Open Door
      • (Item-type of (Item carried by (Triggering unit) of type Key)) Equal to Key
    • Actions
      • Set Item = (Item carried by (Triggering unit) of type Key)
      • For each (Integer A) from 1 to KeyDoorIndex, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Key[(Integer A)] Equal to Item
            • Then - Actions
              • Set i = (Integer A)
              • Custom script: set bj_forLoopAIndex = udg_KeyDoorIndex
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Target destructible of ability being cast) Equal to Key_Door[i]
        • Then - Actions
          • Destructible - Open Key_Door[i]
        • Else - Actions
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Use: A unit starts the effect of an ability
Of course, the Ability the item has to have is "Open Door"

Remove the "(Item-type of (Item carried by (Triggering unit) of type Key)) Equal to Key" condition. There's no use, since only Keys have the "Open Door" ability.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Eeeh... The order in which the Keys are sold is unique, i mean... Everytime a Key is sold, the KeyDoorIndex is increased by 1, and That only key will work for only one pre-assigned door in the Door array.

So, the 4th sold key, will open the Door[4].
 
Level 6
Joined
May 26, 2010
Messages
213
I think this should fix it, but it would need a separate spell for each house sold.
  • Key Sell House 1
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
      • (Item-type of (Sold Item)) Equal to |cffffcc00Buy House|r
      • (Selling unit) Equal to Home Dealership [House] 0003 <gen>
    • Actions
      • Set KeyDoorIndex = (KeyDoorIndex + 1)
      • Item - Remove (Sold Item)
      • Hero - Create Key and give it to (Buying unit)
      • Set Key[KeyDoorIndex] = (Last created item)
      • Set Key_Door[KeyDoorIndex] = Door (Horizontal) 0315 <gen>
      • Unit - Hide Home Dealership [House] 0003 <gen>
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
mmm No. It's not the best way.

Do these bot on Map Initialization:
· Create an ItemType array and store all the Keys (You need a different "Key" item for each house)
· Create a Destructible array and match the Key index with the corresponding Door index.

Then compare both indexes as we have already done, if they match, open the door. You no longer need the KeyDoorIndex variable, neither Set Key[KeyDoorIndex] = (last created item), since all the keys and doors are pre-set on map init.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
The Item-Type of each key is unique. Item-Type (Key, Helm, Claws, etc.) is not the same than Item (Picked Item, Last created item, etc.) Item types can be set on map init, as same as destructibles.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
The difference between Item-Type and Item is the same difference than Unit-Types have with Units.

Footman is a Unit-Type, while (Triggering Unit) is a unit.

Item-Type means Helm of Dominator, Claws of Attack+12, Claws of Attack+6, etc. All these are "Item-Types"

What You need to do is create Different Item-Types, each one as a "Key". Then on map initialization, using an Item-Type variable, you set Key[1] = Key1, and so on.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Sort of... You can also use Hashtables.

You have to create 1Key and 1OpenDoor ability for each door.
Then you add Each Key, it's corresponding "Open Door" ability
On map initialization you save the HandleID of each door on it's corresponding Ability (call SaveInteger(udg_Hashtable, AbilityID, 0, DestructibleID).

When you use the Item Ability On the Destructible, you Load 0 of AbilityID and compare it with the target destructible of ability being cast, if it match, open the door.

The Item is just to hold the correct ability.

There are many many ways of doing this... Using the Hashtable or using the Arrays are the best I can think of.
 
Top