Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Intelligent NPC movements

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
Battleblaze
Warrior Thread Monk




Joined: 19 Dec 2003
Posts: 782
Location: IndY OHR

PostPosted: Thu May 26, 2005 7:25 am    Post subject: Intelligent NPC movements Reply with quote

I'm making a game and I'm tryin to have stealth as an element.

Of course I have an attack script that lets you destroy the NPC (james' sword script) but I don't know how I would go about running the two at the same time. What I'm trying to go for is, when you get within 5 blocks/tiles range of the NPC (and this has to work for more than 1 type of NPC) the NPC will starts to chase you.

What would be even better is if the chase hero part wore off after awhile and the nPc would return to its post...But all I want now is it to follow you if you get too close.

And the step on NPC won't work because I need to have it work for all the NPCs on the map, so using tags is out of the question...

They did somthing like this in smokey magoo but I'm not sure how.
_________________
Indy OHR! and National OHR Month Contest going on now!

"Aeth calls PHC an anti-semite; PHC blames anti-semitism"
-squall
Back to top
View user's profile Send private message Visit poster's website AIM Address
Mike Caron
Technomancer




Joined: 26 Jul 2003
Posts: 889
Location: Why do you keep asking?

PostPosted: Thu May 26, 2005 7:48 am    Post subject: Reply with quote

To tell whether an NPC is within 5 tiles of you (better to think of it this way), you'll need to do something like this:

Code:

script, detect NPC,NPC ID,begin
variable(npc,i)
for(i,0,npc count(NPC ID)-1,1) do, begin
    npc = NPC Reference(NPC ID,i)
    if(npc x(npc) > hero x(me) - 5, and
       npc x(npc) < hero x(me) + 5, and
       npc y(npc) > hero y(me) - 5, and
       npc y(npc) < hero y(me) + 5) then, begin
          #do something if an NPC is close
       end
end
end


This function (which is straight off the top of my head and isn't tested) should probably be called in the same loop that the sword script is. Pass the ID of the NPC to check. Call it multiple times if more than one NPC type should be checked.
_________________
I stand corrected. No rivers ran blood today. At least, none that were caused by us.

Final Fantasy Q
OHR Developer BLOG
Official OHRRPGCE Wiki and FAQ
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Battleblaze
Warrior Thread Monk




Joined: 19 Dec 2003
Posts: 782
Location: IndY OHR

PostPosted: Thu May 26, 2005 5:13 pm    Post subject: Reply with quote

I had to configure it (hspeak hated your varible definitions so i just kept cutin it down until it worked) but hspeak hates the and definitions.

it says

If statements only require one condition you have 3. Try using and & Or statements instead...even tough the script HAD and and or statements...

This is all thats left of your script after I tried to make it work...(sorry I'm really bad at arguments and such)

nclude,plotscr.hsd


define script (1,detect NPC,1,0,)
script, detect NPC,NPC ID,begin


variable(apc,i)
for(apc,-1,1) do, begin

if(npc x(npc) >> hero x(me) - 5,and
npc x(npc) << hero x(me) + 5,and
npc y(npc) >> hero y(me) - 5,and
npc y(npc) << hero y(me) + 5)
then, begin
#do something if an NPC is close
end
end
end

it all makes me sad Neutral
_________________
Indy OHR! and National OHR Month Contest going on now!

"Aeth calls PHC an anti-semite; PHC blames anti-semitism"
-squall
Back to top
View user's profile Send private message Visit poster's website AIM Address
Mike Caron
Technomancer




Joined: 26 Jul 2003
Posts: 889
Location: Why do you keep asking?

PostPosted: Thu May 26, 2005 6:23 pm    Post subject: Reply with quote

Yeah, that was my bad. I accidentally used "<" instead of "<<" and so forth.

This code is the revised code that *would* make the NPC chase you, except I just remembered something: Alter NPC affects all the NPCs of that ID. So, if, say, you have a bunch of guards to be stealthy around, you'd need to make several NPCs with the same properties, you couldn't just drop the same NPC down a couple times.

Anyway, back to the script, making the guard lose interest in you after a while is much more difficult because it would be difficult to keep track of how long each guard was chasing you and stuff. Or, we could just modify the script to say "if they're NOT within 5 tiles, they're not interested", making it so you'd need to escape, or some such thing.

Code:
variable(npc,i) # Note: fixed a typo
    for(apc,-1,1) do, begin
        if(npc x(npc) >> hero x(me) - 5,and
        npc x(npc) << hero x(me) + 5,and
        npc y(npc) >> hero y(me) - 5,and
        npc y(npc) << hero y(me) + 5)
        then, begin
            alter NPC (npc, NPC stat: move type, NPCmovetype:chaseyou)
        end
    end
end

_________________
I stand corrected. No rivers ran blood today. At least, none that were caused by us.

Final Fantasy Q
OHR Developer BLOG
Official OHRRPGCE Wiki and FAQ
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Thu May 26, 2005 7:09 pm    Post subject: Reply with quote

Thats because Mike is (still) using - instead of -- for subtraction.Change those. Also, you have one more instance of 'apc' in the for statement.

Actually, if you want the guard to chase you when you come within 5 tiles, you should probably use <= and >= instead of << and >>
Back to top
View user's profile Send private message Send e-mail
Mike Caron
Technomancer




Joined: 26 Jul 2003
Posts: 889
Location: Why do you keep asking?

PostPosted: Fri May 27, 2005 7:50 am    Post subject: Reply with quote



Shut up. Yes, that which TMC says is correct. I always forget --...
_________________
I stand corrected. No rivers ran blood today. At least, none that were caused by us.

Final Fantasy Q
OHR Developer BLOG
Official OHRRPGCE Wiki and FAQ
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Battleblaze
Warrior Thread Monk




Joined: 19 Dec 2003
Posts: 782
Location: IndY OHR

PostPosted: Sat May 28, 2005 7:43 am    Post subject: Reply with quote

For the Gaurd to lose interest coulden't you just have a wait command followed by another alter NPC command (to wander)?

Awright I have just a few more questions. The script compiled,this is good. But does it have to be a specific NPC or argument?Do have have to change the varible or what? And in the editor the NPC will run the script....but in order to be activated the NPC has to be touched, which deafeats the whole purpose of the stealth thing....

All I really want now is some final directions Smokin' ...
_________________
Indy OHR! and National OHR Month Contest going on now!

"Aeth calls PHC an anti-semite; PHC blames anti-semitism"
-squall
Back to top
View user's profile Send private message Visit poster's website AIM Address
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Sun May 29, 2005 2:49 am    Post subject: Reply with quote

No, you run that script in a while loop in your map autorun script, once for each guard id.

So having a wait followed by another alter npc command won't work. You could have a set of timers, and a bunch of timer checking code in your main loop, but ere it gets compicated quickly, I wouldn't suggest it.
Back to top
View user's profile Send private message Send e-mail
junahu
Custom Title: 45 character limit




Joined: 13 Jan 2004
Posts: 369
Location: Hull, England

PostPosted: Tue Jul 19, 2005 5:17 am    Post subject: Reply with quote

.

Last edited by junahu on Thu Jul 21, 2005 2:21 am; edited 2 times in total
Back to top
View user's profile Send private message Send e-mail
Soule X




Joined: 13 Sep 2004
Posts: 131
Location: Indiana

PostPosted: Tue Jul 19, 2005 10:36 am    Post subject: Reply with quote

Couldn't you just run it as the "Every Step" script?

That way you could do the "Wait (x), Set it to Wander".

I don't see a problem with this, except when you take a step it's going to start chasing you again. But you should be able to set a tag or something that makes the script not run for a few steps.
Back to top
View user's profile Send private message Send e-mail AIM Address
junahu
Custom Title: 45 character limit




Joined: 13 Jan 2004
Posts: 369
Location: Hull, England

PostPosted: Thu Jul 21, 2005 2:20 am    Post subject: Reply with quote

The problem there is that the player has to step to be noticed. With a map autorun/while loop script, it'll run every frame regardless of whether you're moving or not.
_________________
Back to top
View user's profile Send private message Send e-mail
junahu
Custom Title: 45 character limit




Joined: 13 Jan 2004
Posts: 369
Location: Hull, England

PostPosted: Thu Jul 21, 2005 2:24 am    Post subject: Reply with quote

God damn it! My previous link went to a person's profile rather than an actual game. Damn it all! Pissed off!


This is what I meant to link to (I hope)

http://castleparadox.com/ohr/download.php?game=408


P.S. I forgot that the .hss files were not included. I'll get them by tommorrow to show everyone how I did 'intelligent' npcs.
_________________
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group