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
Last revision Both sides next revision
hpl2:tutorials:script:scripting_by_xtron_-_item_that_unlocks_a_door [2011/12/22 14:11]
yourcomputer
hpl2:tutorials:script:scripting_by_xtron_-_item_that_unlocks_a_door [2012/06/23 16:11]
silentstriker [THE SCRIPT]
Line 74: Line 74:
  
  
-<code cpp>void FUNCTION(string &​in ​item, string &​in ​door)+<code cpp>void FUNCTION(string &​in ​asItem, string &​in ​asEntity)
 { {
     SetSwingDoorLocked(door,​ false, true);     SetSwingDoorLocked(door,​ false, true);
Line 88: Line 88:
 <code cpp>void OnStart() <code cpp>void OnStart()
 { {
 + 
 } }
 </​code>​ </​code>​
 +
  
 Change the FUNCTIONNAME to the function name you picked in the previous step. Change the FUNCTIONNAME to the function name you picked in the previous step.
 +
  
 When you're done it should look something like this: When you're done it should look something like this:
Line 102: Line 104:
 } }
    
-void FUNCTION(string &​in ​item, string &​in ​door)+void FUNCTION(string &​in ​asItem, string &​in ​asEntity)
 { {
     SetSwingDoorLocked(door,​ false, true);     SetSwingDoorLocked(door,​ false, true);
Line 110: Line 112:
    
 </​code>​ </​code>​
 +
 +
 +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:
 +
 +
 +<​code>​
 +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>​
 +
 +
 +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 115: 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.txt · Last modified: 2013/08/22 15:12 by yourcomputer