Graal Forums

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

wonderboysp2p 01-06-2004 06:35 AM

-keyNOTdown(i)
 
sorry for being retarded.. i havent been doing any scripting for awhile but oh well!
how would i go about detecting when keys 0-4 were'nt being pushed?


im bored and rescripting movement system and i couldnt think of what to do so he just keeps doing the walk ani unstil i press 'a' XP

screen_name 01-06-2004 06:39 AM

Well, there are a few ways to do it.

Probably the easiest way is to have a array for it, then run a loop and check the corrisponding key to see if it's pressed, if not, then set the variable to false or whoever you want to keep track of it.

Thought 01-06-2004 06:44 AM

NPC Code:
!keydown(#)

?

Python523 01-06-2004 06:44 AM

Quote:

Originally posted by screen_name
Probably the easiest way is to have a array for it, then run a loop and check the corrisponding key to see if it's pressed, if not, then set the variable to false or whoever you want to keep track of it.
Why bother checking? var = keydown(index); works just fine

Lance 01-06-2004 06:45 AM

Rick's got the idea. :)

wonderboysp2p 01-06-2004 06:57 AM

else if (!keydown(0)) set ani idle,;


i had this but it screws up the walk ani X_X

screen_name 01-06-2004 07:03 AM

Quote:

Originally posted by Python523


Why bother checking? var = keydown(index); works just fine

Well hell, I didn't even think of that.

jake13jake 01-06-2004 07:39 AM

Quote:

Originally posted by wonderboysp2p
else if (!keydown(0)) set ani idle,;


i had this but it screws up the walk ani X_X

well.. that's because your condition is all messed up, and not having brackets doesn't help much either. I would write that same line of code as the following:

If you wanted it to be detected when keydown(0) then:
if (!keydown(0)) {
whatever;
}
else {
setani idle,;
}


If you wanted it to not be detected when keydown(0) then:
if (!keydown(0)) {
setani idle,;
}

And you'd want to make sure with the !keydown that you'd have a timeout or something... I'm not sure if it's the same with keydown considering the fact that I don't use keydown much.

GoZelda 01-06-2004 12:47 PM

Quote:

Originally posted by Lance
Rick's got the idea. :)
lol yeah, i thought

"Arrays wtf only Rick makes sense"

D1ce2 01-06-2004 03:13 PM

Isnt there a quick key in here?
I forgot how it goes but it's like
NPC Code:

if(playerenters)
timeout=0.05;

if(timeout){
if(keypressed){
if(keydown(t),true){
bla;
}
}
timeout=0.05;
}


I forgot maybe it is wrong, o-well I tried.
:p
If you don't want it detecting add a key (!)
like
NPC Code:

if(!bla && !bla2 && !bla3 && !bla4)){
//bla
}


Or as kai would do:
NPC Code:

if(!bla){
if(!bla2){
if(!bla3){
if(!bla4){
//bla stuff
}
}
}
}



As it's easier to read;P

Loriel 01-06-2004 04:24 PM

I thiiiink the original poster's enquire was about a function that would tell him whether any of the keys 0-3 was pressed, so he could unset his walking gani accordingly... so I suppose the most sensible thing to do is
NPC Code:
walking = false;
for (d = 0; d < 4; d ++) {
if (keydown(d)) {
do_walking_stuff();
walking = true;
}
}
tokenize idle walk;
setani #t(walking),;


D1ce2 01-06-2004 04:49 PM

Quote:

Originally posted by Loriel
I thiiiink the original poster's enquire was about a function that would tell him whether any of the keys 0-3 was pressed, so he could unset his walking gani accordingly... so I suppose the most sensible thing to do is
NPC Code:
walking = false;
for (d = 0; d < 4; d ++) {
if (keydown(d)) {
do_walking_stuff();
walking = true;
}
}
tokenize idle walk;
setani #t(walking),;


Either way is fine, though I prefer yours.

Dach 01-06-2004 07:40 PM

Quote:

Originally posted by D1ce2
Isnt there a quick key in here?
I forgot how it goes but it's like
NPC Code:

if(playerenters)
timeout=0.05;

if(timeout){
if(keypressed){
if(keydown(t),true){
bla;
}
}
timeout=0.05;
}


I forgot maybe it is wrong, o-well I tried.
:p

its
keydown2(keycode(t),false)
Quote:


If you don't want it detecting add a key (!)
like
NPC Code:

if(!bla && !bla2 && !bla3 && !bla4)){
//bla
}


Or as kai would do:
NPC Code:

if(!bla){
if(!bla2){
if(!bla3){
if(!bla4){
//bla stuff
}
}
}
}



As it's easier to read;P

Kai would choose the first, since the checks are related ;)


oman, Loriel's script is crazygonuts, I never thought to use tokenize like that :megaeek:

Goboom 01-06-2004 10:03 PM

Quote:

Originally posted by Dach

its
keydown2(keycode(t),false)


Kai would choose the first, since the checks are related ;)


oman, Loriel's script is crazygonuts, I never thought to use tokenize like that :megaeek:

Crazygonuts hehe, I don't think many people would even think to do what Loriel did, the thought has never crossed my mind for such a way.

Riot 01-07-2004 01:50 AM

If you bothered to look at the Snippets section of Graal.net (mainly the Elaborate onwall function Loriel posted) you'd already know to do it that way ;)

Thought 01-07-2004 02:07 AM

Quote:

Originally posted by Goboom
Crazygonuts hehe, I don't think many people would even think to do what Loriel did, the thought has never crossed my mind for such a way.
I would have, if presented the challenge of scripting a walking system.

Dach 01-07-2004 03:49 AM

I've made 2 or 3 walking systems and hadn't even considered using tokenize, I usually get by with regular arrays. Come to think of it, I don't really remember how I handled setting the animation... ohwell, back to the point, Loriel has got some wack skills in scripting

Goboom 01-07-2004 04:13 AM

Quote:

Originally posted by Thought

I would have, if presented the challenge of scripting a walking system.

I said many people you happen to be one of the few. :P

adam 01-07-2004 04:21 AM

Re-Scripting the player is a great exercise.

Difficult. But I don't think anybody expects it to be perfect.

Kaimetsu 01-07-2004 04:50 AM

I wish people wouldn't make such wild guesses about how I'd do something.

D1ce2 01-07-2004 10:56 AM

Quote:

Originally posted by Kaimetsu
I wish people wouldn't make such wild guesses about how I'd do something.
Your back.

Kaimetsu 01-07-2004 12:07 PM

Quote:

Originally posted by D1ce2
Your back.
Check the sig, man. I'm only here because I'm in a debate about the new supermods, over in the main forum. I only commented here because I was mentioned.

D1ce2 01-07-2004 12:26 PM

Quote:

Originally posted by Kaimetsu


Check the sig, man. I'm only here because I'm in a debate about the new supermods, over in the main forum. I only commented here because I was mentioned.

*Cough* by me
Anyways, you should come back your highly missed. Eitherway i've got nothing else to say:\

GoZelda 01-07-2004 02:30 PM

Quote:

Originally posted by Kaimetsu
I wish people wouldn't make such wild guesses about how I'd do something.
I think they think you think it should be done like that because of the KI-SGI or stuff.

D1ce2 01-07-2004 03:32 PM

Quote:

Originally posted by GoZelda

I think they think you think it should be done like that because of the KI-SGI or stuff.

For once your correct.

osrs 01-07-2004 03:58 PM

Quote:

Originally posted by GoZelda

I think they think you think
it should be done like that because of the KI-SGI or stuff.
Ow, so many thinks. :D

Kaimetsu 01-07-2004 04:50 PM

Quote:

Originally posted by GoZelda
I think they think you think it should be done like that because of the KI-SGI or stuff.
KSI-GS

I'm sure you're right, but they've misinterpreted the document. I wouldn't script it in any of the ways presented thus far.

GoZelda 01-07-2004 04:56 PM

Quote:

Originally posted by Kaimetsu
KSI-GS
Atleast i had the right letter -_-

Kaimetsu 01-07-2004 05:00 PM

I wasn't dissin' you, I just wanted to make sure people knew what we were talking about.

It's interesting to see that KSI-GS found its way into the Classic tab requirements. I would never have agreed with that decision, and I doubt that the GST are enforcing it (heck, one of the members breaks almost every rule in there).

GoZelda 01-07-2004 05:11 PM

Quote:

Originally posted by Kaimetsu
I wasn't dissin' you, I just wanted to make sure people knew what we were talking about.
Nor did i thought that :o

ZeLpH_MyStiK 01-08-2004 01:43 AM

hehe another scripting thread gone awry ;)

ZeLpH_MyStiK 01-08-2004 03:05 AM

NPC Code:

if (created) timeout=.05;
if (timeout) {
if (keydown(#)) {
// move stuff
}elseif (keydown(#)) {
// move stuff
}elseif (keydown(#)) {
// move stuff
}elseif (keydown(#)) {
// move stuff
}else{
// idle stuff
}
timeout=.05;
}


Use elseifs, they're useful ;)

Thought 01-08-2004 03:28 AM

Quote:

Originally posted by ZeLpH_MyStiK
NPC Code:

if (created) timeout=.05;
if (timeout) {
if (keydown(#)) {
// move stuff
}elseif (keydown(#)) {
// move stuff
}elseif (keydown(#)) {
// move stuff
}elseif (keydown(#)) {
// move stuff
}else{
// idle stuff
}
timeout=.05;
}


Use elseifs, they're useful ;)

WRONG.

Think about it, what do you do to run diagonally? You press two arrow keys.

Loriel 01-08-2004 02:34 PM

Eh, Rick? Your keyboard lacks diagonal arrow keys?

Python523 01-08-2004 03:08 PM

Quote:

Originally posted by Loriel
Eh, Rick? Your keyboard lacks diagonal arrow keys?
Your keyboard has diagnol arrow keys?

Thought 01-08-2004 08:31 PM

He's probably referring to the number pad, eg keys 7, 9, 1 & 3.

GoZelda 01-08-2004 08:42 PM

Laptop...

Oh sure elseifs are useful but not in this case. Unless you use if (keydown(x)&&keydown(y)){}

Kaimetsu 01-09-2004 04:45 AM

Quote:

Originally posted by GoZelda
Laptop...

Oh sure elseifs are useful but not in this case. Unless you use if (keydown(x)&&keydown(y)){}

Or assume mutual exclusivity on the opposing arrow keys.

Kristi 01-14-2004 11:00 AM

I might be a little late in asking this, but how exactly Loriel's tokenize convention more efficient?

it would seem to me that requesting a string to be searched through and broken down and then assigned to 2 seperate parts of an array wouldnt be as efficient at all.

if (walking == 0)
setani idle;
else
setani walk;

what is less efficient about the old way? It does one check.
even if you wanted to be crafty why not..

setstring blah,idle,walk;
setani #I(blah,walking);

although in terms of efficiency it seems equivilent to me. ::shrugs::
The tokenize idea is crazy and unique, but please explain why it is better.

Loriel 01-14-2004 07:01 PM

Certainly is not more efficient, but I deem it more readable or compact, especially with constructions like this ;)
NPC Code:
  if (static == false && playerfreezetime <= 0) {
setstring this.temp,"idle sit walk carry swim","carrystill carrysit carry carryrun","grab push pull","attack","hurt dead";
tokenize #I(this.temp,this.mode);
setani #t(this.submode),;
setstring this.temp,;
}



All times are GMT +2. The time now is 08:41 AM.

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