Frictional Games Forum (read-only)

Full Version: Random sound at random time script help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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"falsefalse);
        
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.
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(0sounds_to_play.length()-1);
    
PlaySoundAtEntity(""sounds_to_play[Time], "Player" 0false);
    
    
// Make sure the minimum range is greater than 0
    //    However, it may be more practical to have a number greater than 10
    
AddTimer(asTimerRandFloat(1,60), "SoundTime");
}

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

    
// Never use 0 for time
    
AddTimer(asTimer0.02f"DoorCheck");

Hi, i have tried this code and i get this error on line 9 it says its missing and ; or ,.
(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.
Ok now im getting this no matching signatures to the addtimer on line 12. in the OnStart()
change Addtimer to AddTimer on line 12 (that is make the t a capital T).