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
[solved] LanternLit function only inside a room?
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#2
RE: [need help] LanternLit function only inside a room?

I am assuming you want to "explode" the player IF he uses the lantern in the room. If you just want to disable the lantern, check out the wiki on the following function:
SetLanternDisabled(bool abX);

Create a "script area" in the room with the explosive gas. For now we shall call this area "explodeArea_1" This script area will be used to check whether or not the player should be exploded if the lantern turns on, so make sure it covers all the places the player could be in the room with the gas! (Note: if one area is not enough due to the shape of the room a tweak is discussed later on to get around this).

You would then set you lantern lit callback as normal
void OnStart()
{  
SetLanternLitCallback("cbLampLit");
}
In the lantern lit callback code we will check whether or not the player is touching the area:
void cbLampLit(bool abLit)
{
   //If the player is touching the explosion area and the lamp was turned on.
   if(GetEntitiesCollide("Player","explodeArea_1") && abLit) onExplosion();
}

void onExplosion()
{
//Explosion code here
}
This, of course, doesn't take into consideration the problem of the player walking into the area with the lantern out, only turning the lantern on inside the area. This can be rectified with the following code:
void OnStart()
{
  SetLanternLitCallback("cbLampLit");
  AddEntityCollideCallback("Player","explodeArea_1","cbExplodeAreaPlayerCollision",false,1)
}

//Called when the player enters the explosive area
void cbExplodeAreaPlayerCollision(string &in asParent, string &in asChild, int alState)
{
  //Lantern is on - explode!
  if(GetLanternActive) onExplosion();
}

So what happens if we need more than ONE explosive area? Assuming you have named you areas "explodeArea_1", "explodeArea_2" etc, the completed code will look like:

void OnStart()
{
   //Player uses lantern (turns on/off)
   SetLanternLitCallback("cbLampLit");
   //For each explosive area, add the player entry callback
   for(int i = 1; GetEntityExists("explodeArea_"+i); i++)
     AddEntityCollideCallback("Player","explodeArea_"+i,"cbExplodeAreaPlayerCollision",false,1)
}

//Called when the player enters the explosive area
void cbExplodeAreaPlayerCollision(string &in asParent, string &in asChild, int alState)
{
  //Lantern is on - explode!
  if(GetLanternActive) onExplosion();
}

//Called when lantern is toggled
void cbLampLit(bool abLit)
{
   //If the lantern isn't on, ignore.
   if(!abLit) return;
   //For each area, If the player is touching the explosion area and the lamp was turned on.
   for(int i = 1; GetEntityExists("explodeArea_"+i); i++)
     if(GetEntitiesCollide("Player","explodeArea_"+i)) onExplosion();
}

Note that this code is untested currently, so I cannot guarantee it will work, however I am fairly confident it should.
11-24-2011, 06:38 PM
Find


Messages In This Thread
RE: [need help] LanternLit function only inside a room? - by Apjjm - 11-24-2011, 06:38 PM



Users browsing this thread: 1 Guest(s)