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=85409)

[email protected] 05-02-2009 09:20 PM

Keydown
 
Is there any way to get the keyname
HTML Code:

keyname(int keycode) returns string
^Returns UP, LEFT, DOWN and RIGHT, from when a player is pressing the default keys to move.

from the function 'onKeyDown'
HTML Code:

onKeyDown(keycode, key)
mainly looking at the keycode, not the key.

Or, to just check if a player is pressing one of the detault keys set on Graals F3 options?

Gambet 05-02-2009 10:12 PM

Not sure I completely understand what you're trying to do but I suppose you could do something like this:

PHP Code:

//#CLIENTSIDE
function GraalControl.onKeyDown(kcodekstringscode)
{
 
temp.keyList = {{380}, {371}, {402}, {393}}; //Up, Left, Down, Right
 
 
for (0keyList.size(); i++)
  {
   if (
keyList[i][0] == kcode)
    {
     
player.chat keyname(keyList[i][1]);
    }
  }



Deas_Voice 05-02-2009 10:15 PM

u missed a param. :)
PHP Code:

onKeyDown(keycodekeynamescancode


[email protected] 05-02-2009 10:34 PM

Quote:

Originally Posted by Deas_Voice (Post 1488517)
u missed a param. :)
PHP Code:

onKeyDown(keycodekeynamescancode


You're kidding- haha I love you :)

Thanks :D


Only one problem- it doesn't detect the arrow keys for 'I,J,K,L'- any solutions? lol

Gambet 05-02-2009 11:06 PM

Quote:

Originally Posted by [email protected] (Post 1488519)
Only one problem- it doesn't detect the arrow keys for 'I,J,K,L'- any solutions? lol


Again, assuming I'm understanding what you're trying to do, then the solution I posted above should work if you just add to the array. The array I posted will only read the directional keys since I just made a quick model but you can add the keycodes for 'i, j, k, l' and give them the same numbers as the directionals (0, 1, 2, 3), which should return 'Up, Left, Down, Right' or whatever when you press those keys.

[email protected] 05-02-2009 11:22 PM

Quote:

Originally Posted by Gambet (Post 1488524)
Again, assuming I'm understanding what you're trying to do, then the solution I posted above should work if you just add to the array. The array I posted will only read the directional keys since I just made a quick model but you can add the keycodes for 'i, j, k, l' and give them the same numbers as the directionals (0, 1, 2, 3), which should return 'Up, Left, Down, Right' or whatever when you press those keys.

You're not understanding- those are not the DEFAULT Graal controls.

Gambet 05-02-2009 11:37 PM

Quote:

Originally Posted by [email protected] (Post 1488528)
You're not understanding- those are not the DEFAULT Graal controls.


Yes they are:

PHP Code:

keydown(int keynumber) - returns if the specified key is pressed (0..10upleftdownrightSADMtabQP


Those are the default keynumbers that correspond to the specified keynames, which is why if you did
player.chat = keyname(0); it would return 'Up' and so forth.

[email protected] 05-02-2009 11:50 PM

Quote:

Originally Posted by Gambet (Post 1488531)
Yes they are:

PHP Code:

keydown(int keynumber) - returns if the specified key is pressed (0..10upleftdownrightSADMtabQP


Those are the default keynumbers that correspond to the specified keynames, which is why if you did
player.chat = keyname(0); it would return 'Up' and so forth.

In your method you are specifiying what the keys are. What if I were to edit my DEFAULT arrow keys to something like '1, 2, 3 and 4', your method would still be looking for your basic arrow keys

Gambet 05-03-2009 12:12 AM

Quote:

Originally Posted by [email protected] (Post 1488532)
In your method you are specifiying what the keys are. What if I were to edit my DEFAULT arrow keys to something like '1, 2, 3 and 4', your method would still be looking for your basic arrow keys


Oh, then you could do something like this:

PHP Code:

//#CLIENTSIDE
function GraalControl.onKeyDown(kcodekstringscode)
{
 for (
011i++)
  {
   if (
keydown(i)) 
    {
     
player.chat "The player has pressed the" SPC kstring SPC "key which is the default action for" SPC keyname(i);
    }
  }



EDIT: The default controls have keynumber values that range from 0-10 regardless of what key you assign to perform the action, which is why regardless of what keys you press to move your character, the keynumbers for directionals will always be 0, 1, 2, and 3.

xXziroXx 05-03-2009 01:09 PM

There is no way to read default key assignments. If there is, it's not been documented.

[email protected] 05-03-2009 02:58 PM

Quote:

Originally Posted by xXziroXx (Post 1488666)
There is no way to read default key assignments. If there is, it's not been documented.

Thanks


For some reason the keys 'I,J,K,L' [movement] don't come recognized as movement keys... x-x

Crow 05-03-2009 03:00 PM

Quote:

Originally Posted by [email protected] (Post 1488678)
Thanks


For some reason the keys 'I,J,K,L' [movement] don't come recognized as movement keys... x-x

keydown(int) detects them perfectly fine.

[email protected] 05-05-2009 05:58 PM

Quote:

Originally Posted by Crow (Post 1488680)
keydown(int) detects them perfectly fine.

Oh true. They're not classed as movement keys though.


All times are GMT +2. The time now is 04:20 AM.

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