Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Npc attacking doors (https://forums.graalonline.com/forums/showthread.php?t=54003)

falco10291029 07-24-2004 09:55 PM

Npc attacking doors
 
NPC Code:

if (created) {
found=0;
hearts=0;

showcharacter;
ap=99;
timeout=.1;

}

if (timeout&&found==0) {
for (this.i=int(random(0,npcscount));found=0;this.i++) {
if (npcs[this.i].hearts>0) found=1;
if (this.i>npcscount) this.i-=npcscount;

}
timeout=.1}
if (timeout&&found==1) {

if (npcs[this.i].hearts<=1) {
found==0;
timeout=.1;
i=0;
}
setcharani walk,;
if (npcs[this.i].x>x&&(abs(npcs[this.i].x-x)>abs(npcs[this.i].y-y))) {
dir=3;
}
if (npcs[this.i].x<x&&(abs(npcs[this.i].x-x)>abs(npcs[this.i].y-y))) {
dir=1;
}
if (npcs[this.i].y>y&&(abs(npcs[this.i].x-x)<abs(npcs[this.i].y-y))) {dir=2;
}
if (npcs[this.i].y<y&&(abs(npcs[this.i].x-x)<abs(npcs[this.i].y-y))) {dir=0;
}
tx =npcs[this.i].x - x;
ty = npcs[this.i].y - y;
dist = (tx*tx+ty*ty)^0.5;
nx = (tx/dist)*1.4;
ny = (ty/dist)*1.4;
move nx,ny,1.4,;
if (npcs[this.i].x in |x-2,x+2|&&npcs[this.i].y in |y-2,y+2|) {
setcharani sword,;
npcs[this.i].hearts-=2;
sleep .25;
if (npcs[this.i].hearts<=0) {
found==0;
timeout=.1;
}
}

timeout=.3
}






Ok, this is supposed to find npcs that are enemies with hearts, and destroy them, then retarget, but it not only wont retarget, sometimes the first target will be a door or something. Why the heck does it do this is it my mistake or a bug in graal programming?

Rick 07-24-2004 10:07 PM

Please format your code first.

VeX_RaT_Boy 07-24-2004 10:13 PM

Wtf? did my post get removed?
I'll rewrite it.

Maybe you should break after finding the npc?


NPC Code:
  if (npcs[this.i].x>x&&(abs(npcs[this.i].x-x)>abs(npcs[this.i].y-y))) {dir=3}
if (npcs[this.i].x<x&&(abs(npcs[this.i].x-x)>abs(npcs[this.i].y-y))) {dir=1}
if (npcs[this.i].y>y&&(abs(npcs[this.i].x-x)<abs(npcs[this.i].y-y))) {dir=2}
if (npcs[this.i].y<y&&(abs(npcs[this.i].x-x)<abs(npcs[this.i].y-y))) {dir=0}


You can use getdir() or the move option.
NPC Code:
  dir=getdir(npcs[this.i].x-x,npcs[this.i].y-y);



the move look unsmooth. use option 2.

Python523 07-24-2004 10:25 PM

1.) Format your code properly
2.) Vex, if you want to help, format your code properly as well.

VeX_RaT_Boy 07-24-2004 10:40 PM

My name is Kjetil, and what in the world was wrong with my formating?
I see nothing wrong in
NPC Code:
dir=getdir(npcs[this.i].x-x,npcs[this.i].y-y);



If you acctuly look, you would see that I posted the same as he, to point out that it was that part I meant...!

Scott 07-24-2004 11:34 PM

Quote:

Originally Posted by Python523
1.) Format your code properly
2.) Vex, if you want to help, format your code properly as well.

Ok Python523.

falco10291029 07-24-2004 11:52 PM

whats "properly formatted" I thought it just had to be spaced a bit I hate these rules....

Xecutor 07-25-2004 12:16 AM

Quote:

Originally Posted by falco10291029
whats "properly formatted" I thought it just had to be spaced a bit I hate these rules....

Line breaks after every command and if check.

falco10291029 07-25-2004 12:16 AM

K ill do that real quick but please help this happpens on many npcs

VeX_RaT_Boy 07-25-2004 01:33 AM

Quote:

Originally Posted by Scott
Ok Python523.

Owned :cool:


[MADtv Stuart mode]
Pyt, LOOK WHAT I CAN DO!:
[/MADtv Stuart mode]
NPC Code:

if (created) {
found=0;
hearts=0;
showcharacter;
ap=99;
timeout=.1;
}

if (timeout) {
if (found==0) {
for (this.i=int(random(0,npcscount));found=0;this.i++) {
if (npcs[this.i].hearts>0) found=1;
if (this.i>npcscount) this.i-=npcscount;
}
timeout=.1;
}elseif (found==1) {
if (npcs[this.i].hearts<=1) {
found==0;
timeout=.1;
i=0;
}
setcharani walk,;
if (npcs[this.i].x>x&&(abs(npcs[this.i].x-x)>abs(npcs[this.i].y-y))) {
dir=3;
}
if (npcs[this.i].x<x&&(abs(npcs[this.i].x-x)>abs(npcs[this.i].y-y))) {
dir=1;
}
if (npcs[this.i].y>y&&(abs(npcs[this.i].x-x)<abs(npcs[this.i].y-y))) {
dir=2;
}
if (npcs[this.i].y<y&&(abs(npcs[this.i].x-x)<abs(npcs[this.i].y-y))) {
dir=0;
}
tx =npcs[this.i].x - x;
ty = npcs[this.i].y - y;
dist = (tx*tx+ty*ty)^0.5;
nx = (tx/dist)*1.4;
ny = (ty/dist)*1.4;
move nx,ny,1.4,;
if (npcs[this.i].x in |x-2,x+2|&&npcs[this.i].y in |y-2,y+2|) {
setcharani sword,;
npcs[this.i].hearts-=2;
sleep .25;
if (npcs[this.i].hearts<=0) {
found==0;
timeout=.1;
}
}
timeout=.3;
}
}


falco10291029 07-25-2004 04:21 AM

thanks ill try that asap

falco10291029 07-25-2004 05:05 AM

meh didnt seem to make a difference

falco10291029 07-25-2004 05:06 AM

is like the players[i].hearts and npcs[i].hearts command bugged? weird

VeX_RaT_Boy 07-25-2004 01:29 PM

I didn't do anything, I just formated it better.
All the players[i].vars and npcs[i].vars are READ-ONLY.

falco10291029 07-26-2004 04:15 AM

i know wthat but that means
NPC Code:
if (npcs[i].hearts>0) do what i say;

should work, but it ignores that flag

Dach 07-26-2004 08:50 AM

Quote:

Originally Posted by falco10291029
NPC Code:


for (this.i=int(random(0,npcscount));found=0;this.i++) {
if (npcs[this.i].hearts>0) found=1;
if (this.i>npcscount) this.i-=npcscount;

}


This makes no sense, try something a little more to the point, such as;
NPC Code:

for (this.i=0;this.i<npcscount;this.i++) {
if (npcs[this.i].hearts>0) {
this.found = 1;
break;
}
}



I'd say more, but you're better off getting your script to work before worrying about refining your scripts. "learn to walk before you run" As we say
consarnit extra spaces in the code brackets, BAH I say! Edit: what's up with all this non-sensical spam? this forum used to be nice

Spark910 07-26-2004 09:16 PM

Edit by Spark: DIABLO2099's post and those relating to it deleted upon request.

sparkers 07-26-2004 10:36 PM

OK ill try that now i didnt no about the break command....

VeX_RaT_Boy 07-26-2004 11:42 PM

Well, you use this.i to check the players, but then if (npcs.[i]hearts>0)

there is no i, only this.i!

Cybnext 07-27-2004 01:40 AM

this.i is always going to max out because there isn't a break command whenever you find it. So if there are 10 npcs in the level, this.i will always be maxed to 10.

GoZelda 07-27-2004 03:35 PM

Perhaps the problem is that your NPC does not has hearts? As far as I heard NPCs do not automatically have hearts...

Dach 07-27-2004 06:38 PM

Quote:

Originally Posted by Cybnext
this.i is always going to max out because there isn't a break command whenever you find it. So if there are 10 npcs in the level, this.i will always be maxed to 10.

The way he set it up before, the condition in his for would break the loop after a suitable npc was found. The problem was that it waited untill the loopcount maxed out if there weren't any npcs with hearts (not to mention it wasn't uneccesarily not straight forward).

Quote:

Originally Posted by GoZelda
Perhaps the problem is that your NPC does not has hearts? As far as I heard NPCs do not automatically have hearts...

I thought that at first too (that there was some bug in reading hearts when it didn't exist). But after testing, it works as expected.

falco10291029 07-28-2004 08:30 PM

any npc it shuld go after have hearts, thats the thing. It shuldnt be going after doors and such, which it does..


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

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