Frictional Games Forum (read-only)
A little understanding needed... - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: A little understanding needed... (/thread-18257.html)



A little understanding needed... - KingWolf - 09-10-2012

So, I was helping Nemet Robert with his unofficial map, and I thought of something. Alas, I'm unable to script it.

I've tried contacting Robby, but he didn't respond. I'm guessing he's still sleeping, or forgot to turn his phone on.

Either way, I have a script zone that triggers a small event (Sanity Damage), and that also triggers a timer. Now, I want that timer to randomly choose 1 event from 4 different events once it depletes.

The events (all can be called by timers) are.

#1 = A sound that plays.
#2 = A sudden increase in the player's FOV. Later on, it returns to normal, followed by the same sound that #1 plays.
#3 = A short hearbeat, soon followed by a small decrease in the player's FOV, and the vision turns blood-red.
#4 = Triggers a particle effect, plays the same sound as #1, triggers the sanity damage again, then plays a scream sound.

Now I can script the events themselves, I just don't know how to script the timer to randomly choose 1 from these 4 events.

If somebody is successful, they will receive a +1 from both me and Robby too!


RE: A little understanding needed... - Robby - 09-10-2012

Ok, ^ refers to me. Phone was in charger, set to silent mode. Just recently noticed the call.

Anyway, it seems like this script is possible, but it is outside my "experience box". I know basic scripting and all, but this is advanced, and I find it difficult. I have little to no understanding in this section (the basic section is 100% over here).

I'm guessing you'll need to use some "float" or "int" thingies (can't find words) here. That is something I am not familiar with.


RE: A little understanding needed... - Adny - 09-10-2012

RandInt + Var's seems like the easiest thing:


void OnStart()
{
SetLocalVarInt("RandomEvent", 0);
///add whatever other callback to set the timers, etc
}

/*
Assuming you have a basic timer set up and it is called, you can do something like this:
*/

void timer_name(string &in asTimer)
{
AddLocalVarInt("RandomEvent", RandInt(1,4));

if(GetLocalVarInt("RandomEvent") == 1)
{
event1();
}
if(GetLocalVarInt("RandomEvent") == 2)
{
event2();
}
if(GetLocalVarInt("RandomEvent") == 3)
{
event3();
}
if(GetLocalVarInt("RandomEvent") == 4)
{
event4();
}
}

void event1()
{
///do event 1 stuff
}

void event2()
{
///do event 2 stuff
}

void event3()
{
///do event 3 stuff
}

void event4()
{
///do event 4 stuff
}


Hope that helped! Also, instead of calling each function like "void event4()", you could put the event stuff inside the if statement to avoid clutter. I just add the extra step to help organize.


RE: A little understanding needed... - Kreekakon - 09-10-2012

First set a LocalInt, or global depending on your needs, and do it like so:

Code:
SetLocalVarInt("blahblah", RandInt(1,4));

The rand at the end will randomly give the generated int a value ranging from the starting number to the last number, in this case 1 to 4. Which means it could 1, 2, 3, or 4.

Then when your timer depletes have it run a script like this:

Code:
switch (GetLocalVarInt("blahblah"))
{
case 1:
{
//stuff
break;
}
case 2:
{
//stuff
break;
}
case 3:
{
//stuff
break;
}
case 4:
{
//stuff
break;
}

Put what you want to do inside the "cases", and whatever number gets picked, it will run that script.


RE: A little understanding needed... - Robby - 09-10-2012

Okay, this will take me a little time to implement. The map's script file is a little messy. Give me 15 minutes, tops!

EDIT: Doing both isn't easy. Give me some time. *refers to Kreekakon, already trying andryrocking123's post*


RE: A little understanding needed... - Kreekakon - 09-10-2012

(09-10-2012, 08:16 AM)Nemet Robert Wrote: EDIT: Doing both isn't easy. Give me some time. *refers to Kreekakon, already trying andryrocking123's post*
No one's rushing you. Take your time. Far as I know, both mine, and andy's methods will work, just pick whichever you like.


RE: A little understanding needed... - Robby - 09-10-2012

(09-10-2012, 08:21 AM)Kreekakon Wrote:
(09-10-2012, 08:16 AM)Nemet Robert Wrote: EDIT: Doing both isn't easy. Give me some time. *refers to Kreekakon, already trying andryrocking123's post*
No one's rushing you. Take your time. Far as I know, both mine, and andy's methods will work, just pick whichever you like.
It is complicated. For me, that is. Almost done, just got to rename some things, and re-arrange the script file a bit.

EDIT: Massive load of errors. Approx. 6 errors in total. Must've done something wrong. I'll retry.

EDIT2: I found the problem. I kept doing something I shouldn't have. Fixing now.


RE: A little understanding needed... - FlawlessHappiness - 09-10-2012

You could also use:

AddTimer("Timer_"+RandInt(1, 4), 3, "Timer");


void Timer(string &in asTimer)
{
if(asTimer == Timer_1)
{
Event_1();
}


if(asTimer == Timer_2)
{
Event_2();
}


if(asTimer == Timer_3)
{
Event_3();
}


if(asTimer == Timer_4)
{
Event_4();
}
}


RE: A little understanding needed... - Robby - 09-10-2012

EDIT: Fully tested and works. So scared right now! I knew what was supposed to happen, and out of those 4 events, one was randomly chosen, but it seemed to hate the 4th event (didn't want to happen). Until, after the 5th try, it suddenly did it, and I can officially say that my spirit landed in my ass! Also used the wrong sound back there, thus resulting in this scare.

KingWolf, when you see this, mark this thread as "[SOLVED]". I can confirm it works (I can just send you those files, since I am the dev here, and you're my assistant.) Or should I send you a video instead?

+1 given to Kreekakon and andyrockin123. KingWolf shall do the same.


RE: A little understanding needed... - KingWolf - 09-10-2012

Marked as solved. Problem's gone. Thanks. And +1 was given to both peeps, as per Robby's instructions.

Tested the map myself after Robby sent me the script file, and yes it works. Better than I thought.

I'll hang with sound creation, while you fix the map and scripts up. I'll also do some mapping if needs be.