11-12-2006, 02:32 AM
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:
Under "' Maximum classes" stuff add this:
Sub GameLogic:
Under "Sub BltNpc" stuff add this new sub:
OBS: Change the 142 to the sprite you want.
modHandleData:
Sub HandleData:
Add this, you know where...
modGameLogic:
Sub GameLoop:
Add this under "' Blit out tiles layers ground/anim1/anim2" stuff:
Server side
modServerTCP:
Add this subs to the module:
modGameLogic:
Sub AttackNpc:
Under "Call SendDataToMap(MapNum, "NPCDEAD" & SEP_CHAR & MapNpcNum & SEP_CHAR & END_CHAR)" add:
Sub PlayerWarp:
Under "' Check if there is an npc on the map and say hello if so" stuff add:
Sub JoinGame:
Under "' Send the flag so they know they can start doing stuff" stuff add:
modGlobals:
Header:
Under "Public MapNpc(1 To MAX_MAPS, 1 To MAX_MAP_NPCS) As MapNpcRec" add this:
Under "' Maximum classes" stuff add this:
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:
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]](http://img228.imageshack.us/img228/897/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
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
Code:
Type DeadBodyRec
Blit As Boolean
Time As Long
X As Byte
Y As Byte
Timer As Byte
StartTimer As Byte
End Type
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
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)
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
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]](http://img228.imageshack.us/img228/897/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