Graal Forums

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

aesquivel 05-18-2002 09:28 AM

Possible?
 
I was just wondering if it was possible to have an npc that coulds the time that youa re standng still and everytime you move the time resets

Dustey4Ever 05-18-2002 09:33 AM

umm correct me if im wrong Kai but maybe a timevar and a position checker that checks to see if the position has moved like

NPC Code:

if (!playerx==playeroldx || !playery==playeroldy) {
this.idletime=0;
}



or somethin like that for the set back part??

aesquivel 05-18-2002 10:00 AM

Quote:

Originally posted by Dustey4Ever
umm correct me if im wrong Kai but maybe a timevar and a position checker that checks to see if the position has moved like

NPC Code:

if (!playerx==playeroldx || !playery==playeroldy) {
this.idletime=0;
}



or somethin like that for the set back part??

Thanx but Kai its not who ever you talking about lol but thanx

Dustey4Ever 05-18-2002 10:20 AM

sorry Kai posts here the most and usually fixes people mistakes=p, hmm.. is it just me or have been less people postin here lately:(

aesquivel 05-18-2002 10:50 AM

yeah not as much ppl used to post here alot but not as much anymroe

nyghtGT 05-18-2002 10:55 AM

its probably laggy and not very good but try this sucka:

NPC Code:

NPC Code:

if (created) {
timeout=1;
}
if (timeout) {
this.oldx=this.newx;
this.oldy=this.newy;
this.newx=playerx;
this.newy=playery;
if ((this.newx==this.oldx)&&(this.newy==this.old)) {
message Player Did Not Move!;
}
timeout=1;
}




thats just a little bit, but toy with it ...

Dustey4Ever 05-18-2002 10:56 AM

*starts to tally reasons*

1. They dont script anymore
2. They dont play graal anymore
3. They are so good they dont need help
4. They figure it out themselves:D
5. They just dont care
6. They just dont care about this forum and would rather let it rot:mad:

Dustey4Ever 05-18-2002 11:06 AM

Quote:

Originally posted by nyghtGT
its probably laggy and not very good but try this sucka:

NPC Code:

NPC Code:

if (created) {
timeout=1;
}
if (timeout) {
this.oldx=this.newx;
this.oldy=this.newy;
this.newx=playerx;
this.newy=playery;
if ((this.newx==this.oldx)&&(this.newy==this.old)) {
message Player Did Not Move!;
}
timeout=1;
}




thats just a little bit, but toy with it ...

umm that wouldnt work I dont think because it set the oldx and y before it messages anything or does anything, so it would always stay player did no move if im not mistaken, heres how i would do this
NPC Code:

if (playereneters) {
timeout=1;
}
if (timeout) {
if ((playerx==this.playeroldx)&&(playery==this.player oldy)) {
this.idletime++;
message Idle for #v(this.idletime);
}
if ((!playerx==this.playeroldx)||(!playery==this.play eroldy)) {
this.idletime=0;
message;
}
this.oldx=playerx;
this.oldy=playery;
timeout=1;
}



would this work?

nyghtGT 05-18-2002 11:13 AM

remember...

when you do an arguement such as:
NPC Code:

you use parenthesis around each 2 arguements:

if ((arguement1==arguement2)&&(arguement3==arguement4 )) {
}


Dustey4Ever 05-18-2002 11:22 AM

Quote:

Originally posted by nyghtGT
remember...

when you do an arguement such as:
NPC Code:

you use parenthesis around each 2 arguements:

if ((arguement1==arguement2)&&(arguement3==arguement4 )) {
}


yes, thats the "proper" way, but on my graal it work either way, i really should use tht way more

Saga2001 05-18-2002 11:30 AM

Quote:

Originally posted by Dustey4Ever


yes, thats the "proper" way, but on my graal it work either way, i really should use tht way more

Ummmmm...Actually thats wrong, well nothing is wrong with coding unless its syntax, but you are not suppose, its just personal style, either works, and either are the right way. The having ((this==this)&&(that==that)) is for multiple statement test as follows:
NPC Code:

if (playerenters && (strequals(#a,Saga2001) || strequals(#a,Nick P2P)) {
// do this
}



But it doesn't really matter...

Dustey4Ever 05-18-2002 11:35 AM

I know it doesnt really matter, but it looks cleaner in my opinion

Bhala 05-18-2002 11:50 AM

for your script just do this.
NPC Code:

if(created) timeout=.05;

if(timeout){
if(!keydown(0) && !keydown(1) && !keydown(2) && !keydown(3)){
this.NotMoving++;
}else{
this.NotMoving=0;
}
timeout=.05;
}


nyghtGT 05-18-2002 01:31 PM

Quote:

Originally posted by Bhala
for your script just do this.
NPC Code:

if(created) timeout=.05;

if(timeout){
if(!keydown(0) && !keydown(1) && !keydown(2) && !keydown(3)){
this.NotMoving++;
}else{
this.NotMoving=0;
}
timeout=.05;
}


even better:
NPC Code:

if (created) {
timeout=0.05;
}
if (timeout) {
for(i=0;i<3;i++) {
if (keydown(i)) {
this.move++;
} else {
this.move=0;
}
}
}


aesquivel 05-18-2002 01:40 PM

Quote:

Originally posted by nyghtGT

even better:
NPC Code:

if (created) {
timeout=0.05;
}
if (timeout) {
for(i=0;i<3;i++) {
if (keydown(i)) {
this.move++;
} else {
this.move=0;
}
}
}


i cant get either one of em ta werk on the second one all it does it stay at 3 and i cantfigrue out what im doing wrong!

Falcor 05-18-2002 10:41 PM

Presumably he means clocking the time that you are idle?

Bhala 05-18-2002 10:48 PM

Quote:

Originally posted by nyghtGT

even better:
NPC Code:

if (created) {
timeout=0.05;
}
if (timeout) {
for(i=0;i<3;i++) {
if (keydown(i)) {
this.move++;
} else {
this.move=0;
}
}
}


No your script does not work as you have to check all vars at once or you will get a value other then 0 while your moving.

Bhala 05-18-2002 10:52 PM

Quote:

Originally posted by aesquivel


i cant get either one of em ta werk on the second one all it does it stay at 3 and i cantfigrue out what im doing wrong!

just put what you want to happen while the player is at idle in the commented area.
NPC Code:

if(created) timeout=.05;
if(timeout){
if(!keydown(0) && !keydown(1) && !keydown(2) && !keydown(3)){
this.NotMoving++;
}else{
this.NotMoving=0;
}
if(this.NotMoving>0){
// Do stuff when not moving
}

timeout=.05;
}


Falcor 05-18-2002 10:53 PM

This might work a little better
 
NPC Code:

if(created || playerenters) {
//intalize vars
this.maxidletime = 30; //time (in seconds) that a player can idle for

}
if(timeout) {
if(this.pos[0] != playerx || this.pos[1] != playery)
this.move=0;
else
this.move+=.05;
this.pos = {playerx,playery};
if(this.move > this.maxidletime) {
//whatever you want to do
}
timeout = 0.05;
}



This would check if you acually MOVED from a spot.

Bhala 05-18-2002 10:57 PM

now that works & much better then mine i may add lol

Falcor 05-18-2002 10:58 PM

It would be more efficient to check if the player is acually moving than pressing buttons. I also would like to add that

if(condition1 || alikecondition2 || alikecondition3 || alikecondition4 || alikecondition5 || etc etc)

isnt a good programming habbit.

Bhala 05-18-2002 11:02 PM

Quote:

Originally posted by Falcor
It would be more efficient to check if the player is acually moving than pressing buttons. I also would like to add that

if(condition1 || alikecondition2 || alikecondition3 || alikecondition4 || alikecondition5 || etc etc)

isnt a good programming habbit.

True but in this case a for loop would not work as it would return a var unexpected some times because you need to check all keys at once.

Falcor 05-19-2002 12:04 AM

I don't quite understand...
If you are experiecned enough, nothing could really go wrong @.o


All times are GMT +2. The time now is 03:44 PM.

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