Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   music instrument (https://forums.graalonline.com/forums/showthread.php?t=75384)

Cherrykao 07-14-2007 02:35 AM

music instrument
 
I scripted a music instrument and when i play it, i can hear it, but other people in the level can't hear it. so my question is how can I make it so that others can hear the sounds from the music instrument too?

here's a part of my script:
NPC Code:

// flute1 is idle gani and flute2 is the animation gani when player plays the flute

//#CLIENTSIDE
function onWeaponFired() {
this.mode = 1;
this.count = 10;
disabledefmovement();
setani flute1,;
setTimer(0.05);
}

function onTimeout() {
if (this.mode == 1) {
// Quit
if (keydown(6)) {
setani idle,;
enabledefmovement();
this.mode = 0;
}
if (keydown(1)) {
setani flute2,;
if (keydown(4)) {
play("flute9.wav");
}
else if (keydown(5)) {
play("flute5.wav");
} else {
play("flute1.wav");
}

// some more codes here...

setTimer(0.05);
}
}


xXziroXx 07-14-2007 02:38 AM

The play() command only plays the sounds for the current player. In order for other players to hear sounds, they have to be in a gani.

And please, use [ PHP][ /PHP] tags instead of code ones. :)

Cherrykao 07-14-2007 02:48 AM

yes indeed, i was speculating that. what i want to do is simply pass an integer from 1 - 16 to the gani and then the gani will play a specific wave file based on the number it was passed. so to do this i would do:

// In the instrument weapon code
PHP Code:

setani("flute2"1); 

but then, how would the code look inside the gani (when i open the gani up in a text editor to read what variable was passed to it)??

// In the gani:
PHP Code:

SCRIPT 
  
if (params[0] == 1) {
    
play("flute1.wav");
  }
  else (
params[0] == 2) {
    
play("flute2.wav");
  }
SCRIPTEND 

is that how it would look inside the gani file?

xXziroXx 07-14-2007 02:53 AM

I haven't tried this, but this -should- work (gani script):


PHP Code:

function onCreated()
{
  
play(params[0]);


If that doesn't work, try this in the wNPC:

PHP Code:

player.attr[20] = "songtoplay.mid";
setani("flute2"); 

And then this in the gani:

PHP Code:

function onPlayerEnters()
{
  
play(player.attr[20]);



cbk1994 07-14-2007 06:36 PM

No, you can't use onCreated() in a GANI script.

onCreated() will overwrite params, and onCreated() will be given no params. So I would do something like this:

PHP Code:

SCRIPT
if (created)
{
  
playparams[0] );
}
SCRIPTEND 

and then do
setAni( "flute_play", "sound1.wav" );

For more advanced gani scripts, you can do
PHP Code:

if ( created )
{
  
this.args params;
  
startScript();
}
function 
startScript()
{
  
// Now params is in this.args
  
doSomething();



DustyPorViva 07-14-2007 06:46 PM

Simple.

setani("flutegani","flutesound_"this.sound);

and in the gani, put a sound and use PARAM1

HolySheepy 07-14-2007 06:57 PM

setani("flutegani","flutesound_" @ this.sound);

corrected :P

DustyPorViva 07-14-2007 08:48 PM

Hmm, I put @ this.sound :( must of got removed somehow.


All times are GMT +2. The time now is 04:28 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.