Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-24-2004, 09:55 PM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
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?
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!

Last edited by falco10291029; 07-25-2004 at 12:18 AM..
Reply With Quote
  #2  
Old 07-24-2004, 10:07 PM
Rick Rick is offline
PipBoy Extraordinaire!
Rick's Avatar
Join Date: Jul 2004
Location: Long Beach, California.
Posts: 831
Rick is on a distinguished road
Please format your code first.
Reply With Quote
  #3  
Old 07-24-2004, 10:13 PM
VeX_RaT_Boy VeX_RaT_Boy is offline
WannaBe Scripter
VeX_RaT_Boy's Avatar
Join Date: Aug 2002
Location: Norway
Posts: 960
VeX_RaT_Boy is on a distinguished road
Send a message via ICQ to VeX_RaT_Boy Send a message via AIM to VeX_RaT_Boy Send a message via Yahoo to VeX_RaT_Boy
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.
__________________
-Kjetil Valen
Reply With Quote
  #4  
Old 07-24-2004, 10:25 PM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
1.) Format your code properly
2.) Vex, if you want to help, format your code properly as well.
Reply With Quote
  #5  
Old 07-24-2004, 10:40 PM
VeX_RaT_Boy VeX_RaT_Boy is offline
WannaBe Scripter
VeX_RaT_Boy's Avatar
Join Date: Aug 2002
Location: Norway
Posts: 960
VeX_RaT_Boy is on a distinguished road
Send a message via ICQ to VeX_RaT_Boy Send a message via AIM to VeX_RaT_Boy Send a message via Yahoo to VeX_RaT_Boy
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...!
__________________
-Kjetil Valen
Reply With Quote
  #6  
Old 07-24-2004, 11:34 PM
Scott Scott is offline
Yoonacorn
Join Date: Oct 2003
Location: Canada
Posts: 3,572
Scott is on a distinguished road
Send a message via MSN to Scott
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.
__________________
Acornlique.
Reply With Quote
  #7  
Old 07-24-2004, 11:52 PM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
whats "properly formatted" I thought it just had to be spaced a bit I hate these rules....
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
  #8  
Old 07-25-2004, 12:16 AM
Xecutor Xecutor is offline
Former UN Manager
Join Date: Apr 2004
Posts: 117
Xecutor is on a distinguished road
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.
Reply With Quote
  #9  
Old 07-25-2004, 12:16 AM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
K ill do that real quick but please help this happpens on many npcs
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
  #10  
Old 07-25-2004, 01:33 AM
VeX_RaT_Boy VeX_RaT_Boy is offline
WannaBe Scripter
VeX_RaT_Boy's Avatar
Join Date: Aug 2002
Location: Norway
Posts: 960
VeX_RaT_Boy is on a distinguished road
Send a message via ICQ to VeX_RaT_Boy Send a message via AIM to VeX_RaT_Boy Send a message via Yahoo to VeX_RaT_Boy
Quote:
Originally Posted by Scott
Ok Python523.
Owned


[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;
}
}

__________________
-Kjetil Valen
Reply With Quote
  #11  
Old 07-25-2004, 04:21 AM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
thanks ill try that asap
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
  #12  
Old 07-25-2004, 05:05 AM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
meh didnt seem to make a difference
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
  #13  
Old 07-25-2004, 05:06 AM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
is like the players[i].hearts and npcs[i].hearts command bugged? weird
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
  #14  
Old 07-25-2004, 01:29 PM
VeX_RaT_Boy VeX_RaT_Boy is offline
WannaBe Scripter
VeX_RaT_Boy's Avatar
Join Date: Aug 2002
Location: Norway
Posts: 960
VeX_RaT_Boy is on a distinguished road
Send a message via ICQ to VeX_RaT_Boy Send a message via AIM to VeX_RaT_Boy Send a message via Yahoo to VeX_RaT_Boy
I didn't do anything, I just formated it better.
All the players[i].vars and npcs[i].vars are READ-ONLY.
__________________
-Kjetil Valen
Reply With Quote
  #15  
Old 07-26-2004, 04:15 AM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
i know wthat but that means
NPC Code:
if (npcs[i].hearts>0) do what i say;

should work, but it ignores that flag
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
  #16  
Old 07-26-2004, 08:50 AM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
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
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial
Reply With Quote
  #17  
Old 07-26-2004, 09:16 PM
Spark910 Spark910 is offline
Ex-Graal Global
Spark910's Avatar
Join Date: Oct 2001
Location: England
Posts: 10,892
Spark910 has a spectacular aura about
Edit by Spark: DIABLO2099's post and those relating to it deleted upon request.
__________________
--Spark911
Reply With Quote
  #18  
Old 07-26-2004, 10:36 PM
sparkers sparkers is offline
Yojumisto Online
sparkers's Avatar
Join Date: Jun 2004
Location: Why does anyone care about that?
Posts: 111
sparkers is on a distinguished road
Send a message via AIM to sparkers
OK ill try that now i didnt no about the break command....
Reply With Quote
  #19  
Old 07-26-2004, 11:42 PM
VeX_RaT_Boy VeX_RaT_Boy is offline
WannaBe Scripter
VeX_RaT_Boy's Avatar
Join Date: Aug 2002
Location: Norway
Posts: 960
VeX_RaT_Boy is on a distinguished road
Send a message via ICQ to VeX_RaT_Boy Send a message via AIM to VeX_RaT_Boy Send a message via Yahoo to VeX_RaT_Boy
Well, you use this.i to check the players, but then if (npcs.[i]hearts>0)

there is no i, only this.i!
__________________
-Kjetil Valen
Reply With Quote
  #20  
Old 07-27-2004, 01:40 AM
Cybnext Cybnext is offline
Registered User
Join Date: Jun 2002
Posts: 100
Cybnext is on a distinguished road
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.
Reply With Quote
  #21  
Old 07-27-2004, 03:35 PM
GoZelda GoZelda is offline
Mister 1,000,000
GoZelda's Avatar
Join Date: Jan 2003
Location: Brussels, capital of Europe.
Posts: 5,396
GoZelda will become famous soon enough
Send a message via AIM to GoZelda Send a message via MSN to GoZelda
Perhaps the problem is that your NPC does not has hearts? As far as I heard NPCs do not automatically have hearts...
__________________

Quote:
Originally Posted by Lance
stefan is satan
I am the best.
[URL removed]Music or aural pollution?
Reply With Quote
  #22  
Old 07-27-2004, 06:38 PM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
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.
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial
Reply With Quote
  #23  
Old 07-28-2004, 08:30 PM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
any npc it shuld go after have hearts, thats the thing. It shuldnt be going after doors and such, which it does..
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:28 AM.


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