NPC Movementation

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
phao
Grandmaster Poster
Posts: 129
Joined: Fri Aug 31, 2007 2:25 pm

NPC Movementation

Post by phao »

Hey.

Is there anyway to make a npc avoid certain positions (x,y,z,realm) while walking?

I want to make NPC learn where traps are so they don't walk into it twice or more. To do that, the npc will have a list of traps (serials) stored as a cprop (array of ints).

Here is the idea I had, but I don't know how to implement it. A function called NextStepToLocation(npc, x, y). This function, which I'll call ns() from now on, will see where the npc is and where is this location passed as argument. It'll then return a direction, which is the direction you should move to get there. This way, I could do this:

dir=ns(npc, x, y)
if has_known_trap_in_dir(npc, dir) move somewhere else
else move to dir
repeat

That raises some problems. For example, the NPC never moving if there is only one way and there is a trap in this way. But that can be easily solved by making the npc moving over the trap.

That is just one idea. The point is... Is there anyway to create a list of known traps (list of serials, ints) and make npcs avoid walking in the positions those traps are in?
User avatar
tiko
New User
Posts: 14
Joined: Sat Mar 25, 2006 10:01 am

Re: NPC Movementation

Post by tiko »

<tiko> phao: your idea about the traps.. why not have your trap script (the walkon) check if the approaching character is an npc and disable the trap if so?
<tiko> simply check for whether or not the character that stepped on it is a player, then set it off
<phao> hmm
<phao> that's WAYYYYY BETTERRRR
<phao> I'll do that.

For reference; phao requested that I add this.
phao
Grandmaster Poster
Posts: 129
Joined: Fri Aug 31, 2007 2:25 pm

Re: NPC Movementation

Post by phao »

Tomi also suggested something else.

His idea is that I can have that ns() function by using facing. I can make the npc face the direction he'll move to. I can use TurnTowardLocation() or TurnToward(). By making the NPC turn towards something and getting its new facing, I can get the next position it'll be in.

By having the next position it'll be in, it's possible to make something like I've said in my previous message.
User avatar
*Edwards
Forum Regular
Posts: 303
Joined: Fri Dec 28, 2007 11:19 pm

Re: NPC Movementation

Post by *Edwards »

2 Solutions:

- Use control script with a kind of ListMobileNearLocation(). You can get exemple from distro097 ( pkg/items/commCrystal ). So you list every mobile near a trap tile every second to force NPC to change facing and direction...

- Simply remove damage to NPC with a check like " if( who.IsA( POLCLASS_NPC )) return 0; " from walkOn script for all the traps.


I would consider using the second option if your goal is to simply de-activate the traps for your NPCs. I do not believe the control script would be the best idea.... these scripts often use a lot of process for functions that could be used on a WalkonScript, or Script
Post Reply