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

NPC check


BillyM
 Share

Recommended Posts

You'd obviously need to send a command from the Client to the Server, and then call this Sub to check for an Adjacent NPC

NOTE: I've not tested this, whipped it up in Notepad  :P

```
Public Sub LookForAdjacentNPC(ByVal index As Integer)
'Temporary Values for the X/Y Position
Dim tX As Integer
Dim tY As Integer
Dim NpcIndex As Integer
Dim ValidNPCIndex As Integer
Dim mapNum As Integer
Dim PlayerDir As Integer

'Get Direction we are facing
PlayerDir = GetPlayerDir(index)

'Get Map we are on
mapNum = GetPlayerMap(index)

'Loop through all Map NPCs and See if we are facing them
For NpcIndex = 1 To MAX_MAP_NPCS

        'Check North
        If PlayerDir = DIR_UP Then
            tY = GetPlayerY(index) - 1
            tX = GetPlayerX(index)

            If Map(mapNum).Npc(NpcIndex).x = tX And Map(mapNum).Npc(NpcIndex).y = tY Then
                ValidNPCIndex = NpcIndex
            End If
        End If

      'Check South
        If PlayerDir = DIR_DOWN Then
            tY = GetPlayerY(index) + 1
            tX = GetPlayerX(index)

            If Map(mapNum).Npc(NpcIndex).x = tX And Map(mapNum).Npc(NpcIndex).y = tY Then
                ValidNPCIndex = NpcIndex
            End If
        End If

        'Check East
        If PlayerDir = DIR_RIGHT Then
            tY = GetPlayerY(index)
            tX = GetPlayerX(index) + 1

            If Map(mapNum).Npc(NpcIndex).x = tX And Map(mapNum).Npc(NpcIndex).y = tY Then
                ValidNPCIndex = NpcIndex
            End If
        End If

        'Check West
        If PlayerDir = DIR_LEFT Then
            tY = GetPlayerY(index)
            tX = GetPlayerX(index) - 1

            If Map(mapNum).Npc(NpcIndex).x = tX And Map(mapNum).Npc(NpcIndex).y = tY Then
                ValidNPCIndex = NpcIndex
            End If
        End If

'End the Loop
Next

'If we have a ValidNPCIndex, do whatever
If ValidNPCIndex <> 0 Then
    'Do Your Code here
    Exit Sub
End If

End Sub

```
Link to comment
Share on other sites

Thanks man.  You didn't have to go and do all of that for me, but it's very appreciated. =)  Looking through all the code gets a little confusing.  I'm still trying to get familiar with it.  There was another question I had, but I can't remember what it was right now but I'll be back to working on some things here soon, so I'll get around to posting.

Thanks.
Link to comment
Share on other sites

Only 1 error that I can recall off the top of my head.

```
Map(mapNum).Npc(NpcIndex).x = tX And Map(mapNum).Npc(NpcIndex).y = tY
```to
```
Map(mapNum).MapNpc(NpcIndex).x = tX And Map(mapNum).MapNpc(NpcIndex).y = tY
```
Pretty damn good for throwing it together in Notepad, Samu!  lol

I edited it slightly to use it how I needed it to be used.  I did away with using to control to attack, and i'm now using right click targeting to attack.  You can see where your sub comes into play =)
And didn't need to send any commands to the server, it's all done on the client.
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...