seth1466
Member
Posts: 59
Threads: 4
Joined: Jun 2011
Reputation:
6
|
RE: Scripting, need urgent help!
Yay we are making good progress thanks to everyone ^^
|
|
07-28-2011, 05:33 AM |
|
JetlinerX
Senior Member
Posts: 599
Threads: 49
Joined: Jun 2011
Reputation:
19
|
RE: Scripting, need urgent help!
All code has been figured out, I will post with any new problems! Thanks so much everyone!
(This post was last modified: 07-28-2011, 10:18 PM by JetlinerX.)
|
|
07-28-2011, 05:34 AM |
|
JetlinerX
Senior Member
Posts: 599
Threads: 49
Joined: Jun 2011
Reputation:
19
|
RE: Scripting, need urgent help!
Anyway to delay the sounds just a tad so they dont sound so immediate, and the character doesnt have a 100% on time reaction?
|
|
07-29-2011, 12:58 AM |
|
DRedshot
Senior Member
Posts: 374
Threads: 23
Joined: Jun 2011
Reputation:
11
|
RE: Scripting, need urgent help!
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
|
|
07-29-2011, 01:06 AM |
|
Apjjm
Is easy to say
Posts: 496
Threads: 18
Joined: Apr 2011
Reputation:
52
|
RE: Scripting, need urgent help!
(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
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.
(This post was last modified: 07-29-2011, 01:16 AM by Apjjm.)
|
|
07-29-2011, 01:11 AM |
|
xiphirx
Senior Member
Posts: 662
Threads: 16
Joined: Nov 2010
Reputation:
5
|
RE: Scripting, need urgent help!
Isn't that a little too over-the-top there apjjm?
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)
?
|
|
07-29-2011, 01:51 AM |
|
Apjjm
Is easy to say
Posts: 496
Threads: 18
Joined: Apr 2011
Reputation:
52
|
RE: Scripting, need urgent help!
(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.
(This post was last modified: 07-29-2011, 02:13 AM by Apjjm.)
|
|
07-29-2011, 02:04 AM |
|
xiphirx
Senior Member
Posts: 662
Threads: 16
Joined: Nov 2010
Reputation:
5
|
RE: Scripting, need urgent help!
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:
|
|
07-29-2011, 02:37 AM |
|
Apjjm
Is easy to say
Posts: 496
Threads: 18
Joined: Apr 2011
Reputation:
52
|
RE: Scripting, need urgent help!
(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 , so i had to make that int parsing code, sadly. Slightly OT but recently just had to revisit that script to make:
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 . Built in string parsing may be a feature in some angelscript extension though, but AFAIK none of those are enabled.
(This post was last modified: 07-29-2011, 03:08 AM by Apjjm.)
|
|
07-29-2011, 03:01 AM |
|
JetlinerX
Senior Member
Posts: 599
Threads: 49
Joined: Jun 2011
Reputation:
19
|
RE: Scripting, need urgent help!
Ehhh... All that is really confusing! Ill try my best I guess...
|
|
07-29-2011, 04:16 AM |
|
|