PutraenusAlivius
Posting Freak
Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation:
119
|
Random Scares
Hello everyone! I've used this technique in my custom story, A Forgotten Memory. Special thanks for people that helped me to understand this. Using this will randomize the scares you will have. This gives the CS/FC replay value.
It's like this, each playthrough had different results. Example;
First Playthrough : You pass out and wakes up in some other place.
Second Playthrough : A door blew open.
It's good. Why? Because the Player will think like he knew, but he didn't.
Okay, enough with the chattering. Let's start.
void OnStart() { AddEntityCollideCallback("Player", "ScriptArea_1", "PlrCollideSwitch", true, 1); }
void PlrCollideSwitch(string &in asParent, string &in asChild, int alState) { int x = RandInt(1, 5); switch(x) { case 1: //Scare 1 break; case 2: //Scare 2 break; case 3: //Scare 3 break; case 4: //Scare 4 break; case 5: //Scare 5 break; } }
Get it? Integer is RandInt, and it will randomize between 1 and 5 as 1 is the minimal and 5 is the maximal. If one of the cases fit with the inputInteger, it will do that case until the first break is reached. For this, you don't need curly brackets({}) to envelope code, but you need breaks.
Just change the
//Scare #CaseNumber
to what scare you want.
Even nobody including you (the creator) will know which one is picked.
This will give your custom story/full conversion replay value.
OFF-TOPIC:
Even Scares are now can be randomized. I'm so smart.
EDIT:
It seems like the script gives everyone an error. I already changed it and now tell me if it works or not.
"Veni, vidi, vici."
"I came, I saw, I conquered."
|
|
04-16-2013, 03:10 PM |
|
Yare
Junior Member
Posts: 22
Threads: 2
Joined: Mar 2013
Reputation:
0
|
RE: Random Scares
Most of scripts in CS I am making now is also random, but in a little bit different way. I mostly use Random Int to get an event activate or not. For example, I put some script area in the middle of the room and create RandInt(1,4). Then, with conditional statement "if", I check if randomized Int equals 1 (or any other number in the range). If it does, the event activates. It means, that there is 25% chance for the event to activate. In other words, the more you walk around the room, the more chance you have to make the scare happen.
Sometimes I add timers to those events with random time, usually ranging from 0 to 5 seconds. That means, the event may occur instantly as well as with uncertain delay.
I tested some of my random events already and this... "randomness" really makes them much more alive. They are not anymore so stiff and occuring instantly after you walk into some area.
|
|
04-16-2013, 03:39 PM |
|
PutraenusAlivius
Posting Freak
Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation:
119
|
RE: Random Scares
(04-16-2013, 03:39 PM)Yare Wrote: Most of scripts in CS I am making now is also random, but in a little bit different way. I mostly use Random Int to get an event activate or not. For example, I put some script area in the middle of the room and create RandInt(1,4). Then, with conditional statement "if", I check if randomized Int equals 1 (or any other number in the range). If it does, the event activates. It means, that there is 25% chance for the event to activate. In other words, the more you walk around the room, the more chance you have to make the scare happen.
Sometimes I add timers to those events with random time, usually ranging from 0 to 5 seconds. That means, the event may occur instantly as well as with uncertain delay.
I tested some of my random events already and this... "randomness" really makes them much more alive. They are not anymore so stiff and occuring instantly after you walk into some area.
Switch statements are more useful as they all can be put into just one function.
"Veni, vidi, vici."
"I came, I saw, I conquered."
|
|
04-17-2013, 06:10 AM |
|
Yare
Junior Member
Posts: 22
Threads: 2
Joined: Mar 2013
Reputation:
0
|
RE: Random Scares
Well, in your example it's surely much more comfortable. But in calculating a chance of event occurence, it doesn't really matter whether I use switch or if. Here is an example of sound function, that consists of both our ideas:
void SoundArea8(string &in asParent, string &in asChild, int alState)
{
SetLocalVarInt("EventChance", RandInt(1,3));
if (GetLocalVarInt("EventChance") == 1) AddTimer("", RandInt(0,3), "SoundArea8Delay");
}
void SoundArea8Delay(string &in asTimer)
{
SetLocalVarInt("WhatSound", RandInt(1,4));
switch(GetLocalVarInt("WhatSound"))
{
case 1:
SetLocalVarInt("WhatArea", RandInt(46,49));
PlaySoundAtEntity("", "18_blow_wind.snt", "ScriptArea_"+GetLocalVarInt("WhatArea"), 0, false);
break;
case 2:
SetLocalVarInt("WhatArea", RandInt(46,49));
PlaySoundAtEntity("", "15_man01_whimp.snt", "ScriptArea_"+GetLocalVarInt("WhatArea"), 0, false);
break;
case 3:
SetLocalVarInt("WhatArea", RandInt(46,49));
PlaySoundAtEntity("", "05_whine.snt", "ScriptArea_"+GetLocalVarInt("WhatArea"), 0, false);
break;
case 4:
SetLocalVarInt("WhatArea", RandInt(46,49));
PlaySoundAtEntity("", "suitor/amb_idle_whimp.snt", "ScriptArea_"+GetLocalVarInt("WhatArea"), 0, false);
break;
}
}
The script has 30% chance to activate (it works every time you walk into area). It can be activated instantly or with not more than 3 seconds delay. It plays one of four sounds in one of four script areas. I know it looks more complicated with full variables declarations, but somehow only in this way everything is clear to me.
|
|
04-17-2013, 12:44 PM |
|
PutraenusAlivius
Posting Freak
Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation:
119
|
RE: Random Scares
(04-17-2013, 12:44 PM)Yare Wrote: Well, in your example it's surely much more comfortable. But in calculating a chance of event occurence, it doesn't really matter whether I use switch or if. Here is an example of sound function, that consists of both our ideas:
void SoundArea8(string &in asParent, string &in asChild, int alState)
{
SetLocalVarInt("EventChance", RandInt(1,3));
if (GetLocalVarInt("EventChance") == 1) AddTimer("", RandInt(0,3), "SoundArea8Delay");
}
void SoundArea8Delay(string &in asTimer)
{
SetLocalVarInt("WhatSound", RandInt(1,4));
switch(GetLocalVarInt("WhatSound"))
{
case 1:
SetLocalVarInt("WhatArea", RandInt(46,49));
PlaySoundAtEntity("", "18_blow_wind.snt", "ScriptArea_"+GetLocalVarInt("WhatArea"), 0, false);
break;
case 2:
SetLocalVarInt("WhatArea", RandInt(46,49));
PlaySoundAtEntity("", "15_man01_whimp.snt", "ScriptArea_"+GetLocalVarInt("WhatArea"), 0, false);
break;
case 3:
SetLocalVarInt("WhatArea", RandInt(46,49));
PlaySoundAtEntity("", "05_whine.snt", "ScriptArea_"+GetLocalVarInt("WhatArea"), 0, false);
break;
case 4:
SetLocalVarInt("WhatArea", RandInt(46,49));
PlaySoundAtEntity("", "suitor/amb_idle_whimp.snt", "ScriptArea_"+GetLocalVarInt("WhatArea"), 0, false);
break;
}
}
The script has 30% chance to activate (it works every time you walk into area). It can be activated instantly or with not more than 3 seconds delay. It plays one of four sounds in one of four script areas. I know it looks more complicated with full variables declarations, but somehow only in this way everything is clear to me.
Does it work? Because I spotted one error and I want you to confirm that it worked or not.
"Veni, vidi, vici."
"I came, I saw, I conquered."
|
|
04-17-2013, 12:51 PM |
|
Yare
Junior Member
Posts: 22
Threads: 2
Joined: Mar 2013
Reputation:
0
|
RE: Random Scares
I have just checked that once again. Seems like working properly.
|
|
04-17-2013, 01:55 PM |
|
VeNoMzTeamHysterical
Member
Posts: 240
Threads: 36
Joined: Dec 2012
Reputation:
3
|
RE: Random Scares
really nice thx
|
|
04-17-2013, 02:04 PM |
|
FlawlessHappiness
Posting Freak
Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation:
171
|
RE: Random Scares
can a switch script determine if the case has been used before?
Trying is the first step to success.
|
|
04-18-2013, 11:11 AM |
|
PutraenusAlivius
Posting Freak
Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation:
119
|
RE: Random Scares
(04-18-2013, 11:11 AM)BeeKayK Wrote: can a switch script determine if the case has been used before?
Dunno.
"Veni, vidi, vici."
"I came, I saw, I conquered."
|
|
04-18-2013, 11:58 AM |
|
Your Computer
SCAN ME!
Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation:
235
|
RE: Random Scares
(04-18-2013, 11:11 AM)BeeKayK Wrote: can a switch script determine if the case has been used before?
Switch statements normally check against integer values, and an integer value isn't enough information to check if something has been used before. If statements check against boolean values, normally through the use of boolean operators or values that can be implicitly converted into a boolean value. Unfortunately, AngelScript scripting (at least the version that comes with Amnesia) doesn't implicitly convert other data types into boolean values for if statement conditions.
|
|
04-18-2013, 12:10 PM |
|
|