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
|