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?
Dobbydoo Offline
Member

Posts: 50
Threads: 6
Joined: Aug 2011
Reputation: 0
#1
[solved] LanternLit function only inside a room?

I'm trying to make a room with explosive gas, so that you can't use the lantern in there, but I can't find any way to delete my explode function when I'm outside the room after I've been inside it. Is it even possible to do? And in that case, how would I do it?
(This post was last modified: 11-26-2011, 12:31 PM by Dobbydoo.)
11-24-2011, 05:13 PM
Find
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
Dobbydoo Offline
Member

Posts: 50
Threads: 6
Joined: Aug 2011
Reputation: 0
#3
RE: [need help] LanternLit function only inside a room?

I get it working when I enter the room, but not when I'm actually inside the room. By that I mean that I can walk into the area with my lantern lit, and explode, but if I go inside the area with my lantern unlit and light it inside the room, nothing happens.
Here's my script.
void OnStart()

{
AddEntityCollideCallback("Player", "PoisonArea_1", "cbExplodeAreaPlayerCollision", false, 1);
SetLanternLitCallback("LanternLit");
}

//Explosion Death

void LanternLit(bool abLit)
{
   if(GetEntitiesCollide("PoisonArea_1","Player") && abLit) Explosion();
}

void cbExplodeAreaPlayerCollision(string &in asParent, string &in asChild, int alState)
{
  if(GetLanternActive()) Explosion();
}

void Explosion()
{
//StartScreenShake(1, 5, 0, 13);
AddPlayerBodyForce(0, 0, -50000, true);
//SetPlayerActive(false);
SetPlayerCrouching(true);
GivePlayerDamage(90000000000000000000000000.0f, "BloodSplat", true, true);
PlaySoundAtEntity("explosion", "explosion_rock_large.snt", "Player", 5, true);
PlaySoundAtEntity("explosion", "explosion_rock_large.snt", "Player", 5, true);
PlaySoundAtEntity("explosion", "explosion_rock_large.snt", "Player", 5, true);
FadeRadialBlurTo(1, 1);
StartEffectFlash(0, 1, 1);
}

And where should I post when I need help? I've gotten my posts moved twice, but I don't know where they where moved to... And also, thanks for helping me Smile
11-25-2011, 09:25 PM
Find
Apjjm Offline
Is easy to say

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

Quote:And where should I post when I need help? I've gotten my posts moved twice, but I don't know where they where moved to... And also, thanks for helping me
No worries Smile. This topic was just moved to a sub-forum of where you posted - called "Development Support" in the "Custom Stories, TCs & Mods - Development" forum. This sub-forum is pretty much for any queries about how to do something in Amnesia.

With regards to the problem with your explosion effect: It may be to do with the where the function "GetEntitiesCollide" expects the "Player" parameter. You could try the following:
//Explosion Death
void LanternLit(bool abLit)
{
   if(GetEntitiesCollide("Player","PoisonArea_1") && abLit) Explosion();
}
If that fails to work, the following will work (it's just a little harder to see what's happening in the script):
void OnStart()
{
//The following code will now trigger the even on both entering and leaving the explosive area
AddEntityCollideCallback("Player", "PoisonArea_1", "cbExplodeAreaPlayerCollision", false, 0);
//Same as before
SetLanternLitCallback("LanternLit");
}

//Explosion Death

void LanternLit(bool abLit)
{
//If we are in at least one explosive areas and the lantern is lit, explode.
if(GetLocalVarInt("ExplosionAreasCount")>0 && abLit) Explosion();
}

void cbExplodeAreaPlayerCollision(string &in asParent, string &in asChild, int alState)
{
  //If entering an explosive area, add 1 to explosive area count, else remove 1.
  AddLocalVarInt("ExplosionAreasCount",alState);
  //If entering an explosive area with the lantern out, explode.
  if(GetLanternActive() && alState == 1) Explosion();
}

void Explosion()
{
//StartScreenShake(1, 5, 0, 13);
AddPlayerBodyForce(0, 0, -50000, true);
//SetPlayerActive(false);
SetPlayerCrouching(true);
GivePlayerDamage(100.0f, "BloodSplat", true, true); //The player's maximum health is 100.
PlaySoundAtEntity("explosion", "explosion_rock_large.snt", "Player", 5, true);
PlaySoundAtEntity("explosion", "explosion_rock_large.snt", "Player", 5, true);
PlaySoundAtEntity("explosion", "explosion_rock_large.snt", "Player", 5, true);
FadeRadialBlurTo(1, 1);
StartEffectFlash(0, 1, 1);
}

11-25-2011, 09:56 PM
Find
Dobbydoo Offline
Member

Posts: 50
Threads: 6
Joined: Aug 2011
Reputation: 0
#5
RE: [need help] LanternLit function only inside a room?

Thank you very much, it works perfectly now! Smile
The reason for having such a high number as explosion damage is because I have set my health very high for testing.
11-26-2011, 09:36 AM
Find




Users browsing this thread: 1 Guest(s)