Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Request How to make several keys in on map
Khan Offline
Member

Posts: 61
Threads: 12
Joined: Aug 2011
Reputation: 0
#1
How to make several keys in on map

kk, so I have a key already, but, I dont know to make another key, can anyone help me here? lol. Here is wat my .hps looks like.

////////////////////////////
// Run when entering map
void OnEnter()
{
AddUseItemCallback("", "chamberkey", "chamberdoor", "FUNCTION", true);
AddEntityCollideCallback("Player", "script_slam", "func_slam", true, 1);
AddEntityCollideCallback("Player" , "doorbreak" , "MonsterFunc1" , true , 1);
AddEntityCollideCallback("Player", "doorslamtrigger1", "Func01", true, 1);
}
void FUNCTION(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("chamberdoor", false, true);
PlaySoundAtEntity("", "unlock_door", "door1", 0, false);
RemoveItem("chamberkey");
SetSwingDoorClosed("doorslam", true, true);
SetSwingDoorClosed("doorslam2", true, true);


As you can see, I have a key already, but I dont know how to make another, I cut off part of the script as to hide the other, surprises, in my custom story. any ideas?
08-17-2011, 03:51 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#2
RE: How to make several keys in on map

The game relies on the name of these entities. Just change the name for each key and have conditional statements for each key.

Tutorials: From Noob to Pro
08-17-2011, 03:57 AM
Website Find
Khan Offline
Member

Posts: 61
Threads: 12
Joined: Aug 2011
Reputation: 0
#3
RE: How to make several keys in on map

Im a complete nooby to scripting, so, I have no clue half of wat you said, lol ;(
08-17-2011, 04:27 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#4
RE: How to make several keys in on map

(08-17-2011, 04:27 AM)Khan Wrote: Im a complete nooby to scripting, so, I have no clue half of wat you said, lol ;(

Tongue

As you should already know, AddUseItemCallback() calls a function upon using an item on another entity. In your case this is FUNCTION(). The variables passed to this function contain the names of the entities that were interacted with. In your case, asItem would contain the name of the key; asEntity would contain the name of the door. A conditional statement is a statement that requires its expression (that which is inside its parentheses) to evaluate to true (boolean) before executing the code in the code block below it. The if statement is therefore a conditional statement.

In your FUNCTION() function, you would place conditional statements to check whether or not asItem contains the name of the key used and whether or not asEntity contains the name of the door you want the key to work on. This allows the same function to be used for multiple keys. It would also allow for the same key to be used on multiple doors.

Example:
void FUNCTION(string &in asItem, string &in asEntity)
{
     if (asItem == "chamberkey" && asEntity == "chamberdoor")
     {
          // unlock door and remove key from inventory
     }

     else if (asItem == "cellarkey" && asEntity == "cellardoor")
     {
          // unlock door and remove key from inventory
     }
}

In the level editor you would name the keys and doors accordingly. If you want any key to be used on any door, then remove the second half of the if statement's expression and don't remove the key from inventory.

Tutorials: From Noob to Pro
(This post was last modified: 08-17-2011, 05:07 AM by Your Computer.)
08-17-2011, 05:00 AM
Website Find
Khan Offline
Member

Posts: 61
Threads: 12
Joined: Aug 2011
Reputation: 0
#5
RE: How to make several keys in on map

I think I messed up :|

////////////////////////////
// Run when entering map
void OnEnter()
{
AddUseItemCallback("", "chamberkey", "chamberdoor", "FUNCTION", true);
AddUseItemCallback("", "cellerkey", "cellerdoor", "FUNCTION", true);
AddEntityCollideCallback("Player", "script_slam", "func_slam", true, 1);
AddEntityCollideCallback("Player" , "doorbreak" , "MonsterFunc1" , true , 1);
AddEntityCollideCallback("Player", "doorslamtrigger1", "Func01", true, 1);
}
void FUNCTION(string &in "chamberkey", string &in "chamberdoor")
{
SetSwingDoorLocked("chamberdoor", false, true);
PlaySoundAtEntity("", "unlock_door", "door1", 0, false);
RemoveItem("chamberkey");
SetSwingDoorClosed("doorslam", true, true);
SetSwingDoorClosed("doorslam2", true, true);
}
void FUNCTION(string &in "cellerkey", string &in "cellerdoor"
{
SetSwingDoorLocked("cellerdoor", false, true);
PlaySoundAtEntity("", "unlock_door", "door1", 0, false);
RemoveItem("cellarkey);
}

I have like, no idea wat Im doing, so I tried wat I THOUGHT would work, it didint, now my game crashes when I try to start it ;(
08-17-2011, 01:16 PM
Find
Obliviator27 Offline
Posting Freak

Posts: 792
Threads: 10
Joined: Jul 2011
Reputation: 66
#6
RE: How to make several keys in on map

////////////////////////////
// Run when entering map
void OnEnter()
{
   AddUseItemCallback("", "chamberkey", "chamberdoor", "FUNCTION1", true);
   AddUseItemCallback("", "cellarkey", "cellerdoor", "FUNCTION2", true);
   AddEntityCollideCallback("Player", "script_slam", "func_slam", true, 1);
   AddEntityCollideCallback("Player" , "doorbreak" , "MonsterFunc1" , true , 1);    
   AddEntityCollideCallback("Player", "doorslamtrigger1", "Func01", true, 1);    
}
void FUNCTION1(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("chamberdoor", false, true);
    PlaySoundAtEntity("", "unlock_door", "chamberdoor", 0, false);
    RemoveItem("chamberkey");
    SetSwingDoorClosed("doorslam", true, true);
    SetSwingDoorClosed("doorslam2", true, true);
}
void FUNCTION2(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("cellerdoor", false, true);
    PlaySoundAtEntity("", "unlock_door", "cellerdoor", 0, false);
    RemoveItem("cellarkey");
}

void OnEnter()
{
}

void OnLeave
{
}
Right, so this code should work for you. I'll let you know what you missed
1) Your syntax was incorrect for your functions. For AddUseItemCallback, you need to end your callback function with (string &in asItem, string &in asEntity). The wikipage shows the correct syntax for callback functions, as well as timers and the like. They're bolded underneath the function.
2) If you want two separate doors to unlock, you need to name the unlock functions accordingly. I changed it up to Function1 and Function2. Of course, you could also use a subroutine, but I left it simple.
3) You forgot to put closing quotation marks around cellarkey in Function2, as well as spelling it differently.
4) All .hps files need to have a OnEnter and OnLeave function. You can leave these empty if you wish, as they only perform functions when the player enters or leaves the map


08-17-2011, 06:49 PM
Find
Khan Offline
Member

Posts: 61
Threads: 12
Joined: Aug 2011
Reputation: 0
#7
RE: How to make several keys in on map

(08-17-2011, 06:49 PM)Obliviator27 Wrote:
////////////////////////////
// Run when entering map
void OnEnter()
{
   AddUseItemCallback("", "chamberkey", "chamberdoor", "FUNCTION1", true);
   AddUseItemCallback("", "cellarkey", "cellerdoor", "FUNCTION2", true);
   AddEntityCollideCallback("Player", "script_slam", "func_slam", true, 1);
   AddEntityCollideCallback("Player" , "doorbreak" , "MonsterFunc1" , true , 1);    
   AddEntityCollideCallback("Player", "doorslamtrigger1", "Func01", true, 1);    
}
void FUNCTION1(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("chamberdoor", false, true);
    PlaySoundAtEntity("", "unlock_door", "chamberdoor", 0, false);
    RemoveItem("chamberkey");
    SetSwingDoorClosed("doorslam", true, true);
    SetSwingDoorClosed("doorslam2", true, true);
}
void FUNCTION2(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("cellerdoor", false, true);
    PlaySoundAtEntity("", "unlock_door", "cellerdoor", 0, false);
    RemoveItem("cellarkey");
}

void OnEnter()
{
}

void OnLeave
{
}
Right, so this code should work for you. I'll let you know what you missed
1) Your syntax was incorrect for your functions. For AddUseItemCallback, you need to end your callback function with (string &in asItem, string &in asEntity). The wikipage shows the correct syntax for callback functions, as well as timers and the like. They're bolded underneath the function.
2) If you want two separate doors to unlock, you need to name the unlock functions accordingly. I changed it up to Function1 and Function2. Of course, you could also use a subroutine, but I left it simple.
3) You forgot to put closing quotation marks around cellarkey in Function2, as well as spelling it differently.
4) All .hps files need to have a OnEnter and OnLeave function. You can leave these empty if you wish, as they only perform functions when the player enters or leaves the map

Thanks, but I got it working like 2 hours ago, lol, yea, I figured wat I did wrong, took me FOREVER tinkering with it, and I had some help from other people, and I cut half the .hps file out for my custom story Im making, didint wanna, ruin the surprises ;P
08-17-2011, 09:01 PM
Find




Users browsing this thread: 1 Guest(s)