Graal Forums

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

Samposse 12-01-2009 01:54 PM

Flute (instrument)
 
Hi , im on my way to learn my self Scripting :D

and im gona start on my first script ever (an flute) ! :)

but how shoud i start ?

and by the way i got an movment system so Disabledefmovment whoud maybe not work :S

Liberated 12-01-2009 04:21 PM

i guess you'll need onkeypressed()
and then put an animation in there, and a sound.

Samposse 12-01-2009 05:53 PM

yes i know that but can u post an Exsampl? ( like howt oscript the onKeypressed() thing=

Rufus 12-01-2009 05:58 PM

Quote:

Originally Posted by Samposse (Post 1541655)
yes i know that but can u post an Exsampl? ( like howt oscript the onKeypressed() thing=

There's an example here http://forums.graalonline.com/forums...55&postcount=9. You can find a lot of things if you use the search feature, and it will help you.

Samposse 12-01-2009 06:15 PM

oh , Thanks ^^

Samposse 12-01-2009 06:17 PM

PHP Code:

function onKeyPressed(keyname, keycode) 
{ 
  
// keyname(6) checks if the Grab button is pressed, default A on Qwerty. 
  
if (keyname == keyname(6).lower()) { 
    
// stuff 
  
} 
} 

but where do i type in what Key i shoud use to play ?

PHP Code:

function onKeyPressed(keyname, keycode) 
{ 
  
// keyname(6) checks if the Grab button is pressed, default A on Qwerty. 
  
if (keyname == keyname(h).lower()) { 
    
// stuff 
  
} 
} 

??

Liberated 12-01-2009 06:47 PM

i normally use
PHP Code:

function onKeyPressed(code,key)
{
  if( 
key == "f")
  {
  }
} 

but if i do it that way the script keeps looping if i hold the key down, and i think with the .lower that is stopped.

Samposse 12-01-2009 08:23 PM

ok i made one now but the Problem is that when i press a the button it playes but it dosnt stop playing :S , like i play 1 note 1 time and it plays that note until i play an other note ...

here's the script

PHP Code:

//Im not using GS2 here!

//#CLIENTSIDE

function onWeaponFired() {
if (!
flute){
setani idle,;
disabledefmovement();
disableweapons();
disableselectweapons();
disablepause();
disablemap();
set flute;
}}

if (
keypressed&&keydown(6)){
if (
flute){
enabledefmovement();
enableweapons();
enableselectweapons();
enablepause();
setani idle,;
unset 
flute;
}}

if (
keydown2(keycode(z),false)) {
if (
flute){
setani("delitto_flute-play1", "");
}}

if (
keydown2(keycode(x),false)) {
if (
flute){
setani("delitto_flute-play2", "");
}}

if (
keydown2(keycode(c),false)) {
if (
flute){
setani delitto_flute-play3,;
}}

if (
keydown2(keycode(j),false)) {
if (
flute){
setani delitto_flute-play4,;
}}

if (
keydown2(keycode(v),false)) {
if (
flute){
setani delitto_flute-play5,;
}}

if (
keydown2(keycode(b),false)) {
if (
flute){
setani delitto_flute-play6,;
}} 

all works but i wont it to only play an note in like 1 second

Switch 12-01-2009 10:11 PM

You're using a mix of GS1 and GS2.

fowlplay4 12-01-2009 10:36 PM

Instead of having all those keydown2 calls, you can use if else or a switch statement instead.

PHP Code:

function onKeyPressed(code,key) {
  if( 
key == "f") {
    
// setani or do whatever
  
}
  else if (
key == "g") {
    
// setani or do whatever
  
}
  else if (
key == "h") {
    
// setani or do whatever
  
}
} 


cbk1994 12-02-2009 12:21 AM

I've converted it to GS2 and fixed a couple of things; see the comments I left

PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
  if (! 
this.flute) { // the flute is off, so turn it on
    
setAni("idle", NULL);
    
disableDefMovement();
    
disableWeapons();
    
disableSelectWeapons();
    
disablePause();
    
disableMap();
    
    
this.flute = true; // 'set' and 'unset' are deprecated and no longer used
  
}
}

// like Jerret (fowlplay4) said, you can combine them in to one function

function onKeyPressed(code, key) {
  if (
this.flute) { // if the flute is on
    
if (keydown(6)) { // turn off the flute
      
enableDefMovement();
      
enableWeapons();
      
enableSelectWeapons();
      
enablePause();
      
enableMap();
      
      
this.flute = false;
    } else if (
key == "z") {
      
setAni("delitto_flute-play1", NULL);
    } else if (
key == "x") {
      
setAni("delitto_flute-play2", NULL);
    } else if (
key == "c") {
      
setAni("delitto_flute-play3", NULL);
    } else if (
key == "j") {
      
setAni("delitto_flute-play4", NULL);
    } else if (
key == "v") {
      
setAni("delitto_flute-play5", NULL);
    } else if (
key == "b") {
      
setAni("delitto_flute-play6", NULL);
    }
  }
} 

There are better ways to do this, but they're more complicated and would probably just make it even more confusing.

As for the problem of the sound repeating, that's in the GANI. Open up each of the GANI files in the GraalShop.exe program, and on the right side with the GANI attributes, change "SETBACKTO" to the name of the flute idle GANI. This way, when the GANI is over, it goes back to the normal animation and doesn't loop the sound.

Samposse 12-02-2009 05:02 PM

Thank You So mutch ^^^it realy help'd me starting on Forums xD

Samposse 12-03-2009 11:27 AM

ok my Flute is working Perfectly but its only one last problem, i need something to frezee the player while playing ...

disabledefmovment dont work ... :/

Samposse 12-03-2009 11:39 AM

shoud i put something as this insted òf Disabledefmovment ?
PHP Code:

clientr.speed = "0"; 

?

fowlplay4 12-03-2009 04:45 PM

You should quit double/triple posting.

I would add a flag such as.. client.disablemovement = true;

Then edit your movement system so it doesn't process movement if that flag is true, and please attempt to figure it out. I suspect you'll just post the movement script and have the forums do it for you yet again.

Samposse 12-03-2009 06:28 PM

1. i will now stop
Quote:

double/triple posting
2. i found an way so worked to frezee them
PHP Code:

frezeeplayer() 

3. Thanks :D

fowlplay4 12-03-2009 07:00 PM

Gratz, glad to see you're starting to become self-sufficient. :)

Codein 12-03-2009 07:04 PM

Quote:

Originally Posted by Samposse (Post 1542192)
1. i will now stop
2. i found an way so worked to frezee them
PHP Code:

frezeeplayer() 

3. Thanks :D

Remember, freezeplayer(). Spelling function names correctly is important!

Samposse 12-04-2009 10:34 AM

Quote:

Orginal Posted by Codein

Spelling function names correctly is important!
yes i know but im from norway, but thanks anyway :D


All times are GMT +2. The time now is 10:57 PM.

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