This is a tutorial for adding sprite changing items. "Costumes" add a little flare to your game. It's fun buying new "looks" in games. I know I said I'd write this a month ago, but I just did it this morning.
In modTypes find
Public Const ITEM_TYPE_SPELL = 13
Underneath that add:
Public Const ITEM_TYPE_COSTUME = 14
Now lets edit some stuff in frmItemEditor. Underneath this code:
If (cmbType.ListIndex = ITEM_TYPE_SPELL) Then fraSpell.Visible = True Else fraSpell.Visible = False End If
Add this code:
If (cmbType.ListIndex = ITEM_TYPE_COSTUME) Then fraSprite.Visible = True Else fraSprite.Visible = False End If
At the very bottom of the frmItemEditor code, add:
Private Sub scrlSprite_Change() lblSprite.Caption = STR(scrlSprite.Value) End Sub Private Sub tmrSprite_Timer() Call ItemEditorBltSprite End Sub
Now lets edit the actual form. Click the cmbType list box. Go to the "list" property, and at the bottom, right underneath spell, add "Costume". Now add a new frame. Name it "fraSprite". Inside fraSprite add a label called "label8" and set the caption to "Sprite". Now add a horizontal scroll bar named "scrlSprite". Add another label named "lblSprite" and set the caption to "0". Now add a picture called "picSprite". Autoredraw = false, Autoresize = false, borderstyle = none. Make the picture the same size as picPic (the picture at the top of the item editor). Add a timer named "tmrSprite" set the interval to 50 and make sure enabled = true. Now, add one more picture anywhere on frmItemEditor. Name it "picSprites". Set the visible = false, make autoredraw = true and autoresize = true. Now drag the fraSprite on top of fraSpells.
Now, lets go to modGameLogic. Underneath this code:
If (frmItemEditor.cmbType.ListIndex = ITEM_TYPE_SPELL) Then Item(EditorIndex).Data1 = frmItemEditor.scrlSpell.Value Item(EditorIndex).Data2 = 0 Item(EditorIndex).Data3 = 0 End If
Add this code:
If (frmItemEditor.cmbType.ListIndex = ITEM_TYPE_COSTUME) Then Item(EditorIndex).Data1 = frmItemEditor.scrlSprite.Value Item(EditorIndex).Data2 = 0 Item(EditorIndex).Data3 = 0 End If
Right under this code:
Public Sub ItemEditorBltItem() Call BitBlt(frmItemEditor.picPic.hdc, 0, 0, PIC_X, PIC_Y, frmItemEditor.picItems.hdc, 0, frmItemEditor.scrlPic.Value * PIC_Y, SRCCOPY) End Sub
Add this code:
Public Sub ItemEditorBltSprite() Call BitBlt(frmItemEditor.picSprite.hdc, 0, 0, PIC_X, PIC_Y, frmItemEditor.picSprites.hdc, 3 * PIC_X, frmItemEditor.scrlSprite.Value * PIC_Y, SRCCOPY) End Sub
Now, right under this code:
Call BitBlt(frmItemEditor.picPic.hdc, 0, 0, PIC_X, PIC_Y, frmItemEditor.picItems.hdc, 0, frmItemEditor.scrlPic.Value * PIC_Y, SRCCOPY)
Add this code:
frmItemEditor.picSprites.Picture = LoadPicture(App.Path & "\sprites.bmp")
That should do it for the client. Time to edit the server. In modTypes find
Public Const ITEM_TYPE_SPELL = 13
Underneath that add:
Public Const ITEM_TYPE_COSTUME = 14
Now lets go to modServerTCP. Underneath this code:
Case ITEM_TYPE_POTIONSUBSP Call SetPlayerSP(Index, GetPlayerSP(Index) - Item(Player(Index).Char(CharNum).Inv(InvNum).Num).Data1) Call TakeItem(Index, Player(Index).Char(CharNum).Inv(InvNum).Num, 0) Call SendSP(Index)
Add this code:
Case ITEM_TYPE_COSTUME n = Item(GetPlayerInvItemNum(Index, InvNum)).Data1 Call SetPlayerSprite(Index, n) Call TakeItem(Index, Player(Index).Char(CharNum).Inv(InvNum).Num, 0) Call SendPlayerData(Index)
That should be everything. If anyone has any errors, or if i've forgotten something in the tutorial, let me know and I'll edit it.[/img]
|