User Tools

Site Tools


hpl2:tutorials:script:scripting_by_xtron_-_item_that_unlocks_a_door

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
hpl2:tutorials:script:scripting_by_xtron_-_item_that_unlocks_a_door [2011/07/13 17:32]
xtron created
hpl2:tutorials:script:scripting_by_xtron_-_item_that_unlocks_a_door [2013/08/22 15:12] (current)
yourcomputer Corrected references
Line 1: Line 1:
-In this tutorial ( the first one actually ) will I ( xtron ) show you! ( the person who reads this ) how to make a item that unlocks a specific ​door!.+====== Item that unlocks a door ======
  
  
-**\\  ** +In this tutorial will I ( xtron ) show you how to make a item that unlocks a specific door!.
  
  
-**THE DOOR:** +==== THE DOOR ====
  
  
Line 20: Line 20:
  
  
-**THE ITEM:\\  ** +==== THE ITEM ==== 
  
  
Line 26: Line 26:
  
  
-//Entities (7) > Item > And take a pick.// ​ +//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)
-Change the name of the item you chose. +
-(A key is the smartest choice for a door but other items will make it rare)+
  
  
Line 41: Line 39:
  
 <code text> <code text>
- +<​CATEGORY Name="​Inventory">​  
- +    <Entry Name="​ItemDesc_item1">​Item description</​Entry>​ 
-<​CATEGORY Name="​Inventory">​ +    <Entry Name="​ItemName_item1">​Item name</​Entry>​
- +
- +
-<Entry Name="​ItemDesc_item1">​Item description</​Entry>​ +
-<Entry Name="​ItemName_item1">​Item name</​Entry>​ +
- +
 </​CATEGORY>​ </​CATEGORY>​
 </​code>​ </​code>​
  
  
-replace item1 with the name you chose in "​CustomSubItemTypeName"​ in the editor and change the name and description to what ever you +replace item1 with the name you chose in "​CustomSubItemTypeName"​ in the editor and change the name and description to what ever you
  
  
Line 60: Line 52:
  
  
-**THE SCRIPT:** +==== THE SCRIPT ​====
  
  
-First off you will need a .hps file and I guess you already have it but to be sure [[http://​www.mediafire.com/?​krxqcj3qdxrj9xs|wClean HPS FILE]] ​\\  ​+First off you will need a .hps file and I guess you already have it but to be sure [[http://​www.mediafire.com/?​krxqcj3qdxrj9xs|wClean HPS FILE]] ​change NAME.hps to your map name.
  
  
-| \\ void OnStart() ​\\  \\ { \\  \\ AddUseItemCallback("",​ "​ITEM",​ "​DOOR",​ "​FUNCTIONNAME",​ true); \\  \\ \\  |+Now you need the code that will be inserted betwen ​void OnStart()s brackets ​{ and )
  
  
-\\  ​+<code cpp>void OnStart() 
 +
 +    AddUseItemCallback("",​ "​ITEM",​ "​DOOR",​ "​FUNCTION",​ true); 
 +
 +</​code>​
  
  
-I'm assuming that you're using the .hps file I uploaded. Copy the AddUseItemCallBack script in to your .hps file inside the brackets were it say\\  ​+Change ITEM to your item, DOOR to your door name and FUNCTION can be whatever.
  
  
-void OnStart. Just like in the box. Edit the ITEM to your item name and then the DOOR to your door name and the function ​name can be+When you done that you will be needing ​the function
  
  
-anything. ​+<code cpp>void FUNCTION(string &in asItem, string &in asEntity) 
 +
 +    SetSwingDoorLocked(asEntity,​ false, true); 
 +    PlaySoundAtEntity("",​ "​unlock_door",​ asEntity, 0, false); 
 +    RemoveItem(asItem);​ 
 +
 +</​code>​
  
  
-When you're done with that +and insert it anywhere but
-you can copy the:+
  
  
-| \\ void FUNCTIONNAME(string &in asItem, string &in asEntity\\ \\ SetSwingDoorLocked("​DOOR",​ false, true); \\ PlaySoundAtEntity("",​ "​unlock_door",​ "​door1",​ 0, false); \\ RemoveItem("​ITEM"​);​ \\ \\  |+<code cpp>void OnStart() 
 +{ 
 +  
 +} 
 +</​code>​
  
  
-and insert it anywhere but+Change the FUNCTIONNAME to the function name you picked in the previous step.
  
  
-| \\ void OnStart() \\  \\ { \\  \\ } \\  |+When you're done it should look something like this:
  
  
-Change the FUNCTIONNAME to the function name you picked ​in the previous step.+<code cpp>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);​ 
 +
 +  
 +</​code>​
  
  
-Change ​the DOOR to your door name and then the ITEM to your item name and then it's all done!.+The best way of doing this kind of script is by using the syntaxes asItem ​and asEntity ​to your advantage
  
  
-When you're done it should look something like this:+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("",​ "ITEM", "DOOR", "​FUNCTION",​ true); ​\\  \\ \\  \\  \\  \\ void FUNCTION(string &in asItem, string &in asEntity) ​\\ \\ SetSwingDoorLocked("​DOOR"​, false, true); ​\\ PlaySoundAtEntity("",​ "​unlock_door", ​"​door1"​, 0, false); ​\\ RemoveItem("​ITEM"​); \\ \\  |+<code cpp> 
 +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); 
 +} 
 +</​code>​
  
  
-If you got any questions please PM me on the forum or contact me through ​msn+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.
  
  
-===== mattias_dionysus@hotmail.com =====+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.
  
  
-Created by xtron+If you got any questions please PM me on the forum
  
  
-<font 16pt:​normal/​Arial;;​inherit;;​inherit>​\\ ​ </​font> ​+Created by xtron<font 16pt:​normal/​Arial;;​inherit;;​inherit ​  ​>​\\ ​ 
 +</​font>​
  
  
-\\+<font 10pt:​normal/​Arial;;​inherit;;​inherit ​   >Edited by SilentStriker</​font>​
  
hpl2/tutorials/script/scripting_by_xtron_-_item_that_unlocks_a_door.1310578355.txt.gz · Last modified: 2011/07/13 17:32 by xtron