It's really simple to do really...Just gotta add a few things, and all done. I've tested it and it works.
Difficulty: 1/5
::Client Side::
Go to modGameLogic and at the bottom add this:
Code: Sub BltNPCName(ByVal Index As Long)
Dim TextX As Long
Dim TextY As Long
With Npc(MapNpc(Index).Num)
'Draw name
TextX = MapNpc(Index).X * PIC_X + MapNpc(Index).XOffset + CLng(PIC_X / 2) - ((Len(Trim$(.Name)) / 2) * 8)
TextY = MapNpc(Index).Y * PIC_Y + MapNpc(Index).YOffset - CLng(PIC_Y / 2) - 4
DrawText TexthDC, TextX, TextY, Trim$(.Name), vbWhite
End With
End Sub
Then find(still in modGameLogic):
Code: ' Lock the backbuffer so we can draw text and names
TexthDC = DD_BackBuffer.GetDC
Below that add:
Code: 'Draw npc name
For i = LBound(MapNpc) To UBound(MapNpc)
If MapNpc(i).Num > 0 Then
BltNPCName i
End If
Next i
hope it works
*crosses fingers
It does for me, I test out all my code that I make tutorials for before I post them up. But if it doesn't for you, for some reason, just post here with the details, I'll try to help you.
Just thought I would add something to this really quick. I haven't tested it but it should work.
If you want to have it only blt the names when you put your mouse over then replace this:
Code: 'Draw npc name
For i = LBound(MapNpc) To UBound(MapNpc)
If MapNpc(i).Num > 0 Then
BltNPCName i
End If
Next i
With this:
Code: 'Draw NPC Names
For i = LBound(MapNpc) To UBound(MapNpc)
If MapNpc(i).Num > 0 Then
If CurX = MapNpc(i).x Then
If CurY = MapNpc(i).y Then
Call BltNPCName(i)
End If
End If
End If
Next i
Also it would be better to make all those If statements just a single If blah And blah2 and blah3 Then because you're just using them for one call.
???
Code: 'Draw NPC Names
For i = LBound(MapNpc) To UBound(MapNpc)
If MapNpc(i).Num > 0 And CurX = MapNpc(i).x And CurY = MapNpc(i).y Then
Call BltNPCName(i)
End If
Next i
Short circuit evaluations still work they just don't work how they should. It would just be for organization really. But never mind on my post.
EDIT:
Never mind...I just did a test with the And statements and without them. I did 10 checks if something was true or not in both ways and did a loop 100 million times and without the and took 8 seconds and with the and took 18 seconds. Don't use And people
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
Shit.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Code: ' Lock the backbuffer so we can draw text and names
TexthDC = DD_BackBuffer.GetDC
that doesnt exist in modGameLogic.. :\
Jared Wrote:Code: ' Lock the backbuffer so we can draw text and names
TexthDC = DD_BackBuffer.GetDC
that doesnt exist in modGameLogic.. :\
Do a project wide search?
Yes i did a project wide search, "Nothing"
:\
Do a search for "TexthDC = DD_BackBuffer.GetDC" without the quotes.
that's what i tried first. lol.
It's in the gameloop sub. Look through it. It's after it calls all the shit for blitting tiles and what not.
Try to search for: Code: TexthDC = DDS_BackBuffer.GetDC
Good luck!
Code: If GettingMap Then
TexthDC = DDS_BackBuffer.GetDC ' Lock the backbuffer so we can draw text and names
Sorry for necro'ing but I have the same problem where I can't find the line Jared couldn't find, I find it in the map portion of the code.
Not only that but I programmed all the code in and it still doesn't work, im using MSE3.79.
This isn't the first time its happened, a lot of times people post tutorials and some people can't even find the line of code they quote and tell them to find, i'm guessing they're using an older version of the source. I just want to know why it doesn't work, I compile it successfully but I test it out and the npcs don't have names over their heads, the only way i'll get an npc name is if I click it.
I assume you're new, so I'll be nice.
Don't bother using tutorials for things this simple, you really won't learn anything. Your best bet is to look at the code for drawing Player names and modifying it for npcs. Very easy to do.
Matt Wrote:I assume you're new, so I'll be nice.
Don't bother using tutorials for things this simple, you really won't learn anything. Your best bet is to look at the code for drawing Player names and modifying it for npcs. Very easy to do.
Exactly.
Try doing it on your own, if you encounter any problems just post and we'd be happy to help you figure it out. However, we will NOT do it for you.
I tried doing this on my own but whenever I put my mouse over an npc nothing happens, I did it correctly as shown above and when I hover my mouse over an npc nothing exquisite happens, is there anything else I have to add because it won't show the character name when I hover my mouse over the npc.
Code: Public Sub DrawNPCName(ByVal Index As Long)
Dim TextX As Long
Dim TextY As Long
Dim color As Long
Select Case Npc(MapNpc(Index).Num).Behavior
Case 0
color = KeyRed
Case 1
color = KeyYellow
Case 2
color = KeyWhite
Case 3
color = KeyWhite
Case 4
color = KeyWhite
End Select
With Npc(MapNpc(Index).Num)
'Draw name and determine location
TextX = MapNpc(Index).x * PIC_X + MapNpc(Index).XOffset + CLng(PIC_X / 2) - ((Len(Trim$(.Name)) / 2) * 8)
TextY = MapNpc(Index).y * PIC_Y + MapNpc(Index).YOffset - CLng(PIC_Y / 2) - 4
Call DrawText(TextX, TextY, TextY + 15, ((Len(Npc(MapNpc(Index).Num).Name)) * 8) + 15, Trim$(.Name), CStr(color))
End With
If TextX < 0 Then TextX = 0
If TextY < 0 Then TextY = 0
End Sub
My code is working fine, except that all NPCs regardless of behavior have their name in red. Do you think that the select case I made should work correctly? Or did I mess up somewhere, I am trying to have the name of each npc be in a different color based on their behavior (attack on sight, attack when attacked, etc.) And I just can't think of what I did wrong here.
I think NPC behavior are strictly strings. like FRIENDLY or ATTACKONSIGHT or whatever. Been a while since I opened a source.
|