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 Need help to make a lever puzzle
Shadowfied Offline
Senior Member

Posts: 261
Threads: 34
Joined: Jul 2010
Reputation: 5
#27
RE: Need help to make a lever puzzle

(01-16-2012, 09:11 PM)Inurias Wrote:
(01-15-2012, 03:13 PM)Statyk Wrote:
(01-15-2012, 11:56 AM)Your Computer Wrote: Here's a more efficient way of doing it (though entirely untested).

PHP Code: (Select All)
const string[] lever_names = {"LEVER1""LEVER2""LEVER3""LEVER4"}
const 
int[] desired_lever_states = {11, -11}

/******************************************************************************/

void OnStart()
{
SetEntityConnectionStateChangeCallback("LEVER1""lever_func");
SetEntityConnectionStateChangeCallback("LEVER2""lever_func");
SetEntityConnectionStateChangeCallback("LEVER3""lever_func");
SetEntityConnectionStateChangeCallback("LEVER4""lever_func");

SetLocalVarInt("LEVER1"0);
SetLocalVarInt("LEVER2"0);
SetLocalVarInt("LEVER3"0);
SetLocalVarInt("LEVER4"0);
}

/******************************************************************************/

void lever_func(string &in asEntityint alState)
{
if (
GetLocalVarInt("LEVER_PUZZLE_COMPLETE") == 1)
return;

SetLocalVarInt(asEntityalState);
CheckFunction();
}

/******************************************************************************/

void CheckFunction()
{
for (
int i 0lever_names.length(); ++i)
{
if (
GetLocalVarInt(lever_names[i]) != desired_lever_states[i])
return;
else
{
SetLeverStuckState(lever_names[i], desired_lever_states[i], true);
SetEntityConnectionStateChangeCallback(lever_names[i], "");
}
}

GiveSanityBoost();
SetSwingDoorLocked("LEVERDOOR"falsetrue);
SetLocalVarInt("LEVER_PUZZLE_COMPLETE"1);




Goodness gracious great balls of fire, this is ridiculous... XD I have a lot to learn! I might give this a whirl to try it out. Also need to find time to watch your scripting tutorial. And guys, I'm really NOT the best scripter. I'm glad you appreciate the effort and stuff but I'm still a newbie to this stuff. >>; I'm glad you liked Hunter though =P I think I'm going to continue it in Cry's 2nd 24-Hour installment.


Also, instead of setting new levers and whatnot, in the "CheckFunction", add this (all issues solved when you can't touch the levers after completion):

CheckFunction()
{
SetEntityInteractionDisabled("LEVER1", true);
SetEntityInteractionDisabled("LEVER2", true);
SetEntityInteractionDisabled("LEVER3", true);
SetEntityInteractionDisabled("LEVER4", true);
}
If you are really going for shortness, I just made up an even shorter version (which works):

string[] vars = {"", "", "", "", ""};

void OnStart()
{
    for (int i = 1; i <= 4; i++)
        SetEntityConnectionStateChangeCallback("LEVER" + i, "LeverCallback");
}

void LeverCallback(string &in asEntity, int alState)
{

    if (alState != 0)
    {
        for (int i = 1; i <= 4; i++)
        {
                if (StringContains(asEntity, "" + i))
                {
                    vars[i] = "b" + asEntity;
                    SetLocalVarInt(vars[i], alState);
                    SetLeverStuckState(asEntity, alState, true);
                    break;
                }
        }
    }

    if (GetLocalVarInt(vars[1]) == 1 && GetLocalVarInt(vars[2]) == 1 && GetLocalVarInt(vars[3]) == -1 && GetLocalVarInt(vars[4]) == 1)
        DoMyStuff();
}

void DoMyStuff()
{
     GiveSanityBoost();
                 SetSwingDoorLocked("LEVERDOOR", false, true);

     for (int l = 1; l <= 4; l++)
        SetEntityInteractionDisabled("LEVER" + l, true);
}

- Inurias
I wish I understood that..


Current - Castle Darkuan
Other - F*cked Map
01-17-2012, 08:15 AM
Find


Messages In This Thread
Need help to make a lever puzzle - by Shadowfied - 01-14-2012, 11:55 AM
RE: Need help to make a lever puzzle - by Statyk - 01-14-2012, 06:21 PM
RE: Need help to make a lever puzzle - by Statyk - 01-14-2012, 07:39 PM
RE: Need help to make a lever puzzle - by flamez3 - 01-15-2012, 10:54 AM
RE: Need help to make a lever puzzle - by Statyk - 01-15-2012, 03:13 PM
RE: Need help to make a lever puzzle - by Inurias - 01-16-2012, 09:11 PM
RE: Need help to make a lever puzzle - by Shadowfied - 01-17-2012, 08:15 AM



Users browsing this thread: 1 Guest(s)