Frictional Games Forum (read-only)

Full Version: Levers!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Yes.. levers! look. Here is what I want to happen.

I have 2 levers and 1 crank. All but 1st lever should be stuck.

When 1st lever is on 1 state, I want the second lever to be unstuck and the first one stuck. And when the second lever is on state 1, the crank will be unstuck and the second lever should be stuck. Finally when the crank is on sate 1, I want it to stuck and play a sound. I've tried with "else if" but, I'm not so good at scripting, so it probably is wrong anyways. Would be grateful for help on this one.

Thanks! Heart
Instead of writing the code for you, how about you post what you have and we work from there?
(02-14-2012, 12:00 AM)Your Computer Wrote: [ -> ]Instead of writing the code for you, how about you post what you have and we work from there?
well, for now, I probably have a completely crap code, but.. Here it is:


SetEntityConnectionStateChangeCallback("lever1","blowwall");
}

void blowwall(string &in asEntity, int alState)
{
SetPropStaticPhysics("lever2", true);
SetPropStaticPhysics("crank1", true);
}
{
if(asEntity "lever1", alState == 1){
SetPropStaticPhysics("lever1", true);
SetPropStaticPhysics("lever2", false);
SetEntityActive("key2pontus", true);
}

else if(asEntity "lever2", alState == 1){
SetPropStaticPhysics("lever2", true);
SetPropStaticPhysics("crank1", false);
}
}

As I said, this sure isn't even close, but, I tried as far as i could. ^^
That doesn't look like all of the relevant code. A script like that would (should) make the game error out.

BTW, you're not supposed to make entities have static physics for a stuck state. You're supposed to use SetLeverStuckState and SetWheelStuckState for levers and wheels. Static physics makes the object lose its interactive properties.
(02-14-2012, 12:16 AM)Your Computer Wrote: [ -> ]That doesn't look like all of the relevant code. A script like that would (should) make the game error out.

BTW, you're not supposed to make entities have static physics for a stuck state. You're supposed to use SetLeverStuckState and SetWheelStuckState for levers and wheels. Static physics makes the object lose its interactive properties.
okay, very well.. I give up. Also to tired now, can't think..
Thanks for your help

(02-14-2012, 12:25 AM)Alento Wrote: [ -> ]okay, very well.. I give up. Also to tired now, can't think..

Post your entire script when you're no longer tired.
(02-14-2012, 12:28 AM)Your Computer Wrote: [ -> ]
(02-14-2012, 12:25 AM)Alento Wrote: [ -> ]okay, very well.. I give up. Also to tired now, can't think..

Post your entire script when you're no longer tired.

void OnStart()
{

SetEntityConnectionStateChangeCallback("lever1", "Stuck");
SetEntityConnectionStateChangeCallback("lever2", "Stuck2");
SetEntityConnectionStateChangeCallback("crank1", "Stuck3");
}

void Stuck3(string& asName, int alState, bool abEffects)
{
SetWheelStuckState("crank1", 1, true);
if(alState == 1){
PlaySoundAtEntity("", "explosion_rock_large.snt", "soundrock", 0, false);
}
}

void Stuck2(string& asName, int alState, bool abEffects)
{
SetLeverStuckState("lever2", 1, true);
if(alState == 1){
SetWheelStuckState("crank1", 0, true);
}
}

void Stuck(string& asName, int alState, bool abEffects)
{
SetLeverStuckState("lever1", 1, true);

if(alState == 1){
SetLeverStuckState("lever2", 0, true);
}
}

So that's the code, i changed it to that today, yesterday i was just.. bah, nvm. Well i tried that now, and still wont work. Any ideas?

And btw, another problem that came up, i want "the player body" to fly backwards, like an "PropForce" but it didn't work, also tried BodyForce, wont work either.. Ideas on that soo?

Thanks!
For starters, the callback syntax doesn't include bool abEffects. Secondly, try not to make a new callbacks for the same puzzle. You can handle it all in one function. Thirdly, if you want things to happen only under certain conditions, don't place things outside of conditional statements. You had SetLeverStuckState and SetWheelStuckState outside of if statements. Fourth, when defining a string parameter, the ampersand should have either in, out, or inout directly following it. In most cases, &in is what should be used.

Finally,
PHP Code:
void OnStart()
{
    
SetEntityConnectionStateChangeCallback("lever1""Stuck");
    
SetEntityConnectionStateChangeCallback("lever2""Stuck");
    
SetEntityConnectionStateChangeCallback("crank1""Stuck");
}

void Stuck(string &in asNameint alState)
{
    if (
asName == "crank1")
    {
        if(
alState == 1){
            
SetWheelStuckState("crank1"1true);
            
PlaySoundAtEntity("""explosion_rock_large.snt""soundrock"0false);
        }
    }
    
    else if (
asName == "lever1")
    {
        if(
alState == 1){
            
SetLeverStuckState("lever1"1true);
            
SetLeverStuckState("lever2"0true);
        }
    }
    
    else if (
asName == "lever2")
    {
        if(
alState == 1){
            
SetLeverStuckState("lever2"1true);
            
SetWheelStuckState("crank1"0true);
        }
    }


For player body force, search here: http://wiki.frictionalgames.com/hpl2/amn...ons#player
(02-14-2012, 01:13 PM)Your Computer Wrote: [ -> ]For starters, the callback syntax doesn't include bool abEffects. Secondly, try not to make a new callbacks for the same puzzle. You can handle it all in one function. Thirdly, if you want things to happen only under certain conditions, don't place things outside of conditional statements. You had SetLeverStuckState and SetWheelStuckState outside of if statements. Fourth, when defining a string parameter, the ampersand should have either in, out, or inout directly following it. In most cases, &in is what should be used.

Finally,
PHP Code:
void OnStart()
{
    
SetEntityConnectionStateChangeCallback("lever1""Stuck");
    
SetEntityConnectionStateChangeCallback("lever2""Stuck");
    
SetEntityConnectionStateChangeCallback("crank1""Stuck");
}

void Stuck(string &in asNameint alState)
{
    if (
asName == "crank1")
    {
        if(
alState == 1){
            
SetWheelStuckState("crank1"1true);
            
PlaySoundAtEntity("""explosion_rock_large.snt""soundrock"0false);
        }
    }
    
    else if (
asName == "lever1")
    {
        if(
alState == 1){
            
SetLeverStuckState("lever1"1true);
            
SetLeverStuckState("lever2"0true);
        }
    }
    
    else if (
asName == "lever2")
    {
        if(
alState == 1){
            
SetLeverStuckState("lever2"1true);
            
SetWheelStuckState("crank1"0true);
        }
    }


For player body force, search here: http://wiki.frictionalgames.com/hpl2/amn...ons#player
hm.. I didn't understood all you said but, anyway, the sound is playing when the crank is on state 1 now, that's a progress! Thank you! Now, the problem is, that, even if I haven't touched the levers, I can spin the crank :/

The thing is, that, Lever 2 shouldn't be able to move if I haven't drag the lever1, and same for the crank, it shouldn't be able to move if I haven't drag the lever2. Ideas for that? Smile
(02-14-2012, 09:25 PM)Alento Wrote: [ -> ]hm.. I didn't understood all you said but, anyway, the sound is playing when the crank is on state 1 now, that's a progress! Thank you! Now, the problem is, that, even if I haven't touched the levers, I can spin the crank :/

The thing is, that, Lever 2 shouldn't be able to move if I haven't drag the lever1, and same for the crank, it shouldn't be able to move if I haven't drag the lever2. Ideas for that? Smile

In the level editor set the states you want them to be in.
Pages: 1 2