changing sound parameters

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

changing sound parameters

Post by wacko »

how can i change the sound parameters defined in the aliascache line by scripting, e.g. to change the volume or the pitch?
Bjarne BZR
Site Admin
Posts: 3298
Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:

Post by Bjarne BZR »

Yes there should be:
g_allclasses.html wrote:playsound( String soundName, [ Integer channel ], [ Float volume ], [ Float min_distance ], [ Float pitch ] )

play a sound coming from this entity.
default channel, CHAN_BODY.
Admin .MAP Forums
Image
Head above heels.
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

I will try this, thanks Bjarne! :D
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

i can't get a playsound working: in my script i use loopsound (where I just can adjust the volume) because it's a continous sound which shall become louder and higher.
but if i used playsound, how could a piece of script look like where the pitch is set by a variable?

Code: Select all

test:
local.pitch=local.pitch+.1
$testspeaker playsound soundname,,,,local.pitch
goto test
end
probably not.

anyway, can I use the aliascache command also later in the script or does it have to stay in main? something like this would be nice:

Code: Select all

main:
setcvar "g_obj_alliedtext1" ""
setcvar "g_obj_alliedtext2" ""
setcvar "g_obj_alliedtext3" ""
setcvar "g_obj_axistext1" ""
setcvar "g_obj_axistext2" ""
setcvar "g_obj_axistext3" ""
setcvar "g_scoreboardpic" "none" 
local.master = spawn ScriptMaster
local.master aliascache soundname sound/mechanics/M1_LightTurn.wav soundparms 1 0.1 2.0 0.0 750 1000 auto loaded maps "m obj dm r"
///////////////////////
level waitTill prespawn
///////////////////////
	
exec global/DMprecache.scr
exec global/ambient.scr mohdm4
thread lift_prep
thread ring_prep

/////////////////////
level waittill spawn
////////////////////
end

test:
local.pitch=local.pitch+0.02
local.loud++
local.master aliascache soundname sound/mechanics/M1_LightTurn.wav soundparms local.loud 0.1 local.pitch 0.0 750 1000 auto loaded maps "m obj dm r"
loopsound soundname
goto test
end
I think it would work. Could someone tell me how and where I must use this 'float' thingie for local.pitch?! Because with above I get an error...
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

The playsound syntaxis as stated in g_allclasses.html is wrong. I think the volume and pitch of sounds are completely determined by their alias.

You can move the scriptmaster code to anywhere you want it in your script, just as long as the code will be executed before level waittill prespawn.

You can have multiple aliases per sound with different volume / pitch values if you want. Only 1 alias per file needs to be above level waitill prespawn, then later you can define new aliases for this file 'on the fly'.

For my flyable chopper for the mw mod, I let the script define 111 aliases for the rotor sound, all with different pitch values.

This is what it looks like:

Code: Select all

for(local.pitch = 0; local.pitch <= 110; local.pitch ++)
		local.master alias ("snd_chopper_" + local.pitch + "p") sound/modernwarfare/chopper.wav soundparms (0.1 + local.pitch / 10) 0.0 (local.pitch / 100.0) 0.0 1024 (local.pitch * 489.76 + 2048) auto loaded maps "obj dm"

Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

Stargate

Post by tltrude »

I love Stargate! I bet there is a site on the net that has that "yung, yung, yung, yung" wave sound for the rings already. Hmmm, is it is four yungs or five?
Tom Trude,

Image
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

lol: if someone had told me some months ago, that I would post such stuff, I would have called him a #CENSORED#

but, there must be something missing:
with a main thread of

Code: Select all

main:
//...
local.master = spawn ScriptMaster
local.master aliascache ring_snd1 sound/mechanics/M1_LightTurn.wav soundparms 1 0.1 2.0 0.0 750 1000 auto loaded maps "m obj dm r"
//...
///////////////////////
level waitTill prespawn
///////////////////////
and a looped piece of

Code: Select all

	{
	local.pitch ++ 
	local.master alias ring_snd1 sound/mechanics/M1_LightTurn.wav soundparms(0.1 + local.pitch / 10) 0.0 (local.pitch / 100.0) 0.0 1024 (local.pitch * 489.76 + 2048) auto loaded maps "m obj dm r"
	$ring1 loopsound ring_snd1
	}
, I get in the console these errors (and a MOHAA crash after some seconds):

Code: Select all

	local.master alias ring_snd1 sound/mechanics/M1_LightTurn.wav soundparms(0.1 + local.pitch / 10) 0.0 (local.pitch / 100.0) 0.0 1024 (local.pitch * 489.76 + 2048) auto loaded maps "m obj dm r" (maps/dm/lager.scr, 180)
	local.master ^

^~^~^ Script Error: command 'alias' applied to NIL

	local.master alias ring_snd1 sound/mechanics/M1_LightTurn.wav soundparms(0.1 + local.pitch / 10) 0.0 (local.pitch / 100.0) 0.0 1024 (local.pitch * 489.76 + 2048) auto loaded maps "m obj dm r" (maps/dm/lager.scr, 180)
	local.master alias ring_snd1 sound/mechanics/M1_LightTurn.wav soundparms(0.1 + local.pitch ^

^~^~^ Script Error: binary '/' applied to incompatible types 'NIL' and 'int'

	local.master alias ring_snd1 sound/mechanics/M1_LightTurn.wav soundparms(0.1 + local.pitch / 10) 0.0 (local.pitch / 100.0) 0.0 1024 (local.pitch * 489.76 + 2048) auto loaded maps "m obj dm r" (maps/dm/lager.scr, 180)
	local.master alias ring_snd1 sound/mechanics/M1_LightTurn.wav soundparms(0.1 ^

^~^~^ Script Error: binary '+' applied to incompatible types 'float' and 'NIL'

	local.master alias ring_snd1 sound/mechanics/M1_LightTurn.wav soundparms(0.1 + local.pitch / 10) 0.0 (local.pitch / 100.0) 0.0 1024 (local.pitch * 489.76 + 2048) auto loaded maps "m obj dm r" (maps/dm/lager.scr, 180)
	local.master alias ring_snd1 sound/mechanics/M1_LightTurn.wav soundparms(0.1 + local.pitch / 10) 0.0 (local.pitch ^

^~^~^ Script Error: binary '/' applied to incompatible types 'NIL' and 'float'

	local.master alias ring_snd1 sound/mechanics/M1_LightTurn.wav soundparms(0.1 + local.pitch / 10) 0.0 (local.pitch / 100.0) 0.0 1024 (local.pitch * 489.76 + 2048) auto loaded maps "m obj dm r" (maps/dm/lager.scr, 180)
	local.master alias ring_snd1 sound/mechanics/M1_LightTurn.wav soundparms(0.1 + local.pitch / 10) 0.0 (local.pitch / 100.0) 0.0 1024 (local.pitch ^

^~^~^ Script Error: binary '*' applied to incompatible types 'NIL' and 'float'

	local.master alias ring_snd1 sound/mechanics/M1_LightTurn.wav soundparms(0.1 + local.pitch / 10) 0.0 (local.pitch / 100.0) 0.0 1024 (local.pitch * 489.76 + 2048) auto loaded maps "m obj dm r" (maps/dm/lager.scr, 180)
	local.master alias ring_snd1 sound/mechanics/M1_LightTurn.wav soundparms(0.1 + local.pitch / 10) 0.0 (local.pitch / 100.0) 0.0 1024 (local.pitch * 489.76 ^

^~^~^ Script Error: binary '+' applied to incompatible types 'NIL' and 'int'
on the other hand, my script now is a complete chaos, because in the beginning i didn't know what I wanted to do :oops: so the reason might be somewhere else!? if someone wanted to do a cleanup, he'd be more than welcome... volunteers, hands up! :wink:
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Re: Stargate

Post by wacko »

tltrude wrote:I love Stargate! I bet there is a site on the net that has that "yung, yung, yung, yung" wave sound for the rings already. Hmmm, is it is four yungs or five?
:shock: why do u say 'stargate'? how did u know? Tom Holmes, eh? In fact it's rather like in that movie 'Contact' with Jodie Foster, but anyway...
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

For

Post by tltrude »

I think you need the "for" line that jv-map used.
Tom Trude,

Image
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Re: For

Post by wacko »

tltrude wrote:I think you need the "for" line that jv-map used.
Doesn't this for-line just produce 111 different aliases? i won't need an alias anymore once it has changed...
Or is such an alias 'writeprotected' while in use?
What does e.g. "Script Error: binary '/' applied to incompatible types 'NIL' and 'int' " want to tell me??
Where in his script did jv put his code and what is in his main thread?
Is there a complete scr file with such a thing somewhere to take a look?
As I am a noob in scripting, i'd need a helping hand which is holding me a little more firmly :(
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

local.pitch

Post by tltrude »

I think it means that it does not know what number to use for "local.pitch" because you have not given it a value. Jv-maps "for" line gives his a value of 110 to start with, I think. But, try "local.pitch = 1.0" in prespawn.
Tom Trude,

Image
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

okay :D
thanks for the help!! 8-)
it's working now , more or less. I had to set the for-loop with all aliascaching before level waitTillPrespawn.
Nevertheless, before actually starting the sound with a low pitch steadily growing, it does kind of (sound) scales. Does anybody know why?
Here's the script (don't laugh). I tried to accentuate the sound parts a bit, hope that helps.

Code: Select all

main:

setcvar "g_obj_alliedtext1" ""
setcvar "g_obj_alliedtext2" ""
setcvar "g_obj_alliedtext3" ""
setcvar "g_obj_axistext1" ""
setcvar "g_obj_axistext2" ""
setcvar "g_obj_axistext3" ""

setcvar "g_scoreboardpic" "none" 
//////////////////////////////////////////////SOUND STUFF  VVV
local.master = spawn ScriptMaster
for (local.i=0;local.i<=120;local.i++)
{
local.master aliascache ("ring_snd_"+local.i) sound/mechanics/M1_LightTurn.wav soundparms(1 + local.i / 5) 0.0 (0.1 + local.i / 1000.0) 0.0 750 2048 auto loaded maps "obj dm"
}
//local.master aliascache ring_snd1 sound/mechanics/M1_LightTurn.wav soundparms 1 0.1 2.0 0.0 750 1000 auto loaded maps "m obj dm r"
local.master aliascache ring_exp sound/weapons/explo/Exp_Interior_01.wav soundparms 3 0.2 0.8 0.4 3000 8000 weapon loaded maps "m obj dm r"
//////////////////////////////////////////////SOUND STUFF ^^^

///////////////////////
level waitTill prespawn
///////////////////////
	
exec global/DMprecache.scr
//exec global/ambient.scr mohdm4
thread ring_prep

/////////////////////
level waittill spawn
////////////////////
end


ring_prep:
	local.besch1=1
	local.speed1=0
	local.besch2=1
	local.speed2=0
	local.besch3=1
	local.speed3=0
	local.ring_exp=0
//////////////////////////////////////////////SOUND STUFF vvv
	local.pitch=0
//////////////////////////////////////////////SOUND STUFF ^^^
	wait .25 
	$ringcorona hide
	wait .5 
	$ringlicht light 1 1 0.5 0
	$ring2 bind $ring1
	$ring3 bind $ring2
	$1coron1 bind $ring1
	$2coron1 bind $ring2
	$3coron1 bind $ring3
	$1coron1 hide
	$2coron1 hide
	$3coron1 hide
	$ringtrigger waittill trigger
	goto ring_move
end

ring_move:
wait 1

if (local.speed3>500)
	{
	wait .25 
	$ringcorona scale 15
	$ringcorona show
	$ringlicht light 1 1 0.5 500
	$ring1 playsound ring_exp
	wait 1
	goto ring_weg
	}
else
	{
		if (local.speed3>300)
			{
			$ringcorona scale (randomfloat 5)
			$ringcorona show
			wait (randomfloat 0.2)
			$ringcorona hide		
			}
	}

local.besch1=local.besch1+.1
local.speed1=local.speed1 + local.besch1
$1coron1 show
//////////////////////////////////////////////SOUND STUFF vvv
local.pitch ++ 
$ring1 loopsound ("ring_snd_"+local.pitch)
//////////////////////////////////////////////SOUND STUFF ^^^

if (local.speed1>100)
	{
	local.besch2=local.besch2+.2
	local.speed2=local.speed2 + local.besch2
	$2coron1 show
	}
	
if (local.speed2>100)
	{
	local.besch3=local.besch3+.4
	local.speed3=local.speed3 + local.besch3
	$3coron1 show
	}

$ring1 rotateY local.speed1
$ring2 rotateZ local.speed2
$ring3 rotateX local.speed3
goto ring_move
end

ring_weg:
	$ring1 stoploopsound
	$ring1 remove
	$ring2 remove
	$ring3 remove
	$1coron1 remove
	$2coron1 remove
	$3coron1 remove
	$ringcorona moveDown 128
	$ringcorona waitmove
end
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

oki, got it rather the way i wanted it to be.
while scripting, though, I became aware that i can't use it in my map :roll: , so I put it in the recycling bin
Post Reply