Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Improving "Sight Range"


Adrian
 Share

Recommended Posts

This is something I have been trying to figure out which I feel may also be helpful to others as well. I'm working on a way to change the way that Sight Range works for NPC's. My goal is to change the Attack on Sight event to only activate when the NPC is facing the player.

I have played around a bit with using the NPC's current direction as well as its placement on the map in relation to the current placement of the Player that it is attempting to target. I don't have much experience with VB so my attempts have been futile.

Any help would be greatly appreciated.

Best,
Adrian
Link to comment
Share on other sites

```

                                       ' Are they in range?  if so GET'M!
                                       If DistanceX <= n And DistanceY <= n Then

                                           If Not MapNpc(mapnum).NPC(x).Dir = DIR_UP And GetPlayerY(i) > MapNpc(mapnum).NPC(x).y Then                      'THIS IS WHAT I ADDED
                                               If NPC(npcNum).Behaviour = NPC_BEHAVIOUR_ATTACKONSIGHT Or GetPlayerPK(i) = YES Then
                                                   If Not (Trim$(NPC(npcNum).AttackSay)) = "." Then
                                                       Call SendChatBubble(mapnum, x, TARGET_TYPE_NPC, Trim$(NPC(npcNum).AttackSay), DarkBrown)
                                                   End If
                                               End If
                                               MapNpc(mapnum).NPC(x).targetType = 1 ' player
                                               MapNpc(mapnum).NPC(x).Target = i  
                                           End If
                                       End If
```
My thought process: If the NPC is facing up, and the character is below the NPC on the map, then the NPC shouldn't be able to target the character (despite being within "sight range").
Note: I used "If Not".. I don't really like it that way but it seems to be the way things are done round' here, or at least in the source code that I have.

Also, this is only for the one direction - I would still have to add the others.
Link to comment
Share on other sites

```
If MapNpc(mapnum).NPC(x).Dir = DIR_UP And GetPlayerY(i) < MapNpc(mapnum).NPC(x).y Then
```~~Would likely work better, the Y value increases as you move further down the map(If memory serves me). :)~~

I'm a dummy. Corrected it, I can't test it as I haven't had VB6 on this machine in ages. I don't know if it will make an actual difference though.. But it should
Link to comment
Share on other sites

Well I've tried that as well, and still nothing. If I were to comment out the 4 lines the NPC does attack when in range. I'm not sure why this code won't work.

```
                                       ' Are they in range?  if so GET'M!

                                       If DistanceX <= n And DistanceY <= n Then
                                           'I have added these 4 lines below
                                           If MapNpc(mapnum).NPC(x).Dir = DIR_UP And GetPlayerY(i) < MapNpc(mapnum).NPC(x).y Then
                                           If MapNpc(mapnum).NPC(x).Dir = DIR_DOWN And GetPlayerY(i) > MapNpc(mapnum).NPC(x).y Then
                                           If MapNpc(mapnum).NPC(x).Dir = DIR_LEFT And GetPlayerX(i) > MapNpc(mapnum).NPC(x).x Then
                                           If MapNpc(mapnum).NPC(x).Dir = DIR_RIGHT And GetPlayerX(i) < MapNpc(mapnum).NPC(x).x Then

                                               If NPC(npcNum).Behaviour = NPC_BEHAVIOUR_ATTACKONSIGHT Or GetPlayerPK(i) = YES Then
                                                   If Not (Trim$(NPC(npcNum).AttackSay)) = "." Then
                                                       Call SendChatBubble(mapnum, x, TARGET_TYPE_NPC, Trim$(NPC(npcNum).AttackSay), DarkBrown)
                                                   End If
                                                   End If
                                                   MapNpc(mapnum).NPC(x).targetType = 1 ' player
                                                   MapNpc(mapnum).NPC(x).Target = i
                                               End If

                                           End If
                                           End If
                                           End If
                                           End If
                                       End If
```
Link to comment
Share on other sites

That will never work, because it will assume all of those will need to be true in all cases. ;) Which of course will never happen.

I didn't think you actually did this, I see why it doesn't work. If statements are being used sequentually like this, if the first one passes it moves to the next. You'd be better off writing a function.

```
Function IsPlayerVisible(ByVal NpcIndex as Long, ByVal PlayerIndex as Long ) as Boolean
   IsPlayerVisible = false
   If MapNpc(mapnum).NPC(x).Dir = DIR_UP And GetPlayerY(i) < MapNpc(mapnum).NPC(x).y Then IsPlayerVisible = true
   If MapNpc(mapnum).NPC(x).Dir = DIR_DOWN And GetPlayerY(i) > MapNpc(mapnum).NPC(x).y Then IsPlayerVisible = true
   If MapNpc(mapnum).NPC(x).Dir = DIR_LEFT And GetPlayerX(i) > MapNpc(mapnum).NPC(x).x Then IsPlayerVisible = true
   If MapNpc(mapnum).NPC(x).Dir = DIR_RIGHT And GetPlayerX(i) < MapNpc(mapnum).NPC(x).x Then IsPlayerVisible = true
End Function
```
That might work, I'm not sure if it will compile though. I'm used to C#.

Just call it like

```
If IsPlayerVisible(Npc, Index) Then
Combt stuff here
End If
```
Link to comment
Share on other sites

So this is my function:

```
Function IsPlayerVisible(NpcIndex As Long, PlayerIndex As Long, mapnum As Long) As Boolean

  Dim i As Long, x As Long
  IsPlayerVisible = False
  If MapNpc(mapnum).NPC(x).Dir = DIR_UP And GetPlayerY(i) < MapNpc(mapnum).NPC(x).y Then IsPlayerVisible = True
  If MapNpc(mapnum).NPC(x).Dir = DIR_DOWN And GetPlayerY(i) > MapNpc(mapnum).NPC(x).y Then IsPlayerVisible = True
  If MapNpc(mapnum).NPC(x).Dir = DIR_LEFT And GetPlayerX(i) > MapNpc(mapnum).NPC(x).x Then IsPlayerVisible = True
  If MapNpc(mapnum).NPC(x).Dir = DIR_RIGHT And GetPlayerX(i) < MapNpc(mapnum).NPC(x).x Then IsPlayerVisible = True
End Function
```
And this is how I call it:

```

                                       ' Are they in range?  if so GET'M!
                                       If DistanceX <= n And DistanceY <= n Then

                                           If IsPlayerVisible(x, i, mapnum) Then
Cmbt stuff..

```I don't think I did it right, it is giving me a RTE:9 on the Line "If MapNpc(mapnum).NPC(x).Dir = DIR_UP And GetPlayerY(i) < MapNpc(mapnum).NPC(x).y "
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...