Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dead Bodies
#1
I think nobody never posted a tut like this. This is my way to do it. I made it a long ago and I decided to post it here to share it w/ you guys.

Author: Dragoons Master
Difficulty: 2/5 (Copy/Paste Tut/Understand)

That's what you should do, first Client side.

modGlobals:
Header:
Under "Public MapNpc(1 To MAX_MAP_NPCS) As MapNpcRec" add this:
Code:
Public MapNpcDBody(1 To MAX_MAPS, 1 To MAX_MAP_NPCS) As DeadBodyRec
Under "' Maximum classes" stuff add this:
Code:
Type DeadBodyRec
    Blit As Boolean
    Time As Long
    X As Byte
    Y As Byte
    Timer As Byte
    StartTimer As Byte
End Type
Sub GameLogic:
Under "Sub BltNpc" stuff add this new sub:
Code:
Sub BltNpcDBody(ByVal MapNpcNum As Long)
Dim X As Long, Y As Long
Dim i As Long
    ' Check to see if we want to stop making him attack
    Dim DBMap As Integer
    For i = 1 To MAX_MAPS
        If MapNpcDBody(i, MapNpcNum).Blit = True Then
            If MapNpcDBody(i, MapNpcNum).Time + 20000 - (MapNpcDBody(i, MapNpcNum).StartTimer * 1250) < GetTickCount Then
                MapNpcDBody(i, MapNpcNum).Blit = False
                MapNpcDBody(i, MapNpcNum).Time = 0
                MapNpcDBody(i, MapNpcNum).X = 0
                MapNpcDBody(i, MapNpcNum).Y = 0
                MapNpcDBody(i, MapNpcNum).Timer = 0
            End If
            
            If MapNpcDBody(i, MapNpcNum).Time + ((MapNpcDBody(i, MapNpcNum).Timer + 1) * 1250) < GetTickCount Then
                MapNpcDBody(i, MapNpcNum).Timer = MapNpcDBody(i, MapNpcNum).Timer + 1
            End If
        End If
    Next i
    If GetPlayerMap(MyIndex) = 0 Then Exit Sub
    DBMap = GetPlayerMap(MyIndex)
    
    rec.Top = 142 * PIC_Y 'I use 142 as a sprite in the spritesurf, use any number you want.
    rec.Bottom = rec.Top + PIC_Y
    rec.Left = (MapNpcDBody(DBMap, MapNpcNum).Timer + MapNpcDBody(DBMap, MapNpcNum).StartTimer) * PIC_X
    rec.RIGHT = rec.Left + PIC_X
    
    X = MapNpcDBody(DBMap, MapNpcNum).X * PIC_X
    Y = MapNpcDBody(DBMap, MapNpcNum).Y * PIC_Y
    
    ' Check if its out of bounds because of the offset
    If Y < 0 Then
        Y = 0
        rec.Top = rec.Top + (Y * -1)
    End If
    If MapNpcDBody(DBMap, MapNpcNum).Blit = True Then
        Call DD_BackBuffer.BltFast(X, Y, DD_SpriteSurf, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
    End If
End Sub
OBS: Change the 142 to the sprite you want.

modHandleData:
Sub HandleData:
Add this, you know where...
Code:
' ::::::::::::::::::::::::::
    ' :: Npc Dead Body Packet ::
    ' ::::::::::::::::::::::::::
    If LCase(Parse(0)) = "npcbody" Then
        MapNpcDBody(Val(Parse(4)), Val(Parse(1))).Blit = True
        MapNpcDBody(Val(Parse(4)), Val(Parse(1))).X = Val(Parse(2))
        MapNpcDBody(Val(Parse(4)), Val(Parse(1))).Y = Val(Parse(3))
        MapNpcDBody(Val(Parse(4)), Val(Parse(1))).StartTimer = Val(Parse(5))
        MapNpcDBody(Val(Parse(4)), Val(Parse(1))).Timer = 0
        MapNpcDBody(Val(Parse(4)), Val(Parse(1))).Time = GetTickCount
        Exit Sub
    End If

modGameLogic:
Sub GameLoop:
Add this under "' Blit out tiles layers ground/anim1/anim2" stuff:
Code:
' Blit out the npcs dead body
            For i = 1 To MAX_MAP_NPCS
                Call BltNpcDBody(i)
            Next i


Server side
modServerTCP:
Add this subs to the module:
Code:
Sub SendNDeadBodyToMap(ByVal MapNum As Long, ByVal MapNpcNum As Long)
Dim Packet As String
    
    Packet = Chr(235) & SEP_CHAR & MapNpcNum & SEP_CHAR & MapNpc(MapNum, MapNpcNum).X & SEP_CHAR & MapNpc(MapNum, MapNpcNum).Y & SEP_CHAR & MapNum & SEP_CHAR & MapNpcDBody(MapNum, MapNpcNum).Timer & END_CHAR
    Call SendDataToMap(MapNum, Packet)
End Sub

Sub SendDBodiesLogin(ByVal Index As Long)
Dim I As Long
Dim J As Long
    
    For I = 1 To MAX_MAPS
        For J = 1 To MAX_MAP_NPCS
            If MapNpcDBody(I, J).Blit = True Then
                Call SendNDeadBodyTo(Index, I, J)
            End If
        Next J
    Next I
End Sub

Sub SendDBodiesMap(ByVal Index As Long)
Dim J As Long
Dim PlayerMap As Long
    PlayerMap = GetPlayerMap(Index)
    If PlayerMap  MAX_MAPS Then Exit Sub
    For J = 1 To MAX_MAP_NPCS
        If MapNpcDBody(PlayerMap, J).Blit = True Then
            Call SendNDeadBodyTo(Index, PlayerMap, J)
        End If
    Next J
End Sub

modGameLogic:
Sub AttackNpc:
Under "Call SendDataToMap(MapNum, "NPCDEAD" & SEP_CHAR & MapNpcNum & SEP_CHAR & END_CHAR)" add:
Code:
MapNpcDBody(MapNum, MapNpcNum).Blit = True
        MapNpcDBody(MapNum, MapNpcNum).Time = GetTickCount
        MapNpcDBody(MapNum, MapNpcNum).Timer = 0
        Call SendNDeadBodyToMap(MapNum, MapNpcNum)
Sub PlayerWarp:
Under "' Check if there is an npc on the map and say hello if so" stuff add:
Code:
Call SendDBodiesMap(Index)

Sub JoinGame:
Under "' Send the flag so they know they can start doing stuff" stuff add:
Code:
Call SendDBodiesLogin(Index)

modGlobals:
Header:
Under "Public MapNpc(1 To MAX_MAPS, 1 To MAX_MAP_NPCS) As MapNpcRec" add this:
Code:
Public MapNpcDBody(1 To MAX_MAPS, 1 To MAX_MAP_NPCS) As DeadBodyRec
Under "' Maximum classes" stuff add this:
Code:
Type DeadBodyRec
    Blit As Boolean
    Time As Long
    X As Byte
    Y As Byte
    Timer As Byte
    StartTimer As Byte
End Type

modGeneral:
Sub GameAI:
Find "' // This is used for checking if an NPC is dead or not //" and you will see that it is totaly quoted. Keep it like that, don't edit it, only add this piece of code under that stuff:
Code:
For x = 1 To MAX_MAP_NPCS
                    If MapNpcDBody(y, x).Blit = True Then
                        If MapNpcDBody(y, x).Time + 20000 < TickCount Then
                            MapNpcDBody(y, x).Blit = False
                            MapNpcDBody(y, x).Time = 0
                            MapNpcDBody(y, x).x = 0
                            MapNpcDBody(y, x).y = 0
                            MapNpcDBody(y, x).Timer = 0
                        End If
                        
                        If MapNpcDBody(y, x).Time + ((MapNpcDBody(y, x).Timer + 1) * 1250) < TickCount Then
                            MapNpcDBody(y, x).Timer = MapNpcDBody(y, x).Timer + 1
                        End If
                    End If
                Next x

I think that's all, maybe I forgot something. Someone plx test and see if it works ^^

EDIT: here is an example of a blood img, like a body.
[Image: bloodoc7.png]
PLX DON'T USE THIS ONE IT IS A CUSTOM ONE, MADE BY MY PIXEL ARTIST!

EDIT2:
Just fixed the wrong missing subs. They shouldn't be there xD
Reply
#2
lol woah this is awesome! lol nice dude, im adding this right now to my game, ill tell you if i get any errors Big Grin
hey btw does the animation stay there? or once its done moving does it dissapear?
Reply
#3
Congrats on the tutorial.
Reply
#4
It's missing a couple subs.

PlayerDBody
SendPDeadBodyToMap
SendNDeadBodyToMap

I could be wrong. I didn't try hardly any debugging.
Reply
#5
Sonire Wrote:It's missing a couple subs.

PlayerDBody
SendPDeadBodyToMap
SendNDeadBodyToMap

I could be wrong. I didn't try hardly any debugging.
Sry guys, I realy did a few things wrong. I have players dead body too, but this is not a tut for players and yes for npc, so I removed the player part. Shouldn't be hard to change that =P
Sry about that but now it is fully working.
Reply
#6
Now this is a tutorial to die for... Get it? lol.
Reply
#7
Bad joke Wink

Nice tute man very nice Smile
Reply
#8
Tnx all you guys ^^ It's a nice stuff to add to your game, or the idea it selfs.
Btw, this is the tut I'm posting for the contest ok? I'm not sure if the contest still up but if it does, this is my tutorial for it ^^
Reply
#9
SORRY FOR THE NECROPOST :S...But, how I do to set the body's image?
Reply
#10
Client side, at Sub BltNpcDBody, change the 142 the sprite number...
Code:
rec.Top = 142 * PIC_Y 'I use 142 as a sprite in the spritesurf, use any number you want.
Reply
#11
Missing Sub

Code:
SendNDeadBodyTo
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)