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

Both sides previous revision Previous revision
Next revision
Previous revision
hpl2:tutorials:script:scripting_by_xtron_-_item_that_unlocks_a_door [2011/07/13 18:24]
xtron
hpl2:tutorials:script:scripting_by_xtron_-_item_that_unlocks_a_door [2013/08/22 15:12] (current)
yourcomputer Corrected references
Line 2: Line 2:
  
  
-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!.+In this tutorial will I ( xtron ) show you how to make a item that unlocks a specific door!.
  
  
-**\\  **  +==== THE DOOR ====
- +
- +
-**THE DOOR:** +
  
  
Line 23: Line 20:
  
  
-**THE ITEM:\\  ** +==== THE ITEM ==== 
  
  
Line 42: Line 39:
  
 <code text> <code text>
-<​CATEGORY Name="​Inventory">​ +<​CATEGORY Name="​Inventory">​  
-  +    <Entry Name="​ItemDesc_item1">​Item description</​Entry>​ 
-  +    <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>​
Line 59: 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]] change NAME.hps to your +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.
- +
- +
-map name.+
  
  
Line 71: Line 61:
  
  
-<code cpp> +<code cpp>void OnStart()
-  +
-void OnStart() +
-  +
- +
 { {
-  +    ​AddUseItemCallback("",​ "​ITEM",​ "​DOOR",​ "​FUNCTION",​ true);
-  +
-**AddUseItemCallback("",​ "​ITEM",​ "​DOOR",​ "​FUNCTION",​ true);**  +
-  +
- +
 } }
 </​code>​ </​code>​
Line 92: Line 74:
  
  
-<code cpp> +<code cpp>void FUNCTION(string &in asItem, string &in asEntity)
-  +
-void FUNCTION(string &in asItem, string &in asEntity)+
 { {
-    SetSwingDoorLocked("​DOOR"​, false, true); +    SetSwingDoorLocked(asEntity, false, true); 
-    PlaySoundAtEntity("",​ "​unlock_door", ​"​door1"​, 0, false); +    PlaySoundAtEntity("",​ "​unlock_door", ​asEntity, 0, false); 
-    RemoveItem("​ITEM"​);+    RemoveItem(asItem);
 } }
-  
-  
-  
 </​code>​ </​code>​
  
Line 109: Line 86:
  
  
-<code cpp>+<code cpp>void OnStart() 
 +
 +  
 +
 +</code>
  
  
-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:
  
  
 +<code cpp>void OnStart()
 +{
 +    AddUseItemCallback("",​ "​ITEM",​ "​DOOR",​ "​FUNCTION",​ true);
 } }
-</​code>​\\  ​+  
 +void FUNCTION(string &in asItem, string &in asEntity) 
 +
 +    SetSwingDoorLocked(asEntity,​ false, true); 
 +    PlaySoundAtEntity("",​ "​unlock_door",​ asEntity, 0, false); 
 +    RemoveItem(asItem);​ 
 +
 +  
 +</​code>​
  
  
-//\\  // +The best way of doing this kind of script is by using the syntaxes asItem and asEntity to your advantage
  
  
-Change ​the FUNCTIONNAME to the function ​name you picked in the previous step. +so instead of writing ​the name of the door and key inside ​the function like the one above you write something like this:
- +
- +
-Change the DOOR to your door name and then the ITEM to your item name and then it's all done!. +
- +
- +
-When you're done it should look something like this:+
  
  
 <code cpp> <code cpp>
-  
 void OnStart() void OnStart()
-  
 { {
-  + AddUseItemCallback("",​ "NAMEOFTHEITEM", "NAMEOFTHEDOOR", "​FUNCTION",​ true);
-AddUseItemCallback("",​ "ITEM", "DOOR", "​FUNCTION",​ true); +
- +
 } }
-  +
- +
 void FUNCTION(string &in asItem, string &in asEntity) void FUNCTION(string &in asItem, string &in asEntity)
 { {
-    ​SetSwingDoorLocked("​DOOR"​, false, true); + SetSwingDoorLocked(asEntity, false, true); 
-    PlaySoundAtEntity("",​ "​unlock_door", ​"​door1"​, 0, false); + PlaySoundAtEntity("",​ "​unlock_door", ​asEntity, 0, false); 
-    RemoveItem("​ITEM"​);+ RemoveItem(asItem);
 } }
-  
 </​code>​ </​code>​
 +
 +
 +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.
  
  
Line 158: Line 144:
  
  
-Created by xtron+Created by xtron<font 16pt:​normal/​Arial;;​inherit;;​inherit ​  >​\\  
 +</​font>​
  
  
-<​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.1310581454.txt.gz · Last modified: 2011/07/13 18:24 by xtron