Frictional Games Forum (read-only)

Full Version: Valve interaction
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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.
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?
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
   }
}
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.
Thank you! it worked. The first actual advice i've gotten on this forum Smile
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.
Sounds good!