Frictional Games Forum (read-only)
Scripting, need urgent help! - 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: Scripting, need urgent help! (/thread-9259.html)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13


RE: Scripting, need urgent help! - seth1466 - 07-28-2011

Yay we are making good progress thanks to everyone ^^


RE: Scripting, need urgent help! - JetlinerX - 07-28-2011

All code has been figured out, I will post with any new problems! Thanks so much everyone!


RE: Scripting, need urgent help! - JetlinerX - 07-29-2011

Anyway to delay the sounds just a tad so they dont sound so immediate, and the character doesnt have a 100% on time reaction?


RE: Scripting, need urgent help! - DRedshot - 07-29-2011

Yep its possible, to make sounds more natural i usually put the FadeIn time to about 0.5f, but if you want to delay it, then instead of putting - "PlayGuiSound" put -
AddTimer("" , 0.1f , "Delay");

then put

void Delay(string &in asTimer)
{
PlayGuiSound("" , );
}

of course it doesnt have to be GuiSound, it can also be PlaySoundAtEntity Smile


RE: Scripting, need urgent help! - Apjjm - 07-29-2011

(07-29-2011, 12:58 AM)JetlinerX Wrote: Anyway to delay the sounds just a tad so they dont sound so immediate, and the character doesnt have a 100% on time reaction?

Delaying sounds? Try this
Code:
int getDigit(uint8 digit) {
    int d = digit-48; //48 is ASCII code for 0
    return ((d >= 0)&&(d<=9)) ? d : -1;
}
int parseStringINT(string str) {
    int output = 0;
    for(int i=0; i<str.length(); i++)
     {
      int digit = getDigit(str[i]);
      if(digit > -1) output = 10*output+digit;
     }
    return output;
}
void _delaysndPlay(string &in sndtmr)
{
  int i = parseStringINT(sndtmr);
  string name = GetLocalVarString("_delaysnd_Name_"+i);
  string file = GetLocalVarString("_delaysnd_File_"+i);
  string ent = GetLocalVarString("_delaysnd_Ent_"+i);
  float fade = GetLocalVarFloat("_delaysnd_Fade_"+i);
  bool save = (GetLocalVarInt("_delaysnd_Sv_"+i)==1);
  PlaySoundAtEntity(name,file,ent,fade,save);
}

//This is the function you want to call!
void delayPlaySoundAtEntity(float afDelay, string asSoundName, string asSoundFile, string asEntity, float afFadeTime, bool abSaveSound)
{
   int i = GetLocalVarInt("_delaysnd_Count");
   AddLocalVarInt("_delaysnd_Count",1);
   SetLocalVarString("_delaysnd_Name_"+i,asSoundName);
   SetLocalVarString("_delaysnd_File_"+i,asSoundFile);
   SetLocalVarString("_delaysnd_Ent_"+i,asSoundName);
   SetLocalVarFloat("_delaysnd_Fade_"+i,afFadeTime);
   SetLocalVarInt("_delaysnd_Sv_"+i,abSaveSound?1:0);
   AddTimer("_delaysnd_timer"+i,afDelay,"_delaysndPlay");
}

That above is a general purpose delay sound play function, you can mod the parameters to suit any functions actually. This was written out in the reply window, so might have a syntax error in it, but aside from that it will work.

It works by creating an integer var, which is an "index". Then when the function is called the index value is incremented and remembered. We then append the index number onto the end of each variable's name so it has a unique name. This index "key" is then put in the timers name too! When the timer expires, the callback function is called, and the index is parsed out of the timer's name. This is then used to access all the variables we just stored, and pass them into the function.


RE: Scripting, need urgent help! - xiphirx - 07-29-2011

Isn't that a little too over-the-top there apjjm?

Code:
void OnEnter()
{
    AddGlobalVarInt("delayCnt", 0);
    AddGlobalVarString("delaySndName", '');
    AddGlobalVarString("delaySndFile", '');
    AddGlobalVarString("delaySndEntity", '');
}

void playSoundDelayed(string &soundName, string &soundFile, string &entity, float delay)
{
    AddTimer("_soundDelay_"+GetGlobalVarInt("delayCnt"), delay, "_soundDelayed");
}

void _soundDelayed()
{
    PlaySoundAtEntity(GetGlobalVarString("delaySndName"),
                GetGlobalVarString("delaySndFile"),
                GetGlobalVarString("delaySndEntity"), 0.0f, false);
}

(untested, should work)

?


RE: Scripting, need urgent help! - Apjjm - 07-29-2011

(07-29-2011, 01:51 AM)xiphirx Wrote: Isn't that a little too over-the-top there apjjm?
Not necessarily. What happens if you want queue more than one sound with the delay function? Having just one var for each argument then is not sufficient - but your idea is better if you can guarantee only one sound will be delayed at a time.


RE: Scripting, need urgent help! - xiphirx - 07-29-2011

That's true. Mine isn't flexible like yours.. but I was more or less talking about the string to int conversion lol. I would think that AngelScript wouldn't be so type strict... right? D:


RE: Scripting, need urgent help! - Apjjm - 07-29-2011

(07-29-2011, 02:37 AM)xiphirx Wrote: That's true. Mine isn't flexible like yours.. but I was more or less talking about the string to int conversion lol. I would think that AngelScript wouldn't be so type strict... right? D:

It moans when if you try to convert/cast it though Sad, so i had to make that int parsing code, sadly. Slightly OT but recently just had to revisit that script to make:
Code:
int[] parseNameToIntArray(string str) {
  int digit =0;
  int[] output = {0}; int j=0; bool finalise=false;
  for(int i=0; i<str.length(); i++)
     {
      digit = getDigit(str[i]);
      if(digit > -1) { output[j] = 10*output[j]+digit; finalise=true; }
      else if(finalise) { j = output.length(); output.resize(j+1); output[j]=0; finalise=false; }
     }
   return output;
}
To parse the set of separated unsigned numbers out of a string, which was much more of a headache Wink. Built in string parsing may be a feature in some angelscript extension though, but AFAIK none of those are enabled.


RE: Scripting, need urgent help! - JetlinerX - 07-29-2011

Ehhh... All that is really confusing! Ill try my best I guess...