1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] Door Key System

Discussion in 'Triggers & Scripts' started by Kunfury, Aug 14, 2012.

  1. Kunfury

    Kunfury

    Joined:
    May 26, 2010
    Messages:
    211
    Resources:
    0
    Resources:
    0
    • 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.
     
  2. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    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.
     
  3. Kunfury

    Kunfury

    Joined:
    May 26, 2010
    Messages:
    211
    Resources:
    0
    Resources:
    0
    I am using two types of doors, will it still work?
     
  4. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    Doesn't matter, as long as the Index of the Key and the Door are the same.
     
  5. Kunfury

    Kunfury

    Joined:
    May 26, 2010
    Messages:
    211
    Resources:
    0
    Resources:
    0
    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>
     
  6. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    • 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: Aug 17, 2012
  7. gorillabull

    gorillabull

    Joined:
    Jul 17, 2011
    Messages:
    1,367
    Resources:
    2
    Spells:
    2
    Resources:
    2
    ^ 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...
     
  8. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    That's what my trigger does. The "hard" part is detecting the index of the door.
     
  9. Kunfury

    Kunfury

    Joined:
    May 26, 2010
    Messages:
    211
    Resources:
    0
    Resources:
    0
    It STILL isn't working, can you please make a testmap of it and upload it here?
     
  10. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    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.
     
  11. Kunfury

    Kunfury

    Joined:
    May 26, 2010
    Messages:
    211
    Resources:
    0
    Resources:
    0
    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>
     
  12. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    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.
     
  13. Kunfury

    Kunfury

    Joined:
    May 26, 2010
    Messages:
    211
    Resources:
    0
    Resources:
    0
    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
     
  14. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    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.
     
  15. Kunfury

    Kunfury

    Joined:
    May 26, 2010
    Messages:
    211
    Resources:
    0
    Resources:
    0
    Thank you so much!!!!

    Edit: Wait would this work if they bought the houses out of order? Like someone bought House #1 then went and bought House #4
     
    Last edited: Aug 18, 2012
  16. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    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].
     
  17. Kunfury

    Kunfury

    Joined:
    May 26, 2010
    Messages:
    211
    Resources:
    0
    Resources:
    0
    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>
     
  18. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    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.
     
  19. Kunfury

    Kunfury

    Joined:
    May 26, 2010
    Messages:
    211
    Resources:
    0
    Resources:
    0
    The keys are not there on map initialization, they are created when a player buys the house.
     
  20. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    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.