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 Elevator Lever to Level Transition
AGP Offline
Senior Member

Posts: 448
Threads: 45
Joined: Dec 2012
Reputation: 23
#1
Elevator Lever to Level Transition

I've been sitting here ages trying to figure this script out, even tearing apart other scripts, and nothing is working. Obviously, I am missing something.

The idea is the rods will unlock the levers (which has not been scripted), and the levers will allow to the elevator to "move", which results in a level transition when the elevator lever is pulled down.

Some things may look a bit weird (like a sob activating when the lever puzzle is complete), but these are just stand-ins for the time being.

Here is the script as it is right now:

void OnStart()
{

}

void OnEnter()
{    
    AddUseItemCallback("", "guiding_rod01", "rodarea_1", "RodMeOnce", true);
    AddUseItemCallback("", "guiding_rod02", "rodarea_2", "RodMeTwice", true);
    AddUseItemCallback("", "guiding_rod03", "rodarea_3", "RodMeThrice", true);
}

void OnLeave()
{

}

void LeverBox(string &in asEntity, int LeverState)
{
    if(GetLeverState("lever_machine_lever_1") == -1
    && GetLeverState("lever_machine_lever_2") == -1
    && GetLeverState("lever_machine_lever_3") == -1
    && GetLeverState("lever_machine_lever_4") == -1
    && GetLeverState("lever_machine_lever_5") == -1
    && GetLeverState("lever_machine_lever_6") == -1)
        {
            PlaySoundAtEntity("", "sob01.snt", "Player", 0, false);
            SetEntityActive("elevator_lever_1", false);
            SetEntityActive("elevator_lever_2", true);
                
            for(int i = 1; i <= 6; i++)
            SetEntityInteractionDisabled("lever_machine_lever_"+i, true);
        }
        
    if(GetLeverState("elevator_lever_2") == -1)
    {
        SetEntityPlayerInteractCallback("elevator_lever_2", "Activate", true);
    }
}

void RodMeOnce(string &in asItem, string &in asEntity)
{
    SetEntityActive("guiding_rod01_stat", true);
    PlaySoundAtEntity("", "13_rod_in.snt", "rods", 0, false);
    RemoveItem("guiding_rod01");
    AddLocalVarInt("Rods", 1);
    
    if(GetLocalVarInt("Rods") == 3)
    {
        PlaySoundAtEntity("", "13_machine_extra.snt", "machine_sound", 0, false);
        PlaySoundAtEntity("", "13_machine_run.snt", "machine_sound", 0, false);
    }
}

void RodMeTwice(string &in asItem, string &in asEntity)
{
    SetEntityActive("guiding_rod02_stat", true);
    PlaySoundAtEntity("", "13_rod_in.snt", "rods", 0, false);
    RemoveItem("guiding_rod02");
    AddLocalVarInt("Rods", 1);
    
    if(GetLocalVarInt("Rods") == 3)
    {
        PlaySoundAtEntity("", "13_machine_extra.snt", "machine_sound", 0, false);
        PlaySoundAtEntity("", "13_machine_run.snt", "machine_sound", 0, false);
    }
}

void RodMeThrice(string &in asItem, string &in asEntity)
{
    SetEntityActive("guiding_rod03_stat", true);
    PlaySoundAtEntity("", "13_rod_in.snt", "rods", 0, false);
    RemoveItem("guiding_rod03");
    AddLocalVarInt("Rods", 1);
    
    if(GetLocalVarInt("Rods") == 3)
    {
        PlaySoundAtEntity("", "13_machine_extra.snt", "machine_sound", 0, false);
        PlaySoundAtEntity("", "13_machine_run.snt", "machine_sound", 0, false);
    }
}

void Activate(string &in asParent, string &in asChild, int alState)
{
    PlaySoundAtEntity("", "14_elevator_activate.snt", "Player", 0, false);
    AddTimer("", 2.0, "Fade");
    StartScreenShake(0.06f, 4.0, 1.0, 1.0);
}

void Fade(string &in asTimer)
{
    FadeOut(5);
    AddTimer("", 5, "TimerTransition");
}

void TimerTransition(string &in asTimer)
{
        ChangeMap("helena_001.map", "PlayerStartArea_1", "", "");
}

My scripting skills are still rather newbie level alas. This is about as far as I could get. :/

(This post was last modified: 11-26-2014, 06:40 AM by AGP.)
11-26-2014, 06:39 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#2
RE: Elevator Lever to Level Transition

Redacted - wouldn't make any difference.

Discord: Romulator#0001
[Image: 3f6f01a904.png]
(This post was last modified: 11-26-2014, 07:49 AM by Romulator.)
11-26-2014, 07:46 AM
Find
AGP Offline
Senior Member

Posts: 448
Threads: 45
Joined: Dec 2012
Reputation: 23
#3
RE: Elevator Lever to Level Transition

Nothing is changing. :/ It doesn't do anything.

I attached the map that I've been testing the script on. Maybe there is something in the map that's been looked-over?


Attached Files
.rar   levertest.rar (Size: 2.94 KB / Downloads: 106)

11-26-2014, 07:51 AM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#4
RE: Elevator Lever to Level Transition

First off you can remove those Once, Twice, Thrice scripts and use a single one with parameters to shorten the code.

PHP Code: (Select All)
void RodMeOnce(string &in asItemstring &in asEntity)
{
    
SetEntityActive(asEntity "_stat"true);
    
PlaySoundAtEntity("""13_rod_in.snt""rods"0false);
    
RemoveItem(asEntity);
    
AddLocalVarInt("Rods"1);
    
    if(
GetLocalVarInt("Rods") == 3)
    {
        
PlaySoundAtEntity("""13_machine_extra.snt""machine_sound"0false);
        
PlaySoundAtEntity("""13_machine_run.snt""machine_sound"0false);
    }


Do the sounds play though? I think the script stops right there. There are only those three callbacks when you enter, and those three code blocks (which could be only one) don't seem to advance the script to the other ones. Unless you have callbacks added to entities in the level? I'm guessing you do at least for the levers. I can't really check the level at the moment though.



This script might not do what you want it to. Let's just see what will happen if done.

PHP Code: (Select All)
void LeverBox(string &in asEntityint LeverState)
{
    if(
GetLeverState("lever_machine_lever_1") == -1
    
&& GetLeverState("lever_machine_lever_2") == -1
    
&& GetLeverState("lever_machine_lever_3") == -1
    
&& GetLeverState("lever_machine_lever_4") == -1
    
&& GetLeverState("lever_machine_lever_5") == -1
    
&& GetLeverState("lever_machine_lever_6") == -1)
        {
            
PlaySoundAtEntity("""sob01.snt""Player"0false);
            
SetEntityActive("elevator_lever_1"false);
            
SetEntityActive("elevator_lever_2"true);
                
            for(
int i 1<= 6i++)
            
SetEntityInteractionDisabled("lever_machine_lever_"+itrue);
        }
        
    if(
GetLeverState("elevator_lever_2") == -1)
    {
        
SetEntityPlayerInteractCallback("elevator_lever_2""Activate"true);
    }


Is this callback added to all the lever_machine_lever entities? Anything else?

Pulling all lever_machine_lever to state -1 will activate the main code, which plays some sounds and changes the elevator_lever entity. To prevent this some happening again, interaction is disabled for these levers. The last part will only activate if elevator_lever_2 is already set to state -1 before the other levers are set, or else they will remain uninteractable and can not call the code. Because elevator_lever_2 is enabled after pulling the other levers, this can cause it to not be finished, unless this callback is also added to the elevator_lever_2, however if so, it will also run the main code again once pulled, because even though the other levers are uninteractable, they're still in state -1 which will pass the code.

(This post was last modified: 11-26-2014, 08:46 AM by Mudbill.)
11-26-2014, 08:31 AM
Find
AGP Offline
Senior Member

Posts: 448
Threads: 45
Joined: Dec 2012
Reputation: 23
#5
RE: Elevator Lever to Level Transition

No the sounds do not play.

Changing the script down to the one RodMe (<-- my pathetic attempt at humor) made it so only one rod would go into the machine; the others would not work.

There are callbacks for the levers, but nothing else.

11-26-2014, 08:38 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#6
RE: Elevator Lever to Level Transition

Welp, I know what the problem is. Now I just have to fix it and reupload it. (For the level change, not the sounds).

Assuming that elevator_lever_2 is the one which you need to pull down to start the transition to the next level through the fade.

Discord: Romulator#0001
[Image: 3f6f01a904.png]
(This post was last modified: 11-26-2014, 08:45 AM by Romulator.)
11-26-2014, 08:44 AM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#7
RE: Elevator Lever to Level Transition

Ah, right, I see the different areas now. Missed that.

If you changed it to use only 1 callback block, don't forget to add the same one to all the items in OnStart or, OnEnter in your case.

PHP Code: (Select All)
for(int i 1<= 3i++) AddUseItemCallback("""guiding_rod0"+i"rodarea_"+i"RodMe"true); 

(This post was last modified: 11-26-2014, 08:45 AM by Mudbill.)
11-26-2014, 08:45 AM
Find
AGP Offline
Senior Member

Posts: 448
Threads: 45
Joined: Dec 2012
Reputation: 23
#8
RE: Elevator Lever to Level Transition

(11-26-2014, 08:31 AM)Mudbill Wrote: Is this callback added to all the lever_machine_lever entities? Anything else?

Pulling all lever_machine_lever to state -1 will activate the main code, which plays some sounds and changes the elevator_lever entity. To prevent this some happening again, interaction is disabled for these levers. The last part will only activate if elevator_lever_2 is already set to state -1 before the other levers are set, or else they will remain uninteractable and can not call the code. Because elevator_lever_2 is enabled after pulling the other levers, this can cause it to not be finished, unless this callback is also added to the elevator_lever_2, however if so, it will also run the main code again once pulled, because even though the other levers are uninteractable, they're still in state -1 which will pass the code.

Sounds like script-ception. o.o The callbacks are only on the lever_machine_levers.

And it still doesn't do anything but play the sound.

(11-26-2014, 08:44 AM)Romulator Wrote: Welp, I know what the problem is. Now I just have to fix it and reupload it. (For the level change, not the sounds).

Assuming that elevator_lever_2 is the one which you need to pull down to start the transition to the next level through the fade.

Yes. the elevator_lever_2 starts the level transition. I think I messed up though on the callback state (the lever should be pulled down and not up; I think it's script to be pulled up.)

11-26-2014, 08:48 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#9
RE: Elevator Lever to Level Transition

(11-26-2014, 08:48 AM)AGP Wrote:
(11-26-2014, 08:44 AM)Romulator Wrote: Welp, I know what the problem is. Now I just have to fix it and reupload it. (For the level change, not the sounds).

Assuming that elevator_lever_2 is the one which you need to pull down to start the transition to the next level through the fade.

Yes. the elevator_lever_2 starts the level transition. I think I messed up though on the callback state (the lever should be pulled down and not up; I think it's script to be pulled up.)

Actually, elevator_lever_2 does nothing, at least it never did anything for me, even when the levers got stuck. Maybe I did something wrong... ;-;

Back to the vanilla. Juuuuuuuust in case. Post 1800. Yay!

Discord: Romulator#0001
[Image: 3f6f01a904.png]
(This post was last modified: 11-26-2014, 08:54 AM by Romulator.)
11-26-2014, 08:50 AM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#10
RE: Elevator Lever to Level Transition

Does it eventually make the levers uninteractable once you've put them all in state -1? What type of levers are they? If they reset to state 0 after being pulled, you can't have them all at state -1 at the same time.

PS: State 1 and -1 depend on the lever if it will be up or down. I think the control room piston levers use static states and -1 is down, but I think most levers have -1 to be up. Might be mistaken.

Edit: Does elevator_lever_2 have a callback added? Is it set to run Activate? Well, no, not really, because that's a collision callback but I see nothing calling it.

(This post was last modified: 11-26-2014, 08:54 AM by Mudbill.)
11-26-2014, 08:52 AM
Find




Users browsing this thread: 1 Guest(s)