Frictional Games Forum (read-only)
Random sound at random time script 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: Random sound at random time script help (/thread-11713.html)



Random sound at random time script help - Gamemakingdude - 12-06-2011

PHP Code:
void OnStart()
{
    
SetGlobalVarInt("Globalvar1", 0);
    
AddTimer("GlobalCheck", 0, "DoorCheck");
    
Addtimer("RandomSound",1.0f,"StartTiming");
}

void StartTiming(string &in asTimer) {
    
int Time = RandInt(1,5);
    
string TimeName = "";
    if(
Time == 1) {
        
TimeName = "1";
        }
    if(
Time == 2) {
        
TimeName = "2";
        }
    if(
Time == 3) {
        
TimeName = "3";
        }
    if(
Time == 4) {
        
TimeName = "4";
        }
    if(
Time == 5) {
        
TimeName = "5";
        }
    
AddTimer(TimeName,RandFloat(0,60),"SoundTime");
}
void SoundTime(string &in asTimer) {
    
string x = asTimer;
    if(
x=="1") {
        
Addtimer("RandomSound",1.0f,"StartTiming");
        
PlaySoundAtEntity("","walkandgrunt.snt","Player",0,false);
    }
    if(
x=="2") {
        
Addtimer("RandomSound",1.0f,"StartTiming");
        
PlaySoundAtEntity("","walkandgrunt.snt","Player",0,false);
    }
    if(
x=="3") {
        
Addtimer("RandomSound",1.0f,"StartTiming");
        
PlaySoundAtEntity("","walkandgrunt.snt","Player",0,false);
    }
    if(
x=="4") {
        
Addtimer("RandomSound",1.0f,"StartTiming");
        
PlaySoundAtEntity("","walkandgrunt.snt","Player",0,false);
    }
    if(
x=="5") {
        
Addtimer("RandomSound",1.0f,"StartTiming");
        
PlaySoundAtEntity("","walkandgrunt.snt","Player",0,false);
    }
}

void DoorCheck(string &in asTimer)
{
if(
GetGlobalVarInt("Globalvar1") == 1)
    {
        
SetSwingDoorLocked("elevator_door_1", false, false);
        
RemoveTimer("GlobalCheck");
    }
else
{
AddTimer("GlobalCheck", 0, "DoorCheck");
}
} 

I get signature matching errors at the AddTimer parts. If there's an simplier way then please go ahead and suggest.


RE: Random sound at random time script help - Your Computer - 12-06-2011

You have Addtimer in a lot of places where AddTimer should be.

Here's a more efficient way of doing what you want, though (code not tested):

PHP Code:
const string[] sounds_to_play = {
    
"walkandgrunt.snt",
    
"walkandgrunt.snt",
    
"walkandgrunt.snt",
    
"walkandgrunt.snt",
    
"walkandgrunt.snt"
};

void OnStart()
{
    
DoorCheck("GlobalCheck");
    
Addtimer("RandomSound", 1.0f, "SoundTime");
}

void SoundTime(string &in asTimer)
{
    
int Time = RandInt(0, sounds_to_play.length()-1);
    
PlaySoundAtEntity("", sounds_to_play[Time], "Player" , 0, false);
    
    
// Make sure the minimum range is greater than 0
    //    However, it may be more practical to have a number greater than 10
    
AddTimer(asTimer, RandFloat(1,60), "SoundTime");
}

void DoorCheck(string &in asTimer)
{
    if(
GetGlobalVarInt("Globalvar1") == 1)
    {
        
SetSwingDoorLocked("elevator_door_1", false, false);
        return;
    }

    
// Never use 0 for time
    
AddTimer(asTimer, 0.02f, "DoorCheck");
} 



RE: Random sound at random time script help - Gamemakingdude - 12-06-2011

Hi, i have tried this code and i get this error on line 9 it says its missing and ; or ,.


RE: Random sound at random time script help - Your Computer - 12-06-2011

(12-06-2011, 08:55 AM)Gamemakingdude Wrote: Hi, i have tried this code and i get this error on line 9 it says its missing and ; or ,.

Whoops, yeah, the string declaration at the top i forgot to put a ; at the end of it. I have fixed the error in my previous post.


RE: Random sound at random time script help - Gamemakingdude - 12-06-2011

Ok now im getting this no matching signatures to the addtimer on line 12. in the OnStart()


RE: Random sound at random time script help - jens - 12-06-2011

change Addtimer to AddTimer on line 12 (that is make the t a capital T).