BillyM Posted February 21, 2011 Author Share Posted February 21, 2011 Is there a function or something on the client to check whether or not your player is adjacent to an NPC? Link to comment Share on other sites More sharing options...
Rob Janes Posted February 21, 2011 Share Posted February 21, 2011 Not sure, but I could whip one up quickly, 1 sec. Link to comment Share on other sites More sharing options...
Rob Janes Posted February 21, 2011 Share Posted February 21, 2011 Do you want it to check for the an NPC in the direction the player is looking, or in any adjacent cell? Link to comment Share on other sites More sharing options...
Rob Janes Posted February 21, 2011 Share Posted February 21, 2011 You'd obviously need to send a command from the Client to the Server, and then call this Sub to check for an Adjacent NPCNOTE: I've not tested this, whipped it up in Notepad :P```Public Sub LookForAdjacentNPC(ByVal index As Integer)'Temporary Values for the X/Y PositionDim tX As IntegerDim tY As IntegerDim NpcIndex As IntegerDim ValidNPCIndex As IntegerDim mapNum As IntegerDim PlayerDir As Integer'Get Direction we are facingPlayerDir = GetPlayerDir(index)'Get Map we are onmapNum = GetPlayerMap(index)'Loop through all Map NPCs and See if we are facing themFor 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 LoopNext'If we have a ValidNPCIndex, do whateverIf ValidNPCIndex <> 0 Then 'Do Your Code here Exit SubEnd IfEnd Sub``` Link to comment Share on other sites More sharing options...
BillyM Posted February 21, 2011 Author Share Posted February 21, 2011 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 More sharing options...
Rob Janes Posted February 21, 2011 Share Posted February 21, 2011 I don't mind helping people out, I really enjoy writing tutorials for people, so I don't mind at all.Let me know if you need anything else. Link to comment Share on other sites More sharing options...
BillyM Posted February 21, 2011 Author Share Posted February 21, 2011 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! lolI 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now