Kimimaru Posted July 6, 2010 Author Share Posted July 6, 2010 Hello, everyone! We all know that Eclipse Origins is a great engine, but we also know that it has some missing features that we'd all like in our games. Displaying npc names on the maps is a feature that I feel is necessary in any game, but unfortunately Eclipse Origins doesn't have it. By the end of this tutorial, you will have this necessity in your game. Let's get started!Everything takes place in the Client source:**modDirectDraw7 -> Sub Render_Graphics**Like player names, we need the npc names to be rendered constantly, so putting the command to draw the names in Sub Render_Graphics, which is in the main game loop, is the ideal place to put the code.Near the bottom of Sub Render_Graphics, find this:```' draw player names For I = 1 To MAX_PLAYERS If IsPlaying(I) And GetPlayerMap(I) = GetPlayerMap(MyIndex) Then Call DrawPlayerName(I) End If Next```Directly under that, add this:```' draw npc names For I = 1 To MAX_MAP_NPCS Call DrawNPCName(I) Next I```Now head over to **modText**, and find **Public Sub DrawPlayerName**. Right under that, add this:```Public Sub DrawNPCName(ByVal Index As Long) Dim NpcName As String Dim TextX As Long, TextY As Long, Sprite As Long, NpcNum As Long NpcNum = MapNpc(Index).Num If NpcNum = 0 Then Exit Sub End If Sprite = Npc(NpcNum).Sprite NpcName = Trim$(Npc(NpcNum).Name) ' Calculate the X coordinate to place the name TextX = ConvertMapX(MapNpc(Index).X * PIC_X) + MapNpc(Index).XOffset + (PIC_X \ 2) - getWidth(TexthDC, NpcName) If Sprite < 1 Or Sprite > NumCharacters Then TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - 17 Else TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - (DDSD_Character(Sprite).lHeight) + 16 End If ' Draw name Call DrawText(TexthDC, TextX, TextY, NpcName, QBColor(White))End Sub```This is just the Sub that actually does the calculations for drawing out the NPC name.That's all! To change the color of the npc name, look at this line in **Public Sub DrawNpcName**:```Call DrawText(TexthDC, TextX, TextY, NpcName, QBColor(White))```Change the **White** variable with the variable of another color. This works for npcs with dynamic sprite sizes as well as npcs with no sprites.Enjoy! Link to comment Share on other sites More sharing options...
Robin Posted July 6, 2010 Share Posted July 6, 2010 @Kimimaru:> although I'm sure it's a planned feature.It's not. I added it in before, but I felt it didn't suit the retro feel I go for.It's an okay tutorial. I take it you just took the code from DrawPlayerName? Link to comment Share on other sites More sharing options...
Kimimaru Posted July 6, 2010 Author Share Posted July 6, 2010 @Robin:> @Kimimaru:> > > although I'm sure it's a planned feature.> > It's not. I added it in before, but I felt it didn't suit the retro feel I go for.> > It's an okay tutorial. I take it you just took the code from DrawPlayerName?Oh, okay. Well, if people want it, at least they can have it now. I took and edited some code from both DrawPlayerName and BltNpc. Link to comment Share on other sites More sharing options...
Robin Posted July 6, 2010 Share Posted July 6, 2010 Good stuff. It's a solid tutorial. Link to comment Share on other sites More sharing options...
Mulkaar Posted July 6, 2010 Share Posted July 6, 2010 Is there a way to make it so that friendly NPCs have visible names and Enemies don't? If so good tutorial. Link to comment Share on other sites More sharing options...
Akselj Posted July 6, 2010 Share Posted July 6, 2010 Obviously you just check that before you call DrawNpcName(I) Link to comment Share on other sites More sharing options...
Kimimaru Posted July 6, 2010 Author Share Posted July 6, 2010 @Grendalin:> Is there a way to make it so that friendly NPCs have visible names and Enemies don't? If so good tutorial.Yes, and it's pretty simple to do. Find this line in Public Sub DrawNpcName:```Sprite = Npc(NpcNum).Sprite```Above that, add this:```If Npc(NpcNum).Behaviour <> NPC_BEHAVIOUR_FRIENDLY Then Exit SubEnd If``` Link to comment Share on other sites More sharing options...
thefakebrain Posted July 7, 2010 Share Posted July 7, 2010 Didn't work :huh: names doesn't show up….what now ? btw im using Visual Basic 2010 express Link to comment Share on other sites More sharing options...
Ruins of Hell Posted July 7, 2010 Share Posted July 7, 2010 Only Visual Basic 6 (not portable) will work when editing the Eclipse Source. Link to comment Share on other sites More sharing options...
Robin Posted July 7, 2010 Share Posted July 7, 2010 [http://www.touchofdeathforums.com/smf/index.php/topic,61053.0.html](http://www.touchofdeathforums.com/smf/index.php/topic,61053.0.html) Link to comment Share on other sites More sharing options...
Punika Posted July 8, 2010 Share Posted July 8, 2010 Thanks Kimimaru.Based on this I have just added an option to turn names (player and npc) on/off. Link to comment Share on other sites More sharing options...
Kimimaru Posted July 9, 2010 Author Share Posted July 9, 2010 Okay, no problem. I'm glad I could help! Link to comment Share on other sites More sharing options...
adr990 Posted July 12, 2010 Share Posted July 12, 2010 Wohoo thanks, great job.I really needed this. :)Though I want to have Atack on sight to be Red.And Shopkeeper, Banker, Friendly, to be White.And Atack when attacked to be Orange. (Or maybe a other color.)I tried this:```Public Sub DrawNPCName(ByVal Index As Long) Dim NpcName As String Dim TextX As Long, TextY As Long, Sprite As Long, NpcNum As Long NpcNum = MapNpc(Index).Num If NpcNum = 0 Then Exit Sub End If If Npc(NpcNum).Behaviour <> NPC_BEHAVIOUR_FRIENDLY Then Call DrawText(TexthDC, TextX, TextY, NpcName, QBColor(White)) Exit Sub Else End If If Npc(NpcNum).Behaviour <> NPC_BEHAVIOUR_SHOPKEEPER Then Call DrawText(TexthDC, TextX, TextY, NpcName, QBColor(White)) Exit Sub End If Sprite = Npc(NpcNum).Sprite NpcName = Trim$(Npc(NpcNum).Name) ' Calculate the X coordinate to place the name TextX = ConvertMapX(MapNpc(Index).X * PIC_X) + MapNpc(Index).XOffset + (PIC_X \ 2) - getWidth(TexthDC, NpcName) If Sprite < 1 Or Sprite > NumCharacters Then TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - 17 Else TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - (DDSD_Character(Sprite).lHeight) + 16 End If ' Draw name Call DrawText(TexthDC, TextX, TextY, NpcName, QBColor(Red))End Sub```As I don't know the command for NPC's like "NPC_BEHAVIOUR_FRIENDLY" I tried guessing it.No compile error. But it doesn't work at all anymore.When I just Kimimaru's script without Shopkeeper, only Friendly have Red. And other behavior NPC's nothing.I would really apprentice all help.Thanks in advance! Link to comment Share on other sites More sharing options...
Ertzel Posted July 12, 2010 Share Posted July 12, 2010 Well you have the code to display text, before all of the displaying text code is even handled, then u have it exiting the script before running it all…Try this```Public Sub DrawNPCName(ByVal Index As Long) Dim NpcName As String Dim TextX As Long, TextY As Long, Sprite As Long, NpcNum As Long NpcNum = MapNpc(Index).Num If NpcNum = 0 Then Exit Sub End If Sprite = Npc(NpcNum).Sprite NpcName = Trim$(Npc(NpcNum).Name) ' Calculate the X coordinate to place the name TextX = ConvertMapX(MapNpc(Index).X * PIC_X) + MapNpc(Index).XOffset + (PIC_X \ 2) - getWidth(TexthDC, NpcName) If Sprite < 1 Or Sprite > NumCharacters Then TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - 17 Else TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - (DDSD_Character(Sprite).lHeight) + 16 End If ' Draw name If Npc(NpcNum).Behaviour = NPC_BEHAVIOUR_ATTACKONSIGHT Then Call DrawText(TexthDC, TextX, TextY, NpcName, QBColor(Red)) End If If Npc(NpcNum).Behaviour = NPC_BEHAVIOUR_ATTACKWHENATTACKED Then Call DrawText(TexthDC, TextX, TextY, NpcName, QBColor(Orange)) End If If Npc(NpcNum).Behaviour <> NPC_BEHAVIOUR_ATTACKONSIGHT And Npc(NpcNum).Behaviour <> NPC_BEHAVIOUR_ATTACKWHENATTACKED Then Call DrawText(TexthDC, TextX, TextY, NpcName, QBColor(White)) End IfEnd Sub``` Link to comment Share on other sites More sharing options...
Fugetaboutit Posted July 12, 2010 Share Posted July 12, 2010 wouldn't it be better to do like how drawplayernames are in a select case.something like…``` ' Check npc behaviour If NpcNum > 0 Then Select Case Npc(NpcNum).Behaviour Case 0 ' NPC_BEHAVIOUR_ATTACKONSIGHT color = RGB(255, 96, 0) Case 1 ' NPC_BEHAVIOUR_ATTACKWHENATTACKED color = QBColor(DarkGrey) Case 2 ' NPC_BEHAVIOUR_FRIENDLY color = QBColor(Cyan) Case 3 ' NPC_BEHAVIOUR_SHOPKEEPER color = QBColor(BrightGreen) Case 4 ' NPC_BEHAVIOUR_GUARD color = QBColor(Yellow) End Select Else color = QBColor(BrightRed) End If``` Link to comment Share on other sites More sharing options...
adr990 Posted July 12, 2010 Share Posted July 12, 2010 @Ertzel:> Well you have the code to display text, before all of the displaying text code is even handled, then u have it exiting the script before running it all…> > Try this> -snip-Hmm.. I see.Thanks a ton Ertzel link! It works flawless now. :)(Though, EO doesn't accept 'Orange' so I changed it to Blue, for the time being)@boneyouYour script doesn't work here. It gives compile errors.But indeed it is a nice idea. Link to comment Share on other sites More sharing options...
Fugetaboutit Posted July 12, 2010 Share Posted July 12, 2010 here's my whole sub. the error you were getting was probably the color wasn't dimmed```Public Sub DrawNPCName(ByVal Index As Long) Dim NpcName As String Dim TextX As Long, TextY As Long, Sprite As Long, NpcNum As Long Dim color As Long NpcNum = MapNpc(Index).Num If NpcNum = 0 Then Exit Sub End If Sprite = Npc(NpcNum).Sprite NpcName = Trim$(Npc(NpcNum).Name) ' Calculate the X coordinate to place the name TextX = ConvertMapX(MapNpc(Index).X * PIC_X) + MapNpc(Index).XOffset + (PIC_X \ 2) - getWidth(TexthDC, NpcName) If Sprite < 1 Or Sprite > NumCharacters Then TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - 17 Else TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - (DDSD_Character(Sprite).lHeight) + 16 End If ' Check npc behaviour If NpcNum > 0 Then Select Case Npc(NpcNum).Behaviour Case 0 ' NPC_BEHAVIOUR_ATTACKONSIGHT color = RGB(255, 96, 0) Case 1 ' NPC_BEHAVIOUR_ATTACKWHENATTACKED color = QBColor(DarkGrey) Case 2 ' NPC_BEHAVIOUR_FRIENDLY color = QBColor(Cyan) Case 3 ' NPC_BEHAVIOUR_SHOPKEEPER color = QBColor(BrightGreen) Case 4 ' NPC_BEHAVIOUR_GUARD color = QBColor(Yellow) End Select Else color = QBColor(BrightRed) End If ' Draw name Call DrawText(TexthDC, TextX, TextY, NpcName, color)End Sub``` Link to comment Share on other sites More sharing options...
adr990 Posted July 12, 2010 Share Posted July 12, 2010 @boneyou:> here's my whole sub. the error you were getting was probably the color wasn't dimmed> > ```> Public Sub DrawNPCName(ByVal Index As Long)> Dim NpcName As String> Dim TextX As Long, TextY As Long, Sprite As Long, NpcNum As Long> Dim color As Long> > NpcNum = MapNpc(Index).Num> > If NpcNum = 0 Then> Exit Sub> End If> > Sprite = Npc(NpcNum).Sprite> NpcName = Trim$(Npc(NpcNum).Name)> > ' Calculate the X coordinate to place the name> TextX = ConvertMapX(MapNpc(Index).X * PIC_X) + MapNpc(Index).XOffset + (PIC_X \ 2) - getWidth(TexthDC, NpcName)> > If Sprite < 1 Or Sprite > NumCharacters Then> TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - 17> Else> TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - (DDSD_Character(Sprite).lHeight) + 16> End If> > ' Check npc behaviour> If NpcNum > 0 Then> > Select Case Npc(NpcNum).Behaviour> Case 0 ' NPC_BEHAVIOUR_ATTACKONSIGHT> color = RGB(255, 96, 0)> Case 1 ' NPC_BEHAVIOUR_ATTACKWHENATTACKED> color = QBColor(DarkGrey)> Case 2 ' NPC_BEHAVIOUR_FRIENDLY> color = QBColor(Cyan)> Case 3 ' NPC_BEHAVIOUR_SHOPKEEPER> color = QBColor(BrightGreen)> Case 4 ' NPC_BEHAVIOUR_GUARD> color = QBColor(Yellow)> End Select> Else> color = QBColor(BrightRed)> End If> > ' Draw name> Call DrawText(TexthDC, TextX, TextY, NpcName, color)> End Sub> ```Neat. :)Thanks for this too, I'm using this at the moment. Keep it up!RGB(255,128,0 =/= Orange (yay) Link to comment Share on other sites More sharing options...
Fugetaboutit Posted July 12, 2010 Share Posted July 12, 2010 Thank Robin. I just took the one from drawplayername and changed it a bit. Link to comment Share on other sites More sharing options...
erkro1 Posted January 3, 2011 Share Posted January 3, 2011 How do you get this working for EC? 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