randomint help

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
User avatar
erick
Major
Posts: 280
Joined: Wed May 30, 2007 1:14 am
Location: USA

randomint help

Post by erick »

How do you use the randomint commands to make sound fit something? :D
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

Post by tltrude »

"randomint" is short for "Random Integer". An Integer is, of course, a number. So it really means "random number".

In the ubersound script, you will see sounds that have the same alias name, but with different numbers. If the sound name is called for, without a number, the game will automattally picks one of the numbered sounds at random. Here is an example.

When a wooden door is opened, the door calls for "door_wood_open_move" and the game randomly picks from these four numbered sounds.

Code: Select all

aliascache door_wood_open_move1 sound/mechanics/DoorWoodOpen_01.wav soundparms 1.2 0.2 0.8 0.2 160 1600 item loaded maps "m1 m2 m3l2 m3l3 m4 m5 m6 dm moh obj train"
aliascache door_wood_open_move2 sound/mechanics/DoorWoodOpen_02.wav soundparms 1.2 0.2 0.8 0.2 160 1600 item loaded maps "m1 m2 m3l2 m3l3 m4 m5 m6 dm moh obj train"
aliascache door_wood_open_move3 sound/mechanics/DoorWoodOpen_03.wav soundparms 1.2 0.2 0.8 0.2 160 1600 item loaded maps "m1 m2 m3l2 m3l3 m4 m5 m6 dm moh obj train"
aliascache door_wood_open_move4 sound/mechanics/DoorWoodOpen_04.wav soundparms 1.2 0.2 0.8 0.2 160 1600 item loaded maps "m1 m2 m3l2 m3l3 m4 m5 m6 dm moh obj train"
This keeps the sound from being repetitive everytime a door is opened.
Tom Trude,

Image
User avatar
erick
Major
Posts: 280
Joined: Wed May 30, 2007 1:14 am
Location: USA

Post by erick »

Wahoo I learned something new! :D
But I was talking about when you associate a sound with an object the sound doesnt fit quite right. Here is what I mean.

Code: Select all

$door time 3
$door rotateXup 90
$door playsound ("DoorWoodMove_01" + (randomint(2) + 1))
$door waitmove
I mean how do you get the randomint correct to the right time (of 3 seconds in this case).
Is the example I gave correct?
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

time

Post by tltrude »

The "time" is how long it takes for the door to move. You can't change how long a sound takes to play. So your only option is to change the time -- you can use fractions like 2.5 .
Tom Trude,

Image
User avatar
erick
Major
Posts: 280
Joined: Wed May 30, 2007 1:14 am
Location: USA

Post by erick »

Why do you put the randomint into the sound then if it doesnt do anything.
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

DoorWoodMove_01

Post by tltrude »

It is an attempt to manually set which of the numbered sounds are randomly picked. It looks like a mistake to me because the alias name should be "door_wood_open_move". The random stuff is not really needed because the game does it automatically -- if you leave the number off the end of the alias name.

$door playsound door_wood_open_move

Here is how I did my first trap door, but it was before I knew the sound was automatically random. Also, notice that the travel time is set for two seconds.

Code: Select all

//------------------------------------------
// trap_door
//------------------------------------------

trap_door_mover:

$trap_door_trigger waittill trigger
$trap_door time 2
$trap_door playsound ("door_wood_open_move" + (randomint(3) + 1)) 
$trap_door rotateXup 90
$trap_door waitmove
$trap_door playsound door_wood_open_stop
wait 20
$trap_door playsound ("door_wood_close_move" + (randomint(1) + 1))
$trap_door rotateXdown 90
$trap_door waitmove
$trap_door playsound ("door_wood_close_stop" + (randomint(2) + 1))

goto trap_door_mover

end
Last edited by tltrude on Thu Jul 26, 2007 11:46 pm, edited 1 time in total.
Tom Trude,

Image
User avatar
erick
Major
Posts: 280
Joined: Wed May 30, 2007 1:14 am
Location: USA

Post by erick »

Okay! Now I understand. The randomint is to randomly select a sound not to make it longer.
Post Reply