Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random sound at random time script help
Gamemakingdude Offline
Senior Member

Posts: 470
Threads: 82
Joined: Nov 2010
Reputation: 9
#1
Random sound at random time script help

PHP Code: (Select All)
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.

Rep if like me or im helpful or you love my stories!
Stephanos house
12-06-2011, 06:09 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#2
RE: Random sound at random time script help

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: (Select All)
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");


Tutorials: From Noob to Pro
(This post was last modified: 12-06-2011, 10:03 AM by Your Computer.)
12-06-2011, 08:27 AM
Website Find
Gamemakingdude Offline
Senior Member

Posts: 470
Threads: 82
Joined: Nov 2010
Reputation: 9
#3
RE: Random sound at random time script help

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

Rep if like me or im helpful or you love my stories!
Stephanos house
12-06-2011, 08:55 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#4
RE: Random sound at random time script help

(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.

Tutorials: From Noob to Pro
12-06-2011, 10:04 AM
Website Find
Gamemakingdude Offline
Senior Member

Posts: 470
Threads: 82
Joined: Nov 2010
Reputation: 9
#5
RE: Random sound at random time script help

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

Rep if like me or im helpful or you love my stories!
Stephanos house
12-06-2011, 10:59 AM
Find
jens Offline
Frictional Games

Posts: 4,093
Threads: 199
Joined: Apr 2006
Reputation: 202
#6
RE: Random sound at random time script help

change Addtimer to AddTimer on line 12 (that is make the t a capital T).
12-06-2011, 11:39 AM
Website Find




Users browsing this thread: 1 Guest(s)