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
T122002 Offline
Junior Member

Posts: 24
Threads: 10
Joined: Dec 2012
Reputation: 1
#11
RE: Acid Scare

(10-24-2013, 10:45 AM)Wapez Wrote:
(10-23-2013, 09:58 PM)T122002 Wrote: I just tried exactly what you did by changing the names and I just checked and there are no entities with the same name on this map.

I will post a new, working script with the same function for you later today.

Okay! Thank you so much, that means a lot!
10-24-2013, 06:26 PM
Find Reply
Wapez Offline
Senior Member

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

Been quite busy today, I'll upload a working code tomorrow. Sorry for the delay bro :/

Founder & Legally Accountable Publisher of Red Line Games.
Environment & Gameplay Designer and Scripter.
http://moddb.com/mods/in-lucys-eyes
10-24-2013, 08:55 PM
Find Reply
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 Reply
T122002 Offline
Junior Member

Posts: 24
Threads: 10
Joined: Dec 2012
Reputation: 1
#14
RE: Acid Scare

(10-25-2013, 10:38 AM)Wapez Wrote: 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.

Sorry I didn't reply to your previous comment about you being busy. Its alright! Big Grin
And thank you so much for posting the correct script and explaining in a nice, detailed manor for a newbie scripter like me to fully understand what you're talking about! I was able to follow along with what you put into the new script just fine. So now I know how everything goes together in a correct way! And I've always done the bad way you told me, such as adding in more script areas that are not necessary. I honestly didn't know what I was supposed to do, so I thought more script areas would work. But you're definitely right. Its very confusing and I couldn't find where the mistakes were because of all the extra coding.
I'm not that great with if statements, but I understood what you did here in this coding.

In the end, thank you so much for helping me out! I was way too confused and it seemed like I tried everything I could from Timers to if statements, which probably isn't much. I just wasn't able to figure this thing out.
Once again, thank you! This means a lot to me! Big Grin
10-26-2013, 03:49 AM
Find Reply
Wapez Offline
Senior Member

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

Glad it worked out fine! For further lessons and tutorials I suggest you check out the wiki, it's stuffed with goodies!
http://wiki.frictionalgames.com/

Founder & Legally Accountable Publisher of Red Line Games.
Environment & Gameplay Designer and Scripter.
http://moddb.com/mods/in-lucys-eyes
10-26-2013, 01:56 PM
Find Reply




Users browsing this thread: 1 Guest(s)