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
Script Help [SOLVED] Using a Single Crowbar on Multiple Doors
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#7
RE: Using a Single Crowbar on Multiple Doors

You're getting closer but not all the way.

I'm very sorry about this but
WALL OF TEXT INCOMING!
I felt inspired to help you ^^

See, in the beginning you wrote:

PHP Code: (Select All)
void OnStart()
{  
    
AddUseItemCallback("""Crowbar_1""asEntity""UseCrowbarOnDoor"true);
    
AddEntityCollideCallback("Joint""AreaBreak""BreakDoor"true1);


You used "asEntity" as the entity. This will not work, and there's a simple explanation.

asEntity, is referring to the parameters in a function.
Fx. when using a collide-function you write:

void CollideFunction(string &in asParent, string &in asChild, int alState)

Notice all the things inside the paranthesises! ^^^^^
You have 3 different parameters here: asParent, asChild and alState.
asParent and asChild has "string" in front of them, because you have to use a word.
alState has "int" in front of it, because it's a whole number, without decimals (1, 0, or -1)

But you wrote "asEntity" in voidOnStart(), which has nothing in the paranthesises. That's why it won't work.

Neelke wrote this:
PHP Code: (Select All)
void OnStart()
{
for(
int i=1i<=4; ++iAddUseItemCallback("crowbarondoors""crowbar""mansion_"+i"UseCrowbarOnDoor"false);


for(int i=1; i<=4; ++i) is used to create a loop.
The first number "int i=1;" says that it has to start at 1.
The second number "i<=4;" says that it has to end at 4.

So by writing "mansion_"+i in the entities-space he selects all the mansion doors named, mansion_1, mansion_2, mansion_3, and mansion_4.

He did this, to save time and space. To understand it better, what he's actually doing is writing this:
PHP Code: (Select All)
void OnStart()
{
AddUseItemCallback("crowbarondoors""crowbar""mansion_1""UseCrowbarOnDoor"false);
AddUseItemCallback("crowbarondoors""crowbar""mansion_2""UseCrowbarOnDoor"false);
AddUseItemCallback("crowbarondoors""crowbar""mansion_3""UseCrowbarOnDoor"false);
AddUseItemCallback("crowbarondoors""crowbar""mansion_4""UseCrowbarOnDoor"false);


Do you see?
He selects all the doors, but he uses the same crowbar. This means that the function "UseCrowbarOnDoor" will call when he uses "crowbar" on either of the selected doors.

In your script, you have chosen to name all the doors "Door_1", "Door_2", and so on...
Remember to rename these.

Now to the function.

PHP Code: (Select All)
void UseCrowbarOnDoor(string &in asItemstring &in asEntity)
{
    if(
asEntity == "Door_1")
      {
        
PlaySoundAtEntity("""player_crouch.snt""Player"0.05false);
        
AddTimer(asEntity0.2"TimerPlaceCrowbar");
      }
      else if(
asEntity == "Door_2")
      {
        
PlaySoundAtEntity("""player_crouch.snt""Player"0.05false);
        
AddTimer(asEntity0.2"TimerPlaceCrowbar");
      }


In this function you are only checking for 2 of the doors. If i recall correctly, you had 4. So the script is not done before you've done it to all 4 doors.
BUT! Since you are now learning about "asEntity" how about we optimize the script a bit?

PHP Code: (Select All)
void UseCrowbarOnDoor(string &in asItemstring &in asEntity)
{
RemoveItem("asItem");
PlaySoundAtEntity("""player_crouch.snt""Player"0.05false);
AddTimer(asEntity0.2"TimerPlaceCrowbar");

SetLocalVarString("CrowbarDoor"asEntity);


Since you are using "asEntity" in the AddTimer it doesn't matter which door you are using it on, since it will always pick the door you are using it on anyway. (Because the door you are using the crowbar on will automatically be "asEntity").

Notice that I added an extra line about setting a "string" to asEntity. This will be useful later. I'm just storing the information. Just read along.

Also notice that I'm removing the crowbar. This is so that the player won't go and use the crowbar on another area, while the joint it active, because then suddenly 2 joints will be active, meaning 2 crowbars. And the player will be like: "Wut? How did i do that?"

Now something a little more difficult appears.

PHP Code: (Select All)
void TimerPlaceCrowbar(string &in asTimer)
{
        
SetEntityActive("Joint"true);
        
PlaySoundAtEntity("""puzzle_place_jar.snt"asTimer0false);


You have chosen only to set "Joint" active. Since there's only 1 object named "Joint" in the map, and it's only placed at 1 of the doors, what will happen at the 4 other doors?
Good question. Right now, the answer is: The same "Joint" will go active again. Which is, (what I'm pretty sure) not what you want.

So instead, let's go and rename all the "Joints" into "Joint_Door_1" if it's at "Door_1", "Joint_Door_2" if it's at "Door_2". And so on...
Hopefully you get the idea now.

This means that we can now write:

PHP Code: (Select All)
void TimerPlaceCrowbar(string &in asTimer)
{
        
SetEntityActive("Joint_"+asTimertrue);
        
PlaySoundAtEntity("""puzzle_place_jar.snt"asTimer0false);


This is because "asTimer" was previously set to be "asEntity", which was the door we were using the crowbar on, in the first case: "Door_1". This means that the object that goes active is "Joint_Door_1", just as we renamed it to.

So what happens when the Joint collides with the area?

PHP Code: (Select All)
void BreakDoor(string &in asParentstring &in asChildint alState)
{
        
SetEntityActive("Joint"false);
        
SetEntityActive("Broken"true);
  
        
SetSwingDoorLocked("Door_x"falsefalse);
        
SetSwingDoorClosed("Door_x"falsefalse);
        
SetSwingDoorDisableAutoClose("Door_x"true);
    
        
AddPropImpulse("Door_x"003"world");
    
        
CreateParticleSystemAtEntity("""ps_hit_wood.ps""AreaEffect"false);
        
PlaySoundAtEntity("""break_wood_metal""AreaEffect"0false);
     
        
GiveSanityBoostSmall();
     
        
PlayMusic("10_puzzle01.ogg"false0.70.110false);
     
        
AddTimer(""0.1"TimerPushDoor");


This is not general enough, since the exact same thing will happen, as the above where, only the first Joint will be deactivated.
So let's touch it up a bit:

PHP Code: (Select All)
void BreakDoor(string &in asParentstring &in asChildint alState)
{
        
SetEntityActive(asParentfalse);
  
        
SetSwingDoorLocked(GetLocalVarString("CrowbarDoor"), falsefalse);
        
SetSwingDoorClosed(GetLocalVarString("CrowbarDoor"), falsefalse);
        
SetSwingDoorDisableAutoClose(GetLocalVarString("CrowbarDoor"), true);
    
        
AddPropImpulse(GetLocalVarString("CrowbarDoor"), 003"world");
    
        
CreateParticleSystemAtEntity("""ps_hit_wood.ps""AreaEffect"false);
        
PlaySoundAtEntity("""break_wood_metal""AreaEffect"0false);
     
        
GiveSanityBoostSmall();
     
        
PlayMusic("10_puzzle01.ogg"false0.70.110false);
     
        
AddTimer(""0.1"TimerPushDoor");

GiveItem("crowbar""Puzzle""crowbar""crowbar.tga"1);


Ok, so what did I edit?

I changed the SetEntityActive entity to asParent, because now we're just setting the Joint inactive.
And now you wanted to add a broken crowbar? Why is that exactly? Because since you're going to be using it again, it shouldn't just break should it?
I deleted that line.

And here comes the special thing. I'm now pulling back the information I stored earlier by using GetLocalVarString("CrowbarDoor"). This way, it'll remember what door it was we were using it on, because it we set it that way.

Also, notice that in the end I'm giving the player the crowbar again, so that he can use it again.

This became rather long. I hope you understand! Smile


EDIT:
Oh right. And in the last 2 functions:

PHP Code: (Select All)
void TimerPushDoor(string &in asTimer)
{
        
AddPropImpulse("Door_x", -421"world");
        
AddTimer(""1.1"TimerDoorCanClose");
}
     
void TimerDoorCanClose(string &in asTimer)
{
        
SetSwingDoorDisableAutoClose("Door_x"false);


Just put "GetLocalVarString("CrowbarDoor")" instead of "Door_x", because "Door_x" isn't anything you have in the editor, and therefore nothing will happen.

It will look like this:

PHP Code: (Select All)
void TimerPushDoor(string &in asTimer)
{
        
AddPropImpulse(GetLocalVarString("CrowbarDoor"), -421"world");
        
AddTimer(""1.1"TimerDoorCanClose");
}
     
void TimerDoorCanClose(string &in asTimer)
{
        
SetSwingDoorDisableAutoClose(GetLocalVarString("CrowbarDoor"), false);


Trying is the first step to success.
(This post was last modified: 09-21-2014, 11:51 PM by FlawlessHappiness.)
09-21-2014, 11:42 PM
Find


Messages In This Thread
RE: Using a Single Crowbar on Multiple Doors - by FlawlessHappiness - 09-21-2014, 11:42 PM



Users browsing this thread: 1 Guest(s)