Author Topic: How to add a sound that loops when you walk in a room?  (Read 1179 times)

0 Members and 1 Guest are viewing this topic.

Offline ect0

  • - Original Poster (OP) -
  • Legless Crawler
  • Posts: 25
  • Country: us
  • Respect: 2
    • View Profile

How to add a sound that loops when you walk in a room?

« on: February 04, 2017, 08:45:52 am »
If you know can you like add me on steam?

[You are not allowed to view external links. Register or Login to see them]

Offline MegaMech43

  • Rotting Walker
  • Posts: 80
  • Country: ca
  • Respect: 16
    • megamech
    • View Profile
    • megamech.net

Re: How to add a sound that loops when you walk in a room?

« Reply #1 on: February 04, 2017, 12:07:03 pm »
Code: [Select]
//A comment is //comment. Compiler skips code with //
#using scripts\zm\_zm_utility; //use a script outside of current scope
while(1) { //loop begin. Run code while true. If 1 becomes zero loop stops.
ent = GetEnt("ent","targetname"); //locates an object named "ent". Make this a script_struct or script_origin
zm_utility::play_sound_at_pos("a_sound", ent.origin);  // play sound with name "a_sound" at the object
if (break_out_of_loop) {break;} //clause to stop the sound if necessary
wait(insert_sound_length_here); //ex. wait(3) stops code for 3 seconds
} //loop end

Put code in function. Run function with thread functionname()
« Last Edit: March 20, 2017, 07:29:58 am by MegaMech43 »

Offline Conbini2017

  • Rotting Walker
  • Posts: 79
  • Country: jp
  • Respect: 8
    • dadakhr
    • View Profile
  • WaW: conbini2017

Re: How to add a sound that loops when you walk in a room?

« Reply #2 on: March 20, 2017, 05:36:58 am »
Because I do not understand script at all,
please tell me in detail. :(

Offline MegaMech43

  • Rotting Walker
  • Posts: 80
  • Country: ca
  • Respect: 16
    • megamech
    • View Profile
    • megamech.net

Re: How to add a sound that loops when you walk in a room?

« Reply #3 on: March 20, 2017, 07:30:26 am »
Modified with more detail

Offline Conbini2017

  • Rotting Walker
  • Posts: 79
  • Country: jp
  • Respect: 8
    • dadakhr
    • View Profile
  • WaW: conbini2017

Re: How to add a sound that loops when you walk in a room?

« Reply #4 on: March 21, 2017, 12:31:20 am »
Thank you very much
How (break_out_of_loop) {break;} is used?

Offline MegaMech43

  • Rotting Walker
  • Posts: 80
  • Country: ca
  • Respect: 16
    • megamech
    • View Profile
    • megamech.net

Re: How to add a sound that loops when you walk in a room?

« Reply #5 on: March 22, 2017, 03:36:06 pm »
Depends on what you're doing. For example

if (variable_name) {break;}

(Code elsewhere)

if (blah) {variable_name = true;}
or you could just do
variable_name = true;
Now next time the code runs it will stop. Actually you probably want this code BEFORE the sound plays to prevent it from playing again.

Offline Cxwh

  • Legless Crawler
  • Posts: 45
  • Country: at
  • Respect: 12
    • GodAspire' Twitter Feed
    • View Profile
  • Skype: CxwhMods

Re: How to add a sound that loops when you walk in a room?

« Reply #6 on: March 29, 2017, 02:54:56 pm »
You'd do that using zones
12 year old music critic, quadrasexual Minecrafter, Linkin Park fan, Hentai enthusiast, intelligent atheist and vegan.

Offline MegaMech43

  • Rotting Walker
  • Posts: 80
  • Country: ca
  • Respect: 16
    • megamech
    • View Profile
    • megamech.net

Re: How to add a sound that loops when you walk in a room?

« Reply #7 on: March 29, 2017, 04:32:03 pm »
Not necessarily. You could make the zone trigger a script but the OP didn't specify. I find it easier to use a trigger.
My example didn't explain how to trigger the code. It's easy enough to figure out.
« Last Edit: March 29, 2017, 04:44:31 pm by MegaMech43 »

Offline Conbini2017

  • Rotting Walker
  • Posts: 79
  • Country: jp
  • Respect: 8
    • dadakhr
    • View Profile
  • WaW: conbini2017

Re: How to add a sound that loops when you walk in a room?

« Reply #8 on: April 01, 2017, 08:42:35 am »
Not necessarily. You could make the zone trigger a script but the OP didn't specify. I find it easier to use a trigger.
My example didn't explain how to trigger the code. It's easy enough to figure out.
Could you tell me how to use the zone?

Offline MegaMech43

  • Rotting Walker
  • Posts: 80
  • Country: ca
  • Respect: 16
    • megamech
    • View Profile
    • megamech.net

Re: How to add a sound that loops when you walk in a room?

« Reply #9 on: April 01, 2017, 11:23:31 am »
Make a trigger_multiple surround the entrance or the entire room, whatever.
Add a key/value and use these functions:
It's  up to you to make it work. You won't learn anything if I do it for you. Search the forums for answers how to use these if you can't figure out how or look it up on the API
Code: [Select]

trigger = GetEnt("damagebox", "targetname");

players = getplayers();

if(players[i] isTouching(trigger))


Offline Conbini2017

  • Rotting Walker
  • Posts: 79
  • Country: jp
  • Respect: 8
    • dadakhr
    • View Profile
  • WaW: conbini2017

Re: How to add a sound that loops when you walk in a room?

« Reply #10 on: April 16, 2017, 04:20:59 am »
Code: [Select]
//A comment is //comment. Compiler skips code with //
#using scripts\zm\_zm_utility; //use a script outside of current scope
while(1) { //loop begin. Run code while true. If 1 becomes zero loop stops.
ent = GetEnt("ent","targetname"); //locates an object named "ent". Make this a script_struct or script_origin
zm_utility::play_sound_at_pos("a_sound", ent.origin);  // play sound with name "a_sound" at the object
if (break_out_of_loop) {break;} //clause to stop the sound if necessary
wait(insert_sound_length_here); //ex. wait(3) stops code for 3 seconds
} //loop end



Put code in function. Run function with thread functionname()
I encountered such an error.
Code: [Select]
^1}
^1^
^1ERR(0) scripts/zm/zm_test.gsc (269,1)  : syntax error, unexpected $end, expecting TOKEN_RIGHT_CURLY : }
Would you please show me an example script you actually used on the map?

Offline MegaMech43

  • Rotting Walker
  • Posts: 80
  • Country: ca
  • Respect: 16
    • megamech
    • View Profile
    • megamech.net

Re: How to add a sound that loops when you walk in a room?

« Reply #11 on: April 16, 2017, 10:40:46 am »
I encountered such an error.
Code: [Select]
^1}
^1^
^1ERR(0) scripts/zm/zm_test.gsc (269,1)  : syntax error, unexpected $end, expecting TOKEN_RIGHT_CURLY : }
Would you please show me an example script you actually used on the map?
I think the error is due to you not putting: #using scripts\zm\_zm_utility; at the top of the code where it's supposed to go.

Here's some code:
Code: [Select]

function damagebox() {
trigger = GetEnt("damagebox", "targetname");
trigger SetHintString("");
trigger SetCursorHint("HINT_NOICON");
while(1) {
wait(2);
players = getplayers();
for( i=0;i<players.size;i++ )
{
if(players[i] isTouching(trigger))
{
players[i] DoDamage(15,players[i].origin);
}
}
}
}



Offline Conbini2017

  • Rotting Walker
  • Posts: 79
  • Country: jp
  • Respect: 8
    • dadakhr
    • View Profile
  • WaW: conbini2017

Re: How to add a sound that loops when you walk in a room?

« Reply #12 on: April 16, 2017, 11:32:35 pm »
I think the error is due to you not putting: #using scripts\zm\_zm_utility; at the top of the code where it's supposed to go.

Here's some code:
Code: [Select]

function damagebox() {
trigger = GetEnt("damagebox", "targetname");
trigger SetHintString("");
trigger SetCursorHint("HINT_NOICON");
while(1) {
wait(2);
players = getplayers();
for( i=0;i<players.size;i++ )
{
if(players[i] isTouching(trigger))
{
players[i] DoDamage(15,players[i].origin);
}
}
}
}
I will try it at once. :)
How can I do with radiant?
What is it, trigger?
Is entity info better to write script_sound and script_label?
please tell me. Please.
« Last Edit: April 17, 2017, 12:57:49 am by Conbini2017 »

Offline MegaMech43

  • Rotting Walker
  • Posts: 80
  • Country: ca
  • Respect: 16
    • megamech
    • View Profile
    • megamech.net

Re: How to add a sound that loops when you walk in a room?

« Reply #13 on: April 17, 2017, 01:44:25 pm »
Go watch some tutorials.

Offline Conbini2017

  • Rotting Walker
  • Posts: 79
  • Country: jp
  • Respect: 8
    • dadakhr
    • View Profile
  • WaW: conbini2017

Re: How to add a sound that loops when you walk in a room?

« Reply #14 on: April 17, 2017, 10:57:20 pm »
Go watch some tutorials.
Is there a video link for the tutorial?