Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Acid Scare
Wapez Offline
Senior Member

Posts: 360
Threads: 37
Joined: Mar 2012
Reputation: 19
#13
RE: Acid Scare

Okay, I created a working version of this!
First of all, here's the finished script:
PHP Code: (Select All)
void OnStart()
{
    
AddUseItemCallback("""glass_jar_1""acid_container_1""FilledContainer"true);
    
AddUseItemCallback("""glass_container_filled""acid_container_1""FilledContainer"true);
    
    
AddEntityCollideCallback("Player""SpawnEnemy""SpawnSatan"false1);
}

void FilledContainer(string &in asItemstring &in asEntity)
{
    if(
asItem == "glass_jar_1"){
        
PlaySoundAtEntity("""puzzle_acid_success"asEntity1.0ffalse);

        
RemoveItem("glass_jar_1");
        
GiveItemFromFile("glass_container_filled""glass_container_filled.ent");

        
SetMessage("Ch02Level15""AcidInJar"0);

        
GiveSanityBoostSmall();
    }
    else if(
asItem == "glass_container_filled"){
        
SetMessage("Ch02Level15""AcidAlreadyInJar"0);
    }
    else{
        
SetMessage("Ch02Level15""AcidWithItem"0);
    }
}

void SpawnSatan(string &in asParentstring &in asChildint alState)
{
    if(
HasItem("glass_container_filled")){
        
SetEntityActive("Enemy_1"true);
        
SetEntityActive("SpawnEnemy"false);
    }


Second, I'll explain what I changed in this spoiler:
Spoiler below!

The first thing I did was to remove this function:

void SuitorScare(string &in asEntity, string &in type)
{
SetEntityActive("SpawnEnemy", true);
AddEntityCollideCallback("Player", "SpawnEnemy", "SpawnSatan", true, 1);
}

Why?

Because you don't have to use an area to spawn another area in cases like this. I can explain why:
What we REALLY want to know here is whether the player has the acid jar while entering the area that spawns the monster. You can do that in many ways, and you chose to keep the monster area unactive until the player walks into another area while having the acid. However, there is better options. The option you chose is bad because:
1. It requires several script areas in the Level Editor.
2. It requires a lot more coding.
3. It's harder to track what's wrong.

The best solution in this case would be to always keep the area that spawns the monster active, and make it trigger every time the player enter it. We do that by changing something in the callback function for that area.

AddEntityCollideCallback("Player", "SpawnEnemy", "SpawnSatan", false, 1);

Changing "true" to "false" decides that the area will not be removed the first time the player collides with it. That way, it can trigger several times, until manually turned off.

But there are still some things to do. The script triggers several times, but we only want the monster to spawn once, when the player has the acid. Well, this is solved by this:

void SpawnSatan(string &in asParent, string &in asChild, int alState)
{
if(HasItem("glass_container_filled")){
SetEntityActive("Enemy_1", true);
SetEntityActive("SpawnEnemy", false);
}
}

The marked line of code has a very useful function: the functions within it's brackets is only called if the player has the item "glass_container_filled", otherwise they will be skipped.
This means that when the player enters the area with the acid, the monster will spawn, but when the player doesn't have the acid, nothing happens.
To make sure that the monster doesn't spawn several times due to the player entering the area again, we manually remove the area when the player enters it and has the acid. The player will after this only be able to enter it once with the acid - after the area has done it's work and is removed from the game. The script is done!

The only thing you have to do is rename the "glass_container_1" to "glass_jar_1" in the Level Editor, remove the SuitorScare area, and then copy my script.


I hope you understand what I did in this script, and why. If you have any further questions or if you need help with something else, feel free to let me know.

Founder & Legally Accountable Publisher of Red Line Games.
Environment & Gameplay Designer and Scripter.
http://moddb.com/mods/in-lucys-eyes
10-25-2013, 10:38 AM
Find


Messages In This Thread
Acid Scare - by T122002 - 10-21-2013, 04:25 AM
RE: Acid Scare - by DnALANGE - 10-21-2013, 01:35 PM
RE: Acid Scare - by FlawlessHappiness - 10-21-2013, 08:14 PM
RE: Acid Scare - by T122002 - 10-22-2013, 03:07 AM
RE: Acid Scare - by Wapez - 10-21-2013, 09:01 PM
RE: Acid Scare - by daortir - 10-22-2013, 02:55 PM
RE: Acid Scare - by T122002 - 10-23-2013, 03:57 AM
RE: Acid Scare - by Wapez - 10-23-2013, 08:11 AM
RE: Acid Scare - by T122002 - 10-23-2013, 09:58 PM
RE: Acid Scare - by Wapez - 10-24-2013, 10:45 AM
RE: Acid Scare - by T122002 - 10-24-2013, 06:26 PM
RE: Acid Scare - by Wapez - 10-24-2013, 08:55 PM
RE: Acid Scare - by Wapez - 10-25-2013, 10:38 AM
RE: Acid Scare - by T122002 - 10-26-2013, 03:49 AM
RE: Acid Scare - by Wapez - 10-26-2013, 01:56 PM



Users browsing this thread: 1 Guest(s)