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
Script Help
GreyFox Offline
Member

Posts: 162
Threads: 23
Joined: Jul 2011
Reputation: 2
#1
Script Help

Hello, I'm new to this forum so go easy on me. I'm also a total noob when it comes to scripting. Anyways let's get straight to my question

In my custom story Demo thing, I want to have a monster in a room and then when you go to open the door it activates the monster and tries to kill you (Exactly like in the level "Storage" in the main game) Since I had no Idea how to do it I copyed everything from storage (The part i wanted) and then copyed the script (the part I needed). I don't know if this isn't allowed here I just though It was a smart way to figure something out. When I go to run the test of the level it loads and then I go to the correct door/area but nothing happens. No error or anything.

Sorry how long it is this is how long it was in their script (except for the door slamming behind you.) Also if I posted the script wrong I apologize

My Script:

////////////////////////////
// Run first time starting map
void OnStart()
{
AddUseItemCallback("", "LockedDoorKey_1", "LockedDoor_1", "UsedKeyOnDoor", true);
AddEntityCollideCallback("Player", "Scare_1", "CollideScare_1", true, 1);
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("LockedDoor_1", false, true);
PlaySoundAtEntity("", "unlock_door", "LockedDoor_1", 0, false);
RemoveItem("LockedDoorKey");
}

void CollideScare_1(string &in asParent, string &in asChild, int alState)
{
SetSwingDoorClosed("ScareDoor_1", true, true);
}

void CollideAreaCloseDoor(string &in asParent, string &in asChild, int alState)
{
if(GetLocalVarInt("GruntInRoomEvent") != 1) return;

//Door opens, make grunt active and normal
if(alState == -1){
AddEnemyPatrolNode("grunt_in_room", "PathNodeArea_4", 0.0f, "");
AddEnemyPatrolNode("grunt_in_room", "PathNodeArea_20", 0.0f, "");
AddEnemyPatrolNode("grunt_in_room", "PathNodeArea_43", 0.0f, "");
SetEntityActive("grunt_in_room", true);

CheckPoint("roomgrunt", "PlayerStartArea_1", "CPCallGruntRoom", "", "");

StopBangDoorEvent();
}

//Door closes, make grunt fictional but not if player is in room too
else{
if(GetLocalVarInt("PlayerInGruntArea") != 1)
StartBangDoorEvent();
}

}

//Check if grunt/player is in the room
void CollideAreaGruntRoom(string &in asParent, string &in asChild, int alState)
{
//If player in room, set var to make sure the grunt will not disable if door is closed.
if(asParent == "Player")
SetLocalVarInt("PlayerInGruntArea", alState);

//Grunt leaves room, so all possible events are shutdown and grunt is just a normal chasing grunt happy with no worries in the world.
if(asParent == "grunt_in_room" && alState == -1){
SetLocalVarInt("GruntInRoomEvent", 2);
SetLocalVarInt("GruntBreakDoor", 3);
StopBangDoorEvent();
AddDebugMessage("Grunt left room", false);
}
}

//Check if player is close to the door outside of the room
void CollideAreaGruntRoomActivate(string &in asParent, string &in asChild, int alState)
{
if(GetLocalVarInt("GruntInRoomEvent") != 1) return;

if(alState == 1)
StartBangDoorEvent();

else
StopBangDoorEvent();
}

//Player comes closer to door, begin the banging
void StartBangDoorEvent()
{
ClearEnemyPatrolNodes("grunt_in_room");

SetEntityActive("grunt_in_room", false);

AddTimer("TimerEBangOnDoor", RandFloat(1.0f, 2.0f), "TimerEBangOnDoor");
}

//Player goes away, remove banging
void StopBangDoorEvent()
{
RemoveTimer("TimerEBangOnDoor");
SetLocalVarInt("TimerEBangOnDoor", 0);

//Event has occured 3 times, remove all, let grunt stay active and do not do event any more
if(GetLocalVarInt("GruntBreakDoor") == 3){
SetEntityActive("AreaGruntRoomActivate", false);
SetEntityActive("AreaGruntRoom", false);
SetEntityActive("AreaCloseDoor", false);

if(GetLocalVarInt("GruntInRoomEvent") != 3){
ClearEnemyPatrolNodes("grunt_in_room");
AddEnemyPatrolNode("grunt_in_room", "PathNodeArea_4", 0.0f, "");
AddEnemyPatrolNode("grunt_in_room", "PathNodeArea_20", 0.0f, "");
AddEnemyPatrolNode("grunt_in_room", "PathNodeArea_43", 0.0f, "");
SetEntityActive("grunt_in_room", true);
}
}
}

//The grunt noise and bang on door
void TimerEBangOnDoor(string &in asTimer)
{
string sEvent = asTimer; //Do not edit, sets timer loop function name.
AddLocalVarInt(sEvent, 1); //Do not edit, steps through timer loop events.
bool bPauseAtStep = false; //Do not edit, to pause or end the timer loop at specified step.

float fEventSpeed = 0.5f; //Set to preferred default time for the timer loop.

switch(GetLocalVarInt(sEvent)){
//////////
//Grunt screams
case 1:
BangOnDoorEffects("grunt", "grunt/notice.snt", false);
break;

//////////
//Grunt bang on door 1
case 2:
BangOnDoorEffects("bang1", "lurker_hit_wood.snt", true);
fEventSpeed = RandFloat(0.2f, 0.8f);
break;

//////////
//Grunt bang on door 2
case 3:
BangOnDoorEffects("bang2", "lurker_hit_wood.snt", true);
fEventSpeed = RandFloat(0.2f, 0.8f);
break;

//////////
//Grunt bang on door 3
case 4:
BangOnDoorEffects("bang3", "lurker_hit_wood.snt", true);
AddLocalVarInt("GruntBreakDoor", 1);

if(GetLocalVarInt("GruntBreakDoor") == 3)
StopBangDoorEvent();
break;


//////////
//End timer when no more steps in the event found.
default:
bPauseAtStep = true;
break;
}

if(!bPauseAtStep) AddTimer(sEvent, fEventSpeed, sEvent);
}

//Effects for each bang
void BangOnDoorEffects(string &in sName, string &in sSound, bool bParticle)
{
PlaySoundAtEntity(sName, sSound, "cellar_wood01_7", 0.0f, false);

if(bParticle)
CreateParticleSystemAtEntity("ps"+sName, "ps_hit_wood.ps", "cellar_wood01_7", false);
}

//Set variable to allow rod grunt to activate.
void EntityCallGruntRoomDisabled(string &in asEntity, string &in type)
{
AddDebugMessage("Grunt from room disabled.", false);

SetLocalVarInt("GruntInRoomEvent", 3);
}

//Checkpoint from room grunt
void CPCallGruntRoom(string &in asName, int alCount)
{
SetLocalVarInt("GruntInRoomEvent", 3);
ResetProp("cellar_wood01_7");

SetEntityActive("AreaGruntBoo", true);

AddEntityCollideCallback("Player", "AreaGruntBoo", "CollideAreaGruntBoo", true, 1);
}
void CollideAreaGruntBoo(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("boo", "grunt/amb_idle.snt", "AreaGruntBoo_1", 0.0f, false);

AddTimer("scare", 1.0f, "TimerPlayerReactions");
AddTimer("breath", 3.0f, "TimerPlayerReactions");
AddTimer("breathl", 5.0f, "TimerPlayerReactions");
}

////////////////////////////
// Run when entering map
void OnEnter()
{

}

///////////////////////////
//Run when leaving map
void OnLeave()
{

}



Current Project
Forgotten
07-12-2011, 05:13 PM
Find
Zypherzemus Offline
Member

Posts: 94
Threads: 7
Joined: Jul 2011
Reputation: 0
#2
RE: Script Help

Explain something to me.. Is the monster in the SAME room you are in when you try to open the door? or is he BEHIND the door you try to open?

And surprisingly, what you want to hapen is only about 3 lines of script long.

This will help you

void OnStart()
{
SetEntityPlayerInteractCallback("door", "MonsterActivate", true);
}

void MonsterActivate(string &in Entity)
{
SetEntityActive("Monster_1", true);
}

void OnEnter()
{
}

void OnLeave()
{
}

This is an example of what you want to happen. I'll explain.
"SetEntityPlayerInteractCallback" pretty much means you want something to happen when you interact with an entity, in this case, it's "door". "door" can be named anything you want as long as it matches up with the name of the entity in the HPL editor.
"MonsterActivate" is the name of the callback function, which can also be named whatever you want, it just has to match up with the callback itself "void MonsterActivate"
"void MonsterActivate" is where you put all the commands you want to happen once you interact with said entity ("door") In this case, you want the monster to activate which is "SetEntityActive". And yeah. Does that help any?
07-12-2011, 07:17 PM
Find
GreyFox Offline
Member

Posts: 162
Threads: 23
Joined: Jul 2011
Reputation: 2
#3
RE: Script Help

Yes that seems like a better idea. and yes when I open the door the enemy is behind the door. (I can show picture if you'd like) also I would like it following waypoints (so it doesn't get stuck, that used to happen in other levels before I did any scripting and just messed around).

1 More thing how did you make your script/example script in that code box?

And just so I understand better.

SetEntityPlayerInteractCallback("door", "MonsterActivate", true);
"door" Should be the Name of The Door I want Correct?
"MonsterActivate" Is the name of the script area in the Editor?
"true" What does the true part mean?

Current Project
Forgotten
07-12-2011, 07:26 PM
Find
Zypherzemus Offline
Member

Posts: 94
Threads: 7
Joined: Jul 2011
Reputation: 0
#4
RE: Script Help

(07-12-2011, 07:26 PM)GreyFox Wrote: Yes that seems like a better idea. and yes when I open the door the enemy is behind the door. (I can show picture if you'd like) also I would like it following waypoints (so it doesn't get stuck, that used to happen in other levels before I did any scripting and just messed around).

1 More thing how did you make your script/example script in that code box?

And just so I understand better.

SetEntityPlayerInteractCallback("door", "MonsterActivate", true);
"door" Should be the Name of The Door I want Correct?
"MonsterActivate" Is the name of the script area in the Editor?
"true" What does the true part mean?

Waypoints? Just set some pathnodes on the ground and the enemy will automatically follow them. (So I've heard) set them on the ground right ooutside the door, when you try to open it (I'm assuming it's locked) He'll break down the door while you run away, if he doesn't spot you, he'll just follow the pathnodes.

to put it in a box, click on the icon that looks like a "#" then you paste your code, then go up to where it says [close tags] click it, and then there ya go.

Yes, "door" is the name of what you named the door. like "mansion_8", or whatever you name, etc.
No, This function isn't a collide function so there would be no area to run into. The "area" would actually be you trying to open the door.
"MonsterActivate" is the callback function, like I said earlier, whatever you want to happen when you interact with that door goes in between the brackets of "void MonsterActivate" or whatever you decide to name the callback function.
as for the meanings:

void SetEntityPlayerInteractCallback(string& asName, string& asCallback, bool abRemoveOnInteraction);

Calls a function when the player interacts with a certain entity.
Callback syntax: void MyFunc(string &in entity)

asName - internal name
asCallback - function to call
abRemoveOnInteraction - determines whether the callback should be removed when the player interacts with the entity


All of the info on what each command and what it means can be found on that page link I added "This will help you"

Oh, here's a heads up:
"bool" (or boolean) just means either "true" or "false"
"int" (or integer) is exaclty what it says, an integer or "whole number" (-1, 0, 5, etc.)
"float" (float) is a decimal number (1.0, 0.5, 0.25, etc.)
(This post was last modified: 07-12-2011, 08:43 PM by Zypherzemus.)
07-12-2011, 08:38 PM
Find
GreyFox Offline
Member

Posts: 162
Threads: 23
Joined: Jul 2011
Reputation: 2
#5
RE: Script Help

Sorry to Bother again, but I have got an error now.

The Error Reads:
could not load script file blah blah (Standard Stuff)
main (21, 1) :ERR : Unexpected token '{'

I understand that it means it doesn't have to be there or something along those lines but if I remove that one Bracket or Both it still gives me an error.

{
    SetEntityPlayerInteractCallback("Mansion_5", "MonsterActivate", true);
}

    void MonsterActivate(string &in Entity)
{
    SetEntityActive("Frank", true);
}


Line 21 is the bracket Above SetEntityPlayerInteractCallback.

Thank you once again and I think this should be the last thing before it starts working. I hope in the future I can become more efficient at scripting lol.


Current Project
Forgotten
07-12-2011, 09:02 PM
Find
Kyle Offline
Posting Freak

Posts: 911
Threads: 36
Joined: Sep 2010
Reputation: 7
#6
RE: Script Help

There should be a legit location for the SetEntityPlayerInteractCallback, meaning for it to be put in a function.

Not sure of exactly what you're trying to do, but try this:

void OnStart()
{
    SetEntityPlayerInteractCallback("Mansion_5", "MonsterActivate", true);
}
void MonsterActivate(string &in Entity)
{
    SetEntityActive("Frank", true);
}

(This post was last modified: 07-12-2011, 09:05 PM by Kyle.)
07-12-2011, 09:05 PM
Find
GreyFox Offline
Member

Posts: 162
Threads: 23
Joined: Jul 2011
Reputation: 2
#7
RE: Script Help

Okay I tried moving around my script so my Monster activate and all that is at the start but now i get the same error but for Line 12, 1 which once again is {.

I don't know what to do. Looking at my script I noticed all the SetXXXXXXXX Commands are after the Void Commands except this one is that the problem?

////////////////////////////
// Run first time starting map
void OnStart()
{
    SetEntityPlayerInteractCallback("Mansion_5", "MonsterActivate", true);
}

void MonsterActivate(string &in Entity)
{
    SetEntityActive("Frank", true);
}

{
    AddUseItemCallback("", "LockedDoorKey_1", "LockedDoor_1", "UsedKeyOnDoor", true);    
    AddEntityCollideCallback("Player", "Scare_1", "CollideScare_1", true, 1);
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("LockedDoor_1", false, true);
    PlaySoundAtEntity("", "unlock_door", "LockedDoor_1", 0, false);
    RemoveItem("LockedDoorKey");
}

void CollideScare_1(string &in asParent, string &in asChild, int alState)
{
    SetSwingDoorClosed("ScareDoor_1", true, true);
    GiveSanityDamage(20, false);
}

////////////////////////////
// Run when entering map
void OnEnter()
{

}

///////////////////////////
//Run when leaving map
void OnLeave()
{

}


Thank you Once again
-Grey Fox

Current Project
Forgotten
07-13-2011, 07:05 PM
Find
Zypherzemus Offline
Member

Posts: 94
Threads: 7
Joined: Jul 2011
Reputation: 0
#8
RE: Script Help

(07-13-2011, 07:05 PM)GreyFox Wrote: Okay I tried moving around my script so my Monster activate and all that is at the start but now i get the same error but for Line 12, 1 which once again is {.

I don't know what to do. Looking at my script I noticed all the SetXXXXXXXX Commands are after the Void Commands except this one is that the problem?

////////////////////////////
// Run first time starting map
void OnStart()
{
    SetEntityPlayerInteractCallback("Mansion_5", "MonsterActivate", true);
}

void MonsterActivate(string &in Entity)
{
    SetEntityActive("Frank", true);
}

{
    AddUseItemCallback("", "LockedDoorKey_1", "LockedDoor_1", "UsedKeyOnDoor", true);    
    AddEntityCollideCallback("Player", "Scare_1", "CollideScare_1", true, 1);
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("LockedDoor_1", false, true);
    PlaySoundAtEntity("", "unlock_door", "LockedDoor_1", 0, false);
    RemoveItem("LockedDoorKey");
}

void CollideScare_1(string &in asParent, string &in asChild, int alState)
{
    SetSwingDoorClosed("ScareDoor_1", true, true);
    GiveSanityDamage(20, false);
}

////////////////////////////
// Run when entering map
void OnEnter()
{

}

///////////////////////////
//Run when leaving map
void OnLeave()
{

}


Thank you Once again
-Grey Fox

Your "AddUseItemCallback" and "AddEntityCollideCallback" both belong in the "void OnStart()"
like so:

////////////////////////////
// Run first time starting map
void OnStart()
{
SetEntityPlayerInteractCallback("Mansion_5", "MonsterActivate", true);
AddUseItemCallback("", "LockedDoorKey_1", "LockedDoor_1", "UsedKeyOnDoor", true);    
AddEntityCollideCallback("Player", "Scare_1", "CollideScare_1", true, 1);
}

void MonsterActivate(string &in Entity)
{
    SetEntityActive("Frank", true);
}


void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("LockedDoor_1", false, true);
    PlaySoundAtEntity("", "unlock_door", "LockedDoor_1", 0, false);
    RemoveItem("LockedDoorKey");
}

void CollideScare_1(string &in asParent, string &in asChild, int alState)
{
    SetSwingDoorClosed("ScareDoor_1", true, true);
    GiveSanityDamage(20, false);
}

////////////////////////////
// Run when entering map
void OnEnter()
{

}

///////////////////////////
//Run when leaving map
void OnLeave()
{

}

and also, "GiveSanityDamage" should have a decimal number instead of a whole number.
07-13-2011, 08:02 PM
Find
GreyFox Offline
Member

Posts: 162
Threads: 23
Joined: Jul 2011
Reputation: 2
#9
RE: Script Help

Oh My God! you fixed it thank you so much. I walked up to the door and Heard the Grunt's Noise and then heard him start walking Thank you thank you.

Is there any tip you can give me on how to know when to group stuff like that together?

-Grey Fox

Current Project
Forgotten
07-13-2011, 08:13 PM
Find
ferryadams11 Offline
Junior Member

Posts: 17
Threads: 1
Joined: Apr 2011
Reputation: 0
#10
RE: Script Help

that things are actually sort of the basics in the scripting
just look on youtube for. clrsub11 tutorial amnesia
07-13-2011, 08:24 PM
Find




Users browsing this thread: 1 Guest(s)