Frictional Games Forum (read-only)

Full Version: Just need some help scripting, im a beginner
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
okay, so im like a complete noob at scripting, like i'm stumped with a lot of stuff. I have an area in my map. In this area, when the player walks by, I want a grunt to be alerted, but ONLY if the player has a certain item in the inventory. How would I script this? (let's call the area Area1 and the item Item1). thx, im just stumped here.
The way I did it awhile back was this:

In the OnStart I had this:
Code:
AddEntityCollideCallback("Player", "Area1", "FunctionName", false, 1);

And the actual function looked like this:
Code:
void FunctionName(string &in asParent, string &in asChild, int alState)
{
    if(HasItem("Item1") == true)
    {
        //DO STUFF HERE
    }
}

What would happen is the function would trigger every time the Player walks past but a certain action wouldn't be taken until the Player has Item1. (Depending on the action you may also need to put a variable in to stop it from happening more than once.)
(05-26-2011, 04:02 AM)willochill Wrote: [ -> ]okay, so im like a complete noob at scripting, like i'm stumped with a lot of stuff. I have an area in my map. In this area, when the player walks by, I want a grunt to be alerted, but ONLY if the player has a certain item in the inventory. How would I script this? (let's call the area Area1 and the item Item1). thx, im just stumped here.

Code:
void OnStart()
{
    AddEntityCollideCallback("Player", "Area1", "Func01", false, 1);
}
void Func01(string &in asParent, string &in asChild, int alState)
{
     if (HasItem("Item1") == true)
     {
          SetEnemyActive("MonsterName", true);
          RemoveEntityCollideCallback("Player", "Area1");
          return;
     }
}

MonsterName is meant to be replaced with the name of the monster that's spawned.

I have to set the bool abOnDelete for the AddEntityCollideCallback because if the player doesn't have the object and when they walk through, it would stop the function from working because it's deleted and also nothing would happen.

So when the player does have the item, it sets the monster active and then prevents the player from accidently colliding with Area1 after the script was used.