In this tutorial will I ( xtron ) show you how to make a item that unlocks a specific door!.
You will need to create that lovely little door by doing like this:
Entities (7) > Door > Select a door that you want to use and change the name of it.
When you're done adding this door you will need to lock it by doing like this:
Press the door you want to lock > Entity > Check the “Locked” box.
To unlock your door you will need an item, it could be anything from the item tab, do like this:
Entities (7) > Item > And take a pick. Change the name of the item you chose. (A key is the smartest choice for a door but other items will make it rare)
If you want a name for your item (OPTIONAL):
Click on your item > Entity > At the bottom there's a box named “CustomSubItemTypeName” You can type anything, don't have to be the key name.
Open your extra_lang and add this code (if you don't already have it ofcourse)
<CATEGORY Name="Inventory"> <Entry Name="ItemDesc_item1">Item description</Entry> <Entry Name="ItemName_item1">Item name</Entry> </CATEGORY>
replace item1 with the name you chose in “CustomSubItemTypeName” in the editor and change the name and description to what ever you
want.
First off you will need a .hps file and I guess you already have it but to be sure wClean HPS FILE change NAME.hps to your map name.
Now you need the code that will be inserted betwen void OnStart()s brackets ( { and } )
void OnStart() { AddUseItemCallback("", "ITEM", "DOOR", "FUNCTION", true); }
Change ITEM to your item, DOOR to your door name and FUNCTION can be whatever.
When you done that you will be needing the function
void FUNCTION(string &in asItem, string &in asEntity) { SetSwingDoorLocked(asEntity, false, true); PlaySoundAtEntity("", "unlock_door", asEntity, 0, false); RemoveItem(asItem); }
and insert it anywhere but
void OnStart() { }
Change the FUNCTIONNAME to the function name you picked in the previous step.
When you're done it should look something like this:
void OnStart() { AddUseItemCallback("", "ITEM", "DOOR", "FUNCTION", true); } void FUNCTION(string &in asItem, string &in asEntity) { SetSwingDoorLocked(asEntity, false, true); PlaySoundAtEntity("", "unlock_door", asEntity, 0, false); RemoveItem(asItem); }
The best way of doing this kind of script is by using the syntaxes asItem and asEntity to your advantage
so instead of writing the name of the door and key inside the function like the one above you write something like this:
void OnStart() { AddUseItemCallback("", "NAMEOFTHEITEM", "NAMEOFTHEDOOR", "FUNCTION", true); } void FUNCTION(string &in asItem, string &in asEntity) { SetSwingDoorLocked(asEntity, false, true); PlaySoundAtEntity("", "unlock_door", asEntity, 0, false); RemoveItem(asItem); }
So this works since asEntity is declared as the name of the door and the asItem is declared as the item you want to use on the door through the AddUseItemCallback.
So by using this code you can write more AddUseItemCallback and call the same function and they will unlock their corresponding door with the corresponding item.
If you got any questions please PM me on the forum
Created by xtron
Edited by SilentStriker