Graal Forums

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

Raelyn 07-30-2004 07:09 AM

Keydown?
 
I am trying to get keydown to work and it doesn't seem to be working. Does anyone know what I may be doing wrong? I've got:

if (keydown(Q)){
say2 example;
}

I have tried it several ways, and it just simply doesn't seem to work. Any ideas?

WanDaMan 07-30-2004 07:15 AM

You can't just have keydown as an event. Either use in a timeout or use keypressed (best).

Also, I don't believe that keydown(Q) will work, you'll have to use numeric indexes, I forgot what they are, but I believe Q is 9?

Raelyn 07-30-2004 08:11 AM

Keypressed? I don't believe I've seen this used. Could you elaborate?
As for Q being 9, I see that now that you say that, I missunderstood the description before. Thank you.

Silver Knight 07-30-2004 08:15 AM

Yes, you'll want to use keypressed.
From commands.rtf:
keydown(key) "the specified key is pressed (0..10: up,left,down,right,S,A,D,M,tab,Q,P)"
So, yes, Q would be 9.

If you want to use other letters not specified in the above info, you would use keydown2.
The syntax for keydown2 is similar, keydown2(keycode,ignorecase);
So, with that, and using the keycode() thing, you can do things like:
NPC Code:

if (keypressed) {
if (keydown2(keycode(x),true)) {
triggeraction playerx+1.5+vecx(playerdir)*2,playery+2+vecy(playe rdir)*2,Stuff,;
}
}



In that code, it would check to see if a key was pressed (keypressed), then would check in the x button was pressed (keydown2(keycode(x),true)) and would ignore the case, so X would work as well.
If all that was true, it would do the triggeraction.

Raelyn 07-30-2004 08:19 AM

Ahh, I see, very awesome, thank you. :)

Lance 07-30-2004 09:06 AM

Quote:

Originally Posted by Silver Knight
Yes, you'll want to use keypressed.
From commands.rtf:
keydown(key) "the specified key is pressed (0..10: up,left,down,right,S,A,D,M,tab,Q,P)"
So, yes, Q would be 9.

If you want to use other letters not specified in the above info, you would use keydown2.
The syntax for keydown2 is similar, keydown2(keycode,ignorecase);
So, with that, and using the keycode() thing, you can do things like:
NPC Code:

if (keypressed) {
if (keydown2(keycode(x),true)) {
triggeraction playerx+1.5+vecx(playerdir)*2,playery+2+vecy(playe rdir)*2,Stuff,;
}
}



In that code, it would check to see if a key was pressed (keypressed), then would check in the x button was pressed (keydown2(keycode(x),true)) and would ignore the case, so X would work as well.
If all that was true, it would do the triggeraction.

I will note that keydown2 is good for checking specific keys, and keydown is good for if you want to check the keys set in graal options so regardless of what the person has set for the q-menu (maybe a joystick button), the script will work the way you want.

Raelyn 07-30-2004 09:21 AM

Ok, I've gotten it working, but I have a question while not keydown related so much as it's related to the same script.

I'm trying to remove all default graal functions, such as, the default GUI, player, animations, sounds etc and I have managed to get rid of everything thus far except sound using the following.

NPC Code:

if (created){
disableselectweapons;
showstats 1;
showstats 2;
showstats 4;
showstats 8;
showstats 16;
showstats 32;
showstats 64;
showstats 128;
showstats 256;
showstats 512;
}



Is this the most effecient way to do this, I'm just worried that however they are not showing, that they are still being calculated unnessesarily? Also, I am trying to get rid of the sounds of walking/swords etc. any suggestion on how to achieve this? I tried:

NPC Code:

if (keypressed) {
if (keydown(0)) {
stopsound steps.wav;
}
}



However it doesn't do the trick...

Thank you again. ^^

Lance 07-30-2004 10:11 AM

Quote:

Originally Posted by Raelyn
Ok, I've gotten it working, but I have a question while not keydown related so much as it's related to the same script.

I'm trying to remove all default graal functions, such as, the default GUI, player, animations, sounds etc and I have managed to get rid of everything thus far except sound using the following.

NPC Code:

if (created){
disableselectweapons;
showstats 1;
showstats 2;
showstats 4;
showstats 8;
showstats 16;
showstats 32;
showstats 64;
showstats 128;
showstats 256;
showstats 512;
}


You can combine the showstats:

NPC Code:
showstats 1+2+4+8+16+32+64+128+256+512;



Quote:

Is this the most effecient way to do this, I'm just worried that however they are not showing, that they are still being calculated unnessesarily?
I'd hope not.

Quote:

Also, I am trying to get rid of the sounds of walking/swords etc. any suggestion on how to achieve this? I tried:

NPC Code:

if (keypressed) {
if (keydown(0)) {
stopsound steps.wav;
}
}



However it doesn't do the trick...
This is where you make your own ganis and use replaceani defaultaniname,newaniname;

Crono 07-30-2004 10:24 AM

Just wanted to say, thanks for not being a complete jerk to him like some people would to others :)

Raelyn 07-30-2004 10:35 AM

Ahh, so the sound is in relation to the gani and I simply need to replace the gani? I was hoping to have it not process a gani whatsoever, but I suppose replacing with a single frame gani that does nothing would fix the problem? I am sort of putting together a menu, so a gani for it is pointless, but would a comepletely blank, single frame gani be the best solution?

Silver Knight 07-30-2004 10:39 AM

I assume you mean to use the arrow keys in the menu to move, and you don't want the walk gani to commence, am I correct?
If that is the case, you should look into the commands disabledefmovement & enabledefmovement, or so.
These commands will disable movement and enable it, respectively.
It would be useful if you wanted to be able to use the arrow keys in the menu to select things, yet the player would not move and the gani would not play, and thus no walking sound.

Raelyn 07-30-2004 10:43 AM

Actually, I don't want anything on the screen at all, what I am making uses a single level of all black tiles, no GUI, so character on screen, or anything. It's all just going to consist of a single large menu. There isn't really going to be any movement to disable or re-enable.

Edit:

Quote:

Originally Posted by Lance
You can combine the showstats:

NPC Code:
showstats 1+2+4+8+16+32+64+128+256+512;


Tried this and it was a no go.

Polo 07-30-2004 11:42 AM

Then dont you want...
NPC Code:

showstats 0;


The showstas command is using whats called a bit field to set lots of options at the same time. Simply sum up the numbers of the gui bits you do want to be seen, and then use showstats with that number.

Raelyn 07-30-2004 11:49 AM

Quote:

Originally Posted by Polo
Then dont you want...
NPC Code:

showstats 0;


The showstas command is using whats called a bit field to set lots of options at the same time. Simply sum up the numbers of the gui bits you do want to be seen, and then use showstats with that number.

Nice. :eek: That's great, cleaned up very well. :)

GoZelda 07-30-2004 12:48 PM

Mh, you could've used keypressed too.

NPC Code:

if (keypressed){
if (strequals(#p(1), q)){
//menu code here
}
}


and for the showstats, if you have so many you might want to consider using.

NPC Code:

showstats allstats-whatever you don't want // Not sure if 'allstats' is correct, but it was something similiar.


Raelyn 07-30-2004 08:13 PM

Quote:

Originally Posted by GoZelda
Mh, you could've used keypressed too.

NPC Code:

if (keypressed){
if (strequals(#p(1), q)){
//menu code here
}
}


and for the showstats, if you have so many you might want to consider using.

NPC Code:

showstats allstats-whatever you don't want // Not sure if 'allstats' is correct, but it was something similiar.


The thing is, I am making a menu, and there won't be anything behind it, so no need to use keypressed. I am just having the menu be the whole screen.

Also, I thought that showstats 0; worked quite well. ^^

osrs 07-30-2004 08:14 PM

the variable 'allstats' is the addition of all stats flags, so only 'showstats allstats;' will enable all default status bar stuff again. GoZelda's example was right too, i believe, so 'showstats allstats-1024;' will show everything besides the player.

Raelyn 07-30-2004 08:56 PM

Ugh, one annoyance after another, I replaced the ani, but it still plays the original for a split second when I press arrow keys before it switches to the other animation, just enough time to play that retarded steps.wav once everytime you press an arrow key. :| Is there not a way to make it replace the gani before it gets the chance to start the default gani at all? :\

NPC Code:

if (created){
replaceani idle,frolic_menu;
replaceani walk,frolic_menu;
}



I appreciate the help. Thank you. ^^

Lance 07-30-2004 08:59 PM

The replaceanis should be done in the created block of a default weapon. You may also want to use the:

weaponorder=

serveroption, which is a comma separated list of weapons the player should load first.

As for the showstats, it's a relatively safe bet that the way you had it first was only showing the last one (512), overriding the others. However, 0 seems more fitting to what you want, unless there is something you still want to preserve.

Raelyn 07-30-2004 09:22 PM

Quote:

Originally Posted by Lance
The replaceanis should be done in the created block of a default weapon. You may also want to use the:

weaponorder=

serveroption, which is a comma separated list of weapons the player should load first.

As for the showstats, it's a relatively safe bet that the way you had it first was only showing the last one (512), overriding the others. However, 0 seems more fitting to what you want, unless there is something you still want to preserve.

Unfortunately, I am doing this all offline, I don't have a server, therefor server options wouldn't help me much, eh? >_<

The way I had it was doing the exact same as showstats 0; only with alot more commands going through obviously, so to do it with one is much better, thank you again. ^^

Polo 07-31-2004 04:26 AM

Quote:

Originally Posted by Raelyn
Also, I thought that showstats 0; worked quite well. ^^

Well you did say you were trying to hide everything, and thats the way you do it :P

Raelyn 07-31-2004 05:06 AM

Quote:

Originally Posted by Polo
Well you did say you were trying to hide everything, and thats the way you do it :P

Yes, but Tseng doesn't seem to have realised that problem has already been solved. :|

omegaslayer 08-08-2004 01:14 AM

This might work?

if (keypressed&&keydown2(keycode(Q),)) {
say2 example;
}

Dach 08-08-2004 02:16 AM

Quote:

Originally Posted by Raelyn
The way I had it was doing the exact same as showstats 0; only with alot more commands going through obviously, so to do it with one is much better, thank you again. ^^

LIES!!

You just didn't notice the inventory, which was the only thing showing since you had showstats 512;.
Quote:

Yes, but Tseng doesn't seem to have realised that problem has already been solved. :|
he was clearing things up for you, since you're posts showed that you didn't quite understand the command entirely


yes, I know this is late, but I didn't read those parts, so blah


All times are GMT +2. The time now is 06:45 AM.

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