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
Help needed with SetEntityActive in custom story
hagridas Offline
Junior Member

Posts: 2
Threads: 1
Joined: Jan 2017
Reputation: 0
#1
Help needed with SetEntityActive in custom story

Hello. I decided to make a custom story. I am green at scripting, however i can make some simple things like key that unlocks specific doors n stuff. Today i tried to make a script where a monster spawns when player collides with ScriptArea, walks abit and then despawns at certain pathnode. The monster spawns, walks, however it doesnt despawn i tried multiple times watched multiple videos but it doesnt work. I will appreciate any help. My script:

void OnStart()
{
AddEntityCollideCallback("Player", "area", "monster", true,1);
AddEntityCollideCallback("grunt", "PathNodeArea_12", "CollideStop", true, 1);
}

void monster(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("grunt",true);
AddEnemyPatrolNode("grunt", "PathNodeArea_1", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_2", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_3", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_4", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_5", 4, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_6", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_7", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_8", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_9", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_10", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_11", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_12", 0.001, "");
}

void CollideStop(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("grunt", false);
}

THANK YOU !!!
01-03-2017, 08:41 PM
Find
Spelos Away
Banned

Posts: 231
Threads: 19
Joined: Sep 2014
#2
RE: Help needed with SetEntityActive in custom story

Alright, a few things. I'll order them by their relevance to your case:

WHY IT DOESN'T WORK
While you are creating a collision callback for the enemy, a path node is just a single point in the world. It is just a directional helper, a flag if you will, that the enemies use to calculate their path towards their destination. Collision can be calculated with things that actually take up space. Such as Script Areas.

Tell me more:
Spoiler below!

Collisions are calculated based on a position and size of an entity. With those, we can calculate the volume of this object as well as detect if two of them intersect. However, in the case of a single point that has no volume (like a PathNode or Point), you cannot determine this intersection. Moreover, things like entering the intersection, being in it and leaving would have to in a way trigger at the same time or multiple times if single point intersection would be allowed.


HOW TO MAKE IT WORK
Instead of referencing the last PathNode, create a script area there. The enemy will collide with that area.

WHAT TO THINK ABOUT
Enemies disappear on their own once far enough from a player & at the end of their patrol instructions.

(!) SCRIPT RELATED WARNINGS AND TIPS
  • Your function "monster" isn't really telling you much about what it does. Consider changing the name (for your own sake) to something descriptive like "StartHallMonsterEvent"
  • Based on general convention, Function names start with a Capital letter.
  • Consider adding the Collide callback when needed, creating the enemy collision callback in the "monster" function itself.
  • Your "CollideStop" function might be generalized. Meaning it could be called "EnemyDisableTrigger" and instead of
    PHP Code: (Select All)
    void EnemyDisableTrigger(string &in asParentstring &in asChildint alState)
    {
    SetEntityActive("grunt"false);

    can use the asParent variable to determine what to despawn. That would allow you to add the callback to any number of monsters you want, and each that would collide would get despawned.
    PHP Code: (Select All)
    // The parameters of this function can also be simplified (although not necessary)
    void EnemyDisableTrigger(string parentstring childint state)
    {
    SetEntityActive(parentfalse); // Actually, the monster might be a child of the collision... Not sure there.

(This post was last modified: 01-03-2017, 09:51 PM by Spelos.)
01-03-2017, 09:42 PM
Find
hagridas Offline
Junior Member

Posts: 2
Threads: 1
Joined: Jan 2017
Reputation: 0
#3
RE: Help needed with SetEntityActive in custom story

It is working now, thanks alot! I thought Amnesia is dead and didn't expect anyone to reply, but WOW your reply was big and helpful Big Grin Thanks again, everything is working fine now. Ill definately check your Youtube channel for some tutorials n stuffTongue
01-04-2017, 10:11 AM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#4
RE: Help needed with SetEntityActive in custom story

(01-04-2017, 10:11 AM)hagridas Wrote: I thought Amnesia is dead and didn't expect anyone to reply

Don't worry.
We're still a small group of people here!

Trying is the first step to success.
01-04-2017, 02:01 PM
Find




Users browsing this thread: 1 Guest(s)