Kimimaru Posted July 6, 2010 Author Share Posted July 6, 2010 Hey, everyone! This is another feature I feel is important for games made with Eclipse Origins. I will explain the code as the tutorial progresses. Let's get started!**Server**There is only one thing we need to do in the Server, and that is to send the map npc's hp to everyone on the map when it loses some HP. Luckily, Eclipse Origins already has a Sub designed for doing this; all we need to do is call it.**modPlayer -> Sub AttackNpc**Find this:```' NPC not dead, just do the damage    MapNpc(MapNum).Npc(MapNpcNum).Vital(Vitals.HP) = MapNpc(MapNum).Npc(MapNpcNum).Vital(Vitals.HP) - Damage    ' Check for a weapon and say damage    SendActionMsg MapNum, "-" & Damage, BrightRed, 1, (MapNpc(MapNum).Npc(MapNpcNum).x * 32), (MapNpc(MapNum).Npc(MapNpcNum).y * 32)    SendBlood GetPlayerMap(Attacker), MapNpc(MapNum).Npc(MapNpcNum).x, MapNpc(MapNum).Npc(MapNpcNum).y```Add this right under that:```SendMapNpcVitals GetPlayerMap(Attacker), MapNpcNum```That's all for the Server!**Client**Now it's time for us to actually draw out the HP bar graphics above the npc. Like most other graphics, we need to call the Sub that draws the HP bar in the main game loop so that it is constantly being rendered. The best place to do this would be Public Sub Render_Graphics.**modDirectDraw7 -> Public Sub Render_Graphics**Find this:```' Npcs      For I = 1 To MAX_MAP_NPCS        If MapNpc(I).Y = Y Then          Call BltNpc(I)        End If      Next```Replace it with this:```' Npcs      For I = 1 To MAX_MAP_NPCS        ' Draw out npc hp bars        Call BltNpcHP(I)        If MapNpc(I).Y = Y Then          Call BltNpc(I)        End If      Next```Now that that's done, we just have to put in the Sub that draws the mini HP bar.Add this under **Public Sub BltNpc** in **modDirectDraw7**:```Public Sub BltNpcHP(ByVal Index As Long)  Dim X As Long, Y As Long, Sprite As Long, NpcNum As Long  NpcNum = MapNpc(Index).Num  If NpcNum = 0 Then    Exit Sub  End If  ' Don't display the HP if the npc is at max hp  If MapNpc(Index).Vital(Vitals.HP) = Npc(NpcNum).HP Then    Exit Sub  End If  ' Only display HP for npcs that we can attack  If Npc(NpcNum).Behaviour <> NPC_BEHAVIOUR_ATTACKONSIGHT And Npc(NpcNum).Behaviour <> NPC_BEHAVIOUR_ATTACKWHENATTACKED Then    Exit Sub  End If  Sprite = Npc(NpcNum).Sprite  ' Calculate the X coordinate to place the name  X = MapNpc(Index).X * PIC_X + MapNpc(Index).XOffset  If Sprite < 1 Or Sprite > NumCharacters Then    Y = MapNpc(Index).Y * PIC_Y + MapNpc(Index).YOffset - 22  Else    Y = MapNpc(Index).Y * PIC_Y + MapNpc(Index).YOffset - (DDSD_Character(Sprite).lHeight) + 11  End If  ' Draw the outside box  Call DDS_BackBuffer.SetFillColor(RGB(0, 0, 0))  Call DDS_BackBuffer.DrawBox(ConvertMapX(X), ConvertMapY(Y), ConvertMapX(X + 32), ConvertMapY(Y + 4))  ' Draw the HP  Call DDS_BackBuffer.SetFillColor(RGB(0, 255, 0))  Call DDS_BackBuffer.DrawBox(ConvertMapX(X), ConvertMapY(Y), ConvertMapX(X + Int(((MapNpc(Index).Vital(Vitals.HP) / 32) / (Npc(NpcNum).HP / 32)) * 32)), ConvertMapY(Y + 4))End Sub```This is the Sub that renders the HP bar above the npc. To change the position of the HP bar, find these lines of code:```    Y = MapNpc(Index).Y * PIC_Y + MapNpc(Index).YOffset - 22    Y = MapNpc(Index).Y * PIC_Y + MapNpc(Index).YOffset - (DDSD_Character(Sprite).lHeight) + 11```The above statement is if the npc has no sprite, and the bottom one is if the npc has a sprite. Simply change the numbers at the end (-22 and +11) to change the position of the HP bar. Decreasing the number will result in the HP bar being rendered higher above the npc, and increasing the number will render the HP bar closer to the npc.Currently, the npc's mini HP bar will not display if its HP is full. To make the mini HP bar display all the time, remove these few lines of code from **Public Sub BltNpcHP**:```' Don't display the HP if the npc is at max hp  If MapNpc(Index).Vital(Vitals.HP) = Npc(NpcNum).HP Then    Exit Sub  End If```Enjoy! Link to comment Share on other sites More sharing options...
bandcampboy Posted July 7, 2010 Share Posted July 7, 2010 I'm pretty sure I did everything you said and It's not working for me. Could you post screenshots of the effects so I can see what it's supposed to look like. Link to comment Share on other sites More sharing options...
Kimimaru Posted July 7, 2010 Author Share Posted July 7, 2010 @bandcampboy:> I'm pretty sure I did everything you said and It's not working for me. Could you post screenshots of the effects so I can see what it's supposed to look like.Yeah, I can, but did you make sure you put some of the code in the Server?Npc at max HP:![](http://www.freemmorpgmaker.com/files/imagehost/pics/51f870c0360cee47a0ec8b88b8386d9c.png)Npc with HP taken:![](http://www.freemmorpgmaker.com/files/imagehost/pics/ee5b9b337a9450c5487959e26300889a.png) Link to comment Share on other sites More sharing options...
bandcampboy Posted July 7, 2010 Share Posted July 7, 2010 Yeah I'm sure I put code in the server. I just double checked my placement of all the code step by step and it all seems to check out. Link to comment Share on other sites More sharing options...
Kimimaru Posted July 7, 2010 Author Share Posted July 7, 2010 Did you try taking out HP from an NPC? Link to comment Share on other sites More sharing options...
bandcampboy Posted July 7, 2010 Share Posted July 7, 2010 Yeah I tested it. I tried changing the code so it appeared all the time and that didn't work either. Link to comment Share on other sites More sharing options...
Robin Posted July 7, 2010 Share Posted July 7, 2010 Are you compiling the project properly? Link to comment Share on other sites More sharing options...
bandcampboy Posted July 8, 2010 Share Posted July 8, 2010 I'm not sure. What is the proper way to compile exactly? Link to comment Share on other sites More sharing options...
Robin Posted July 8, 2010 Share Posted July 8, 2010 Ctrl + F5 in the IDE. Link to comment Share on other sites More sharing options...
bandcampboy Posted July 8, 2010 Share Posted July 8, 2010 Please excuse my noobness but I'm new to Visual basic. What's the IDE? Link to comment Share on other sites More sharing options...
Kimimaru Posted July 8, 2010 Author Share Posted July 8, 2010 Basically, when you have your project open in Visual Basic 6, press CTRL + F5 to compile it. Link to comment Share on other sites More sharing options...
bandcampboy Posted July 8, 2010 Share Posted July 8, 2010 K. I did that and it didnt work. Could I send the .vbp files to you so you can see what I did wrong? Link to comment Share on other sites More sharing options...
Kimimaru Posted July 8, 2010 Author Share Posted July 8, 2010 Yeah, I suppose. Just send them to me through a PM. Link to comment Share on other sites More sharing options...
bandcampboy Posted July 9, 2010 Share Posted July 9, 2010 I got it working! It's a very handy feature. Thank you for sharing this and helping me. Link to comment Share on other sites More sharing options...
Kimimaru Posted July 9, 2010 Author Share Posted July 9, 2010 No problem. Link to comment Share on other sites More sharing options...
adr990 Posted July 12, 2010 Share Posted July 12, 2010 Thanks for this. :)Â Good stuff, keep it up!This is really a need for most of the games people are willing to make IMO. Link to comment Share on other sites More sharing options...
Kimimaru Posted July 13, 2010 Author Share Posted July 13, 2010 No problem. I'm glad it's helping you out! Link to comment Share on other sites More sharing options...
pigboss Posted July 13, 2010 Share Posted July 13, 2010 Dude thanks man! Link to comment Share on other sites More sharing options...
Ertzel Posted July 13, 2010 Share Posted July 13, 2010 Hmmm…. I added all of the code and the bars show up right. But when I attack my NPC and he loses HP the bar doesn't go down with his HP. But if I log out and log back in when he has HP lost, then it shows up. Link to comment Share on other sites More sharing options...
Kimimaru Posted July 14, 2010 Author Share Posted July 14, 2010 Did you make sure that you've added in the part in the server that updates the NPC's HP? Link to comment Share on other sites More sharing options...
Ertzel Posted July 14, 2010 Share Posted July 14, 2010 oh shit lol, for some reason I forgot to put that in :P Link to comment Share on other sites More sharing options...
Zetasis Posted July 22, 2010 Share Posted July 22, 2010 For some reason I keep getting this error. I followed your tutorial step by step and it was easy to follow so I don't see how I messed this up. I'll attach a pic of the error I'm getting.Edit: Never Mind I got it. Thanks for the tutorial. Link to comment Share on other sites More sharing options...
Guest Posted August 6, 2010 Share Posted August 6, 2010 when i press Ctrl and F5 it sas Compile error: User defined type not defined and it shols DDS_Player() As DirectDrawSurface7 Link to comment Share on other sites More sharing options...
Robin Posted August 6, 2010 Share Posted August 6, 2010 Fairly sure it's DDS_Character() now. Link to comment Share on other sites More sharing options...
delgado88 Posted August 6, 2010 Share Posted August 6, 2010 when i compile the code i got this error ;/ 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