Frictional Games Forum (read-only)
Valve interaction - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods (https://www.frictionalgames.com/forum/forum-35.html)
+--- Thread: Valve interaction (/thread-7484.html)



Valve interaction - Josh707 - 04-19-2011

Hey everyone, I have set up my map with toggle-able light switches and I want to know how to make a valve turn on a heater. I have tried to do
Code:
SetEntityPlayerInteractCallback("heatervalve", "Turnonheater", true);

then

Code:
void Turnonheater(string &in entity)
{
    PlaySoundAtEntity("", "22_fire.snt", "geostove", 0, false);
    SetLampLit("bonfire", true, false);
}
But the stove turns on as soon as I touch the valve, not when it turns all the way... I have searched the script functions page for everything related to valves, interaction, wheels, buttons etc. and I have not found anything. How do I make it call a function when it's turned to the maximum?

tl;dr How do I make a valve call a function when I turn it all the way?


RE: Valve interaction - Anxt - 04-19-2011

Select the object in the map editor that has the wheel on it. Go to the entity tab, and where it says "ConnectionStateChangeCallback" or something of the sort, type in the TurnOnHeater function name.
Then, make your function look like this:

void Turnonheater(string &in entity)
{
if(alState==1)
{
PlaySoundAtEntity("", "22_fire.snt", "geostove", 0, false);
SetLampLit("bonfire", true, false);
}
}

Get rid of the SetEntityPlayerInteractCallback you have as well, it will mess it up.


RE: Valve interaction - Josh707 - 04-19-2011

Error says: 'alState' is not declared, and Expression must be of boolean type


at the start you said the object that has the wheel on it, I just have a valve (rotating wheel with nothing behind it) stuck into the wall. Is that a problem or do I need to use a certain type of valve?


RE: Valve interaction - Apjjm - 04-19-2011

You will want the function "SetEntityConnectionStateChangeCallback" for that job.
Quote:void SetEntityConnectionStateChangeCallback(string& asName, string& asCallback);
A callback called when ever the connection state changes (button being switched on, lever switched, etc).
Callback syntax: void Func(string &in EntityName, int alState)
alState: -1 = off, 0 = between, 1 = on
E.g:
Code:
void OnStart()
{
  SetEntityConnectionStateChangeCallback("valve", "callback_func");
}
void callback_func(string &in EntityName, int alState)
{
  //Called when the var alState of the lever/valve changes between:
  // -1 (off), 0 (middle), 1 (on)
  if(alState == 1)
   { //Turn object on
   }
  else if(alState ==-1)
   { //Turn object off
   }
}



RE: Valve interaction - Anxt - 04-19-2011

Oh sorry, forgot to fix the function name. My bad. Should be:

void Turnonheater(string &in entity, int alState)
{
if(alState==1)
{
PlaySoundAtEntity("", "22_fire.snt", "geostove", 0, false);
SetLampLit("bonfire", true, false);
}
}

Forgot to add the alState bit. Now it should work.


RE: Valve interaction - Josh707 - 04-19-2011

Thank you! it worked. The first actual advice i've gotten on this forum Smile


RE: Valve interaction - Anxt - 04-19-2011

I do my best to help out when I can, if you need anything feel free to send me a PM, that way I will definitely see it.


RE: Valve interaction - Josh707 - 04-19-2011

Sounds good!