02-04-2009, 11:53 AM
I've been trying again and again but the NPC simply doesn't do what I want it to do.
Well, that's something quite vital for my game, because I make some wildlife simulation online.
So the prey-npc (it's a seperate type declared in the corresponding module) should run (or walk, whatever) away from
the player if he/she is in the right distance. I took out the distance stuff because I'm not sure if it was causing the
problems but well, it's still not working.
That code below should check if the npc got prey-behavior and if not it's behaving normally.
Otherwise the prey will take a good run away from the player. That's the plan.
I'm not sure though why it's not doing what it's supposed to
Any ideas?
Well, that's something quite vital for my game, because I make some wildlife simulation online.
So the prey-npc (it's a seperate type declared in the corresponding module) should run (or walk, whatever) away from
the player if he/she is in the right distance. I took out the distance stuff because I'm not sure if it was causing the
problems but well, it's still not working.
That code below should check if the npc got prey-behavior and if not it's behaving normally.
Otherwise the prey will take a good run away from the player. That's the plan.
I'm not sure though why it's not doing what it's supposed to

Code:
' /////////////////////////////////////////////
' // This is used for NPC walking/targetting //
' /////////////////////////////////////////////
' Make sure theres a npc with the map
If map(y).Npc(x) > 0 And MapNpc(y, x).num > 0 Then
Target = MapNpc(y, x).Target
' Check to see if its time for the npc to walk
If Npc(NpcNum).Behavior NPC_BEHAVIOR_SHOPKEEPER Then
' Check to see if we are following a player or not
'If Target > 0 Then
' Check if the player is even playing, if so follow'm
If IsPlaying(Target) And GetPlayerMap(Target) = y Then
DidWalk = False
i = Int(Rnd * 5)
' Lets move the npc
If Npc(NpcNum).Behavior NPC_BEHAVIOR_PREY Then
Select Case i
Case 0
' Up
If MapNpc(y, x).y > GetPlayerY(Target) And DidWalk = False Then
If CanNpcMove(y, x, DIR_UP) Then
Call NpcMove(y, x, DIR_UP, MOVING_WALKING)
DidWalk = True
End If
End If
' Down
If MapNpc(y, x).y < GetPlayerY(Target) And DidWalk = False Then
If CanNpcMove(y, x, DIR_DOWN) Then
Call NpcMove(y, x, DIR_DOWN, MOVING_WALKING)
DidWalk = True
End If
End If
' Left
If MapNpc(y, x).x > GetPlayerX(Target) And DidWalk = False Then
If CanNpcMove(y, x, DIR_LEFT) Then
Call NpcMove(y, x, DIR_LEFT, MOVING_WALKING)
DidWalk = True
End If
End If
' Right
If MapNpc(y, x).x < GetPlayerX(Target) And DidWalk = False Then
If CanNpcMove(y, x, DIR_RIGHT) Then
Call NpcMove(y, x, DIR_RIGHT, MOVING_WALKING)
DidWalk = True
End If
End If
Case 1
' Right
If MapNpc(y, x).x < GetPlayerX(Target) And DidWalk = False Then
If CanNpcMove(y, x, DIR_RIGHT) Then
Call NpcMove(y, x, DIR_RIGHT, MOVING_WALKING)
DidWalk = True
End If
End If
' Left
If MapNpc(y, x).x > GetPlayerX(Target) And DidWalk = False Then
If CanNpcMove(y, x, DIR_LEFT) Then
Call NpcMove(y, x, DIR_LEFT, MOVING_WALKING)
DidWalk = True
End If
End If
' Down
If MapNpc(y, x).y < GetPlayerY(Target) And DidWalk = False Then
If CanNpcMove(y, x, DIR_DOWN) Then
Call NpcMove(y, x, DIR_DOWN, MOVING_WALKING)
DidWalk = True
End If
End If
' Up
If MapNpc(y, x).y > GetPlayerY(Target) And DidWalk = False Then
If CanNpcMove(y, x, DIR_UP) Then
Call NpcMove(y, x, DIR_UP, MOVING_WALKING)
DidWalk = True
End If
End If
Case 2
' Down
If MapNpc(y, x).y < GetPlayerY(Target) And DidWalk = False Then
If CanNpcMove(y, x, DIR_DOWN) Then
Call NpcMove(y, x, DIR_DOWN, MOVING_WALKING)
DidWalk = True
End If
End If
' Up
If MapNpc(y, x).y > GetPlayerY(Target) And DidWalk = False Then
If CanNpcMove(y, x, DIR_UP) Then
Call NpcMove(y, x, DIR_UP, MOVING_WALKING)
DidWalk = True
End If
End If
' Right
If MapNpc(y, x).x < GetPlayerX(Target) And DidWalk = False Then
If CanNpcMove(y, x, DIR_RIGHT) Then
Call NpcMove(y, x, DIR_RIGHT, MOVING_WALKING)
DidWalk = True
End If
End If
' Left
If MapNpc(y, x).x > GetPlayerX(Target) And DidWalk = False Then
If CanNpcMove(y, x, DIR_LEFT) Then
Call NpcMove(y, x, DIR_LEFT, MOVING_WALKING)
DidWalk = True
End If
End If
Case 3
' Left
If MapNpc(y, x).x > GetPlayerX(Target) And DidWalk = False Then
If CanNpcMove(y, x, DIR_LEFT) Then
Call NpcMove(y, x, DIR_LEFT, MOVING_WALKING)
DidWalk = True
End If
End If
' Right
If MapNpc(y, x).x < GetPlayerX(Target) And DidWalk = False Then
If CanNpcMove(y, x, DIR_RIGHT) Then
Call NpcMove(y, x, DIR_RIGHT, MOVING_WALKING)
DidWalk = True
End If
End If
' Up
If MapNpc(y, x).y > GetPlayerY(Target) And DidWalk = False Then
If CanNpcMove(y, x, DIR_UP) Then
Call NpcMove(y, x, DIR_UP, MOVING_WALKING)
DidWalk = True
End If
End If
' Down
If MapNpc(y, x).y < GetPlayerY(Target) And DidWalk = False Then
If CanNpcMove(y, x, DIR_DOWN) Then
Call NpcMove(y, x, DIR_DOWN, MOVING_WALKING)
DidWalk = True
End If
End If
End Select
Else
Target = 1 ' For testing it's set to 1..
' it's the first Player online.
' Down / Up
If GetPlayerY(Target) = MapNpc(y, x).y Then
If MapNpc(y, x).y > GetPlayerY(Target) Then
If CanNpcMove(y, x, DIR_DOWN) Then
Call NpcMove(y, x, DIR_DOWN, MOVING_WALKING)
DidWalk = True
End If
ElseIf MapNpc(y, x).y < GetPlayerY(Target) Then
If CanNpcMove(y, x, DIR_UP) Then
Call NpcMove(y, x, DIR_UP, MOVING_WALKING)
DidWalk = True
End If
End If
' Right / Left
ElseIf GetPlayerY(Target) = MapNpc(y, x).y Then
If MapNpc(y, x).x > GetPlayerX(Target) Then
If CanNpcMove(y, x, DIR_RIGHT) Then
Call NpcMove(y, x, DIR_RIGHT, MOVING_WALKING)
DidWalk = True
End If
ElseIf MapNpc(y, x).x < GetPlayerX(Target) Then
If CanNpcMove(y, x, DIR_LEFT) Then
Call NpcMove(y, x, DIR_LEFT, MOVING_WALKING)
DidWalk = True
End If
End If
End If
End If