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 Levers!
Alento Offline
Member

Posts: 64
Threads: 11
Joined: Jan 2012
Reputation: 0
#1
Levers!

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

---------Want help with YOUR Custom Story? ---------
http://www.frictionalgames.com/forum/user-19049.html
02-13-2012, 11:50 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#2
RE: Levers!

Instead of writing the code for you, how about you post what you have and we work from there?

Tutorials: From Noob to Pro
02-14-2012, 12:00 AM
Website Find
Alento Offline
Member

Posts: 64
Threads: 11
Joined: Jan 2012
Reputation: 0
#3
RE: Levers!

(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. ^^

---------Want help with YOUR Custom Story? ---------
http://www.frictionalgames.com/forum/user-19049.html
02-14-2012, 12:04 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#4
RE: Levers!

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.

Tutorials: From Noob to Pro
02-14-2012, 12:16 AM
Website Find
Alento Offline
Member

Posts: 64
Threads: 11
Joined: Jan 2012
Reputation: 0
#5
RE: Levers!

(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


---------Want help with YOUR Custom Story? ---------
http://www.frictionalgames.com/forum/user-19049.html
02-14-2012, 12:25 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#6
RE: Levers!

(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.

Tutorials: From Noob to Pro
02-14-2012, 12:28 AM
Website Find
Alento Offline
Member

Posts: 64
Threads: 11
Joined: Jan 2012
Reputation: 0
#7
RE: Levers!

(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!

---------Want help with YOUR Custom Story? ---------
http://www.frictionalgames.com/forum/user-19049.html
(This post was last modified: 02-14-2012, 11:33 AM by Alento.)
02-14-2012, 11:30 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#8
RE: Levers!

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: (Select All)
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

Tutorials: From Noob to Pro
02-14-2012, 01:13 PM
Website Find
Alento Offline
Member

Posts: 64
Threads: 11
Joined: Jan 2012
Reputation: 0
#9
RE: Levers!

(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: (Select All)
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

---------Want help with YOUR Custom Story? ---------
http://www.frictionalgames.com/forum/user-19049.html
02-14-2012, 09:25 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#10
RE: Levers!

(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.

Tutorials: From Noob to Pro
02-14-2012, 09:33 PM
Website Find




Users browsing this thread: 1 Guest(s)