Difficulity : Medium 3/5
Well, I'm actually in a good mood today so I'm going to explain how to add pets. Now enjoy this because me giving tutorials on anything is rare. :wink: I don't usually give anything from my game but I actually removed this because I was too lazy to make animations when the player turns direction (you'll see when you use it)
Now first off, here is bltPet. Add this below bltplayer clientside.
Sub BltPet(ByVal Index As Long) Dim Anim As Byte Dim x As Long, y As Long ' Check for animation Anim = 0 If Player(Index).Attacking = 0 Then Select Case GetPlayerDir(Index) Case DIR_UP If (Player(Index).YOffset < PIC_Y / 2) Then Anim = 1 Case DIR_DOWN If (Player(Index).YOffset < PIC_Y / 2 * -1) Then Anim = 1 Case DIR_LEFT If (Player(Index).XOffset < PIC_Y / 2) Then Anim = 1 Case DIR_RIGHT If (Player(Index).XOffset < PIC_Y / 2 * -1) Then Anim = 1 End Select Else If Player(Index).AttackTimer + 500 > GetTickCount Then Anim = 2 End If End If ' Check to see if we want to stop making him attack If Player(Index).AttackTimer + 1000 < GetTickCount Then Player(Index).Attacking = 0 Player(Index).AttackTimer = 0 End If 'was getplayerpet instead of sprite rec.Top = GetPlayerPet(Index) * PIC_Y 'Scrolls to the sprite down the list (Sprite # * 32) and + 32? that's wrong rec.Bottom = rec.Top + PIC_Y 'this is the sprite # (rec.top) + pic Y which would be the 1st 32x32 box. +32 is wrong rec.Left = (GetPlayerDir(Index) * 3 + Anim) * PIC_X 'the direction * 3 + whatever anim. If anim = 2 then show 3rd sprite in dir left section, etc rec.Right = rec.Left + PIC_X 'left just the next side which is right again NO +32
'-------------this is the only section we need to edit for pet location in relation to player-------------------
Select Case GetPlayerDir(Index) '25 was 32 Case DIR_UP x = GetPlayerX(Index) * PIC_X + Player(Index).XOffset y = GetPlayerY(Index) * PIC_Y + 18 + Player(Index).YOffset - 4 Case DIR_DOWN x = GetPlayerX(Index) * PIC_X + Player(Index).XOffset y = GetPlayerY(Index) * PIC_Y - 28 + Player(Index).YOffset - 4 Case DIR_LEFT x = GetPlayerX(Index) * PIC_X + 25 + Player(Index).XOffset y = GetPlayerY(Index) * PIC_Y + Player(Index).YOffset - 4 Case DIR_RIGHT x = GetPlayerX(Index) * PIC_X - 25 + Player(Index).XOffset y = GetPlayerY(Index) * PIC_Y + Player(Index).YOffset - 4 End Select
'Removed blt and kept bltfast Call DD_BackBuffer.BltFast(x, y, DD_SpriteSurf, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY) End Sub
Replace blt out players section in the gameloop clientside with this:
' Blit out players For I = 1 To MAX_PLAYERS If IsPlaying(I) And GetPlayerMap(I) = GetPlayerMap(MyIndex) Then Call BltPlayer(I)
If GetPlayerPet(I) > 0 Then Call BltPet(I) End If End If Next I
Add at the bottom of modTypes:
Function GetPlayerPet(ByVal Index As Long) As Long GetPlayerPet = Player(Index).Pet End Function Sub SetPlayerPet(ByVal Index As Long, ByVal Pet As Long) Player(Index).Pet = Pet End Sub
In the packet "playerdata" in modClientTCP add:
Call SetPlayerPet(I, Val(Parse(Whatever the next # is)))
Now you'd have to add in playerrec Pet as integer. (Both sides of course) and have that save to the account folder (All that good stuff. Just copy everything for .sprite for players everywhere such as packets, saveplayer, etc)
Now onto the commands!
Clientside: (In one of the admin access levels)
' Giving a pet If LCase(Mid(MyText, 1, 4)) = "/pet" Then I = Val(Mid(MyText, 6, 3)) MyText = Mid(MyText, 10, Len(MyText) - 9) Call SendSetPet(MyText, I) MyText = "" Exit Sub End If
Bottom of modClientTCP
Sub SendSetPet(ByVal Name As String, ByVal Pet As Long) Dim Packet As String
Packet = "SETPET" & SEP_CHAR & Name & SEP_CHAR & Pet & SEP_CHAR & END_CHAR Call SendData(Packet) End Sub
Now onto serverside...
Put somewhere in the HandleData sub in modServerTCP
' ::::::::::::::::::::::: ' :: Pet Packet :: ' ::::::::::::::::::::::: If LCase(Parse(0)) = "setpet" Then N = FindPlayer(Parse(1)) T = Val(Parse(2)) Call SetPlayerPet(N, T) Call SendPlayerData(index) Exit Sub End If
Then add at the bottom of modTypes:
Function GetPlayerPet(ByVal index As Long) As Long GetPlayerPet = Player(index).Char(Player(index).CharNum).Pet End Function
Sub SetPlayerPet(ByVal index As Long, ByVal Pet As Long) Player(index).Char(Player(index).CharNum).Pet = Pet End Sub
This is pretty much it (I think. I may have left some stuff out but it shouldn't be too hard to figure out) Now the rest you will have to do yourself (the changing direction animation, blocking the pet from being walked under, etc) Hope this helped a few people. And if there's any questions, feel free to ask. :)
|