Linus Ågren
Senior Member
Posts: 309
Threads: 58
Joined: Jan 2011
Reputation:
5
|
Doing nothing on an IF & Resetting level on death?
Well, I got two questions.
First one, if you got a script with an IF statement such as:
if(GetSwingDoorLocked("mansion_5") == true) SetMessage("Level_01", "GruntChaseLockedDoor", 0);
else
If you don't want anything to happen on the ELSE, how do you stop the script?
I've heard that you can use a BREAK in some languages but I'm not too sure here.
And for my second question, as my friends die on my customs, (lol ) and like, a door is closed and locked, or a monster spawns and they have to redo from start, all things and events are already done. How do you make it so that they will become back to normal if you die? (If you have a checkpoint at one place, I don't want the events before that to get resetted)
Thanks in advance
Creator of The Dark Treasure.
|
|
02-10-2011, 11:43 PM |
|
Nye
Senior Member
Posts: 250
Threads: 8
Joined: Jan 2011
Reputation:
2
|
RE: Doing nothing on an IF & Resetting level on death?
(02-10-2011, 11:43 PM)junkfood2121 Wrote: Well, I got two questions.
First one, if you got a script with an IF statement such as:
if(GetSwingDoorLocked("mansion_5") == true) SetMessage("Level_01", "GruntChaseLockedDoor", 0);
else
If you don't want anything to happen on the ELSE, how do you stop the script?
I've heard that you can use a BREAK in some languages but I'm not too sure here.
And for my second question, as my friends die on my customs, (lol ) and like, a door is closed and locked, or a monster spawns and they have to redo from start, all things and events are already done. How do you make it so that they will become back to normal if you die? (If you have a checkpoint at one place, I don't want the events before that to get resetted)
Thanks in advance
FIRST QUESTION:
----------------------
Just use empty curly brackets. Like this:
if(GetSwingDoorLocked("mansion_5") == true)
{
SetMessage("Level_01", "GruntChaseLockedDoor", 0);
}
else
{
INSERT STUFF HERE
}
If you want to leave the ELSE blank, you DON'T even need to include the ELSE. I know where you are coming from, having programmed in other languages. The language used for scripting here does not require you to use an ELSE, even if its blank
The below code 'SHOULD' work fine:
if(GetSwingDoorLocked("mansion_5") == true)
{
SetMessage("Level_01", "GruntChaseLockedDoor", 0);
}
SECOND QUESTION:
-------------------------
If you are concerned about scripted events being undone, you will need to use local variables. (Local, meaning they are specific to just the current map and not the entire custom story, which are global variables).
When you trigger a scripted event, be sure to include the following line:
SetLocalVarInt(string& asName, int alVal);
For example, assume I lock a door named "door1" behind the player. I will use this code:
void OnStart()
{
AddEntityCollideCallback("Player", "TRIGGERNAME", "DOOREVENT", false, 1); //<---SET TO FALSE, SO THE PROCEDURE CAN REPEAT!
SetLocalVarInt("EVENTDONE", 0);
}
void DOOREVENT(string &in asParent , string &in asChild , int alState)
{
if(GetLocalVarInt("EVENTDONE") == 0)
{
SetLocalVarInt("EVENTDONE", 1);
*blah blah, locking door etc.*
}
}
Then, just add a point, eg. when the player spawns, where you set the "EVENTDONE" variable back to 0 again.
Hope this helped!
(This post was last modified: 02-11-2011, 12:21 AM by Nye.)
|
|
02-11-2011, 12:12 AM |
|
jens
Frictional Games
Posts: 4,093
Threads: 199
Joined: Apr 2006
Reputation:
202
|
RE: Doing nothing on an IF & Resetting level on death?
A tip if you want to put things back if you die, like a swingdoor that was locked but got unlocked and then the player died, you can use ResetProp("name_of_swingdoor");
|
|
02-11-2011, 06:33 AM |
|
Linus Ågren
Senior Member
Posts: 309
Threads: 58
Joined: Jan 2011
Reputation:
5
|
RE: Doing nothing on an IF & Resetting level on death?
Thanks! The first code worked x)
The second worked aswell, but I got a problem.
When changing the val to false on the collidecallback, each time I run into the collide box the event appears so you can run back and fourth into the box to make the event reappear. Any idea on how to fix it?
My code to make sure I did correct
//Collide callbacks
AddEntityCollideCallback("Player", "MoveStatues", "CollideMoveStatues", false, 1);
AddEntityCollideCallback("Player", "ShutDoor", "CollideShutDoor", true, 1);
AddEntityCollideCallback("Player", "SoundSteps", "CollideSoundSteps", true, 1);
AddEntityCollideCallback("Player", "StrangeSound_1", "CollideStrangeSound_1", true, 1);
AddEntityCollideCallback("Player", "StrangeSound_2", "CollideStrangeSound_2", true, 1);
SetLocalVarInt("EVENTDONE", 0);
}
and the other code:
//Throws the two statues heads off and creates dust at them
void CollideMoveStatues(string &in asParent, string &in asChild, int alState)
{
if(GetLocalVarInt("EVENTDONE") == 0)
{
AddPropImpulse("Statue_1", 2.0f, 5.0f, 2.0f, "World");
CreateParticleSystemAtEntity("StatueBehead_1", "ps_dust_impact_vert.ps", "StatueDust_1", false);
AddPropImpulse("Statue_2", -2.0f, 5.0f, -2.0f, "World");
CreateParticleSystemAtEntity("StatueBehead_2", "ps_dust_impact_vert.ps", "StatueDust_2", false);
GiveSanityDamage(3.0f, true);
PlaySoundAtEntity("StatueScare", "react_breath", "Player", 0.5f, false);
}
}
Creator of The Dark Treasure.
|
|
02-11-2011, 08:14 AM |
|
Nye
Senior Member
Posts: 250
Threads: 8
Joined: Jan 2011
Reputation:
2
|
RE: Doing nothing on an IF & Resetting level on death?
(02-11-2011, 08:14 AM)junkfood2121 Wrote: Thanks! The first code worked x)
The second worked aswell, but I got a problem.
When changing the val to false on the collidecallback, each time I run into the collide box the event appears so you can run back and fourth into the box to make the event reappear. Any idea on how to fix it?
My code to make sure I did correct
//Collide callbacks
AddEntityCollideCallback("Player", "MoveStatues", "CollideMoveStatues", false, 1);
AddEntityCollideCallback("Player", "ShutDoor", "CollideShutDoor", true, 1);
AddEntityCollideCallback("Player", "SoundSteps", "CollideSoundSteps", true, 1);
AddEntityCollideCallback("Player", "StrangeSound_1", "CollideStrangeSound_1", true, 1);
AddEntityCollideCallback("Player", "StrangeSound_2", "CollideStrangeSound_2", true, 1);
SetLocalVarInt("EVENTDONE", 0);
}
and the other code:
//Throws the two statues heads off and creates dust at them
void CollideMoveStatues(string &in asParent, string &in asChild, int alState)
{
if(GetLocalVarInt("EVENTDONE") == 0)
{
AddPropImpulse("Statue_1", 2.0f, 5.0f, 2.0f, "World");
CreateParticleSystemAtEntity("StatueBehead_1", "ps_dust_impact_vert.ps", "StatueDust_1", false);
AddPropImpulse("Statue_2", -2.0f, 5.0f, -2.0f, "World");
CreateParticleSystemAtEntity("StatueBehead_2", "ps_dust_impact_vert.ps", "StatueDust_2", false);
GiveSanityDamage(3.0f, true);
PlaySoundAtEntity("StatueScare", "react_breath", "Player", 0.5f, false);
}
}
When you run the event after EVENTDONE=0, did you remember to set the local variant EVENTDONE to 1? That way, the procedure will repeat itself but nothing will happen until EVENTDONE =0 again. This is what I did in the example I think (sent from my phone, I might have made a mistake :p)
|
|
02-11-2011, 08:24 AM |
|
Linus Ågren
Senior Member
Posts: 309
Threads: 58
Joined: Jan 2011
Reputation:
5
|
RE: Doing nothing on an IF & Resetting level on death?
Mm.. I've done it like this:
AddEntityCollideCallback("Player", "MoveStatues", "CollideMoveStatues", false, 1);
The script is set to false as you said, and it doesn't repat now ^^
I also have this script within "OnStart":
SetLocalVarInt("EVENTDONE", 0);
However, it doesn't work if you die. It doesn't do anything if you run through the triggerbox again.
void CollideMoveStatues(string &in asParent, string &in asChild, int alState)
{
if(GetLocalVarInt("EVENTDONE") == 0)
{
SetLocalVarInt("EVENTDONE", 1);
AddPropImpulse("Statue_1", 2.0f, 5.0f, 2.0f, "World");
CreateParticleSystemAtEntity("StatueBehead_1", "ps_dust_impact_vert.ps", "StatueDust_1", false);
AddPropImpulse("Statue_2", -2.0f, 5.0f, -2.0f, "World");
CreateParticleSystemAtEntity("StatueBehead_2", "ps_dust_impact_vert.ps", "StatueDust_2", false);
GiveSanityDamage(3.0f, true);
PlaySoundAtEntity("StatueScare", "react_breath", "Player", 0.5f, false);
}
}
I have my code like that.
Creator of The Dark Treasure.
|
|
02-11-2011, 02:57 PM |
|
Nye
Senior Member
Posts: 250
Threads: 8
Joined: Jan 2011
Reputation:
2
|
RE: Doing nothing on an IF & Resetting level on death?
(02-11-2011, 02:57 PM)junkfood2121 Wrote: Mm.. I've done it like this:
AddEntityCollideCallback("Player", "MoveStatues", "CollideMoveStatues", false, 1);
The script is set to false as you said, and it doesn't repat now ^^
I also have this script within "OnStart":
SetLocalVarInt("EVENTDONE", 0);
However, it doesn't work if you die. It doesn't do anything if you run through the triggerbox again.
void CollideMoveStatues(string &in asParent, string &in asChild, int alState)
{
if(GetLocalVarInt("EVENTDONE") == 0)
{
SetLocalVarInt("EVENTDONE", 1);
AddPropImpulse("Statue_1", 2.0f, 5.0f, 2.0f, "World");
CreateParticleSystemAtEntity("StatueBehead_1", "ps_dust_impact_vert.ps", "StatueDust_1", false);
AddPropImpulse("Statue_2", -2.0f, 5.0f, -2.0f, "World");
CreateParticleSystemAtEntity("StatueBehead_2", "ps_dust_impact_vert.ps", "StatueDust_2", false);
GiveSanityDamage(3.0f, true);
PlaySoundAtEntity("StatueScare", "react_breath", "Player", 0.5f, false);
}
}
I have my code like that.
Somehow, you need to set the local variable EVENTDONE to 0 again. This is what I would do...
On the spawn point, make a tiny script area, to act as a trigger. Make it small, so that there is a very low chance the player will backtrack and step on it. Then, when the player spawns, he/she will trigger it and you can do this to set it back to 0:
SetLocalVarInt("EVENTDONE", 0);
There might be a better way, but the game was not built to accomodate this, so I don't think there is an "On Death" sort of procedure.
|
|
02-11-2011, 05:55 PM |
|
|