Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[EO] Mystery Boxes!


Golf
 Share

Recommended Posts

Mystery Box System 1.0

At the end of tutorial it should look like this:

![](http://i.imgur.com/jjOc0MW.png)

**Client side**

In frmEditor_Item add new frame fraBox and in that frame add label lblBox and scrollbar scrlBox

It should look like this

![](http://i.imgur.com/nCvDCUg.png)

In scrlBox code add:

```
If EditorIndex < 1 Or EditorIndex > MAX_ITEMS Then Exit Sub
lblBox.Caption = "Box: " & scrlBox.value
item(EditorIndex).CBoxNumber = scrlBox.value
Exit Sub

```
Now in cmbType List at the end add "Box"

In modConstants add:

```
Public Const ITEM_TYPE_BOX As Byte = 9

```
In modEnumerations add:

```
SMysteryBox

```
In modGameEditors in sub ItemInit before End With add

```
'Box
If (frmEditor_Item.cmbType.ListIndex = ITEM_TYPE_BOX) Then
frmEditor_Item.fraBox.Visible = True
frmEditor_Item.scrlBox.value = .CBoxNumber
Else
frmEditor_Item.fraBox.Visible = False
End If

```
In modHandleData in sub InitMessages add:

```
HandleDataSub(SMysteryBox) = GetAddress(AddressOf HandleMysteryBox)

```
In same module add:

```
Private Sub HandleMysteryBox(ByVal Index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
Dim Buffer As clsBuffer
Dim itemnumber As Byte
Dim value As String
Set Buffer = New clsBuffer
Buffer.WriteBytes Data()
itemnumber = Buffer.ReadLong
value = Buffer.ReadString
OpenMystery itemnumber, value
End Sub

```
Create new module and name it modMysteryBox and add in it :

```
Public Sub OpenMystery(ByVal itemnum As Integer, ByVal value As String)
Dim itempic As Long
itempic = item(itemnum).Pic
frmMysteryBox.Show
frmMysteryBox.lblItemName.Caption = value & " " & item(itemnum).Name
End Sub

```
In ModGeneral in sub LoadGUI add:

```
frmMysteryBox.Picture = LoadPicture(App.Path & "\data files\graphics\gui\main_mystery.bmp")

```
In modTypes in Type ItemRec add:

```
CBoxNumber As Byte

```
**SERVER SIDE**

Create new module and name it modBox and in it add:

```
Public Sub OpenMystery(index As Long, caseID As Long)
Dim n As Byte
Select Case caseID
Case "0"
PlayerMsg index, "I feel lucky today!", White
PlayerMsg index, "You've obtained Nothing", Red
SendPlayerData index
Case "1"
PlayerMsg index, "I feel lucky today!", White
n = Random(0, 20)
If (n < 1) Then
Call GiveInvItem(index, 1, 100000, True)
PlayerMsg index, "You've obtained 100k $", Red
SendMysteryBox index, 1, "100k"
ElseIf (n < 5) Then
Call GiveInvItem(index, 1, 1000000, True)
PlayerMsg index, "You've obtained 1M $", Red
SendMysteryBox index, 1, "1 Million"
Else
Call GiveInvItem(index, 1, 1, True)
PlayerMsg index, "You've obtained 1$", Red
SendMysteryBox index, 1, "1"
SendPlayerData index
End If

Case Else

End Select
End Sub

```
In modConstants add:

```
Public Const ITEM_TYPE_BOX As Byte = 9

```
In modEnumerations add:

```
SMysteryBox

```
In modServerTcp add :

```
Public Sub SendMysteryBox(ByVal index As Long, ByVal itemnum As Long, ByVal Value As String)
SendActionMsg GetPlayerMap(index), "I just won " & Value & " " & Item(itemnum).Name, Pink, ACTIONMSG_SCROLL, GetPlayerX(index) * 32, GetPlayerY(index) * 32
Dim Buffer As clsBuffer
Set Buffer = New clsBuffer

Buffer.WriteLong SMysteryBox
Buffer.WriteLong itemnum
Buffer.WriteString Value
SendDataTo index, Buffer.ToArray

Set Buffer = Nothing
End Sub

```
In modPlayer in sub UseItem before End Select add:

```
Case ITEM_TYPE_BOX
'get box number
n = Item(itemnum).CBoxNumber
Call OpenMystery(index, n)
Call TakeInvItem(index, itemnum, 1)

```
In modTypes in Type ItemRec add

```
CBoxNumber As Byte

```
Now you are DONE!

**Without this system wont work!**

**Download files [here](https://www.mediafire.com/?agukh66lbf1xxgx).**

**Paste main_mystery.bmp in data files\graphics\GUI**

**Inside client source in folder Forms  open  frmMysteryBox . Also paste frmMysteryBox in src folder.**
Link to comment
Share on other sites

Update:

Server side:

In modServerTCP in sub SendMysteryBox.

At the top of sub add :

```
SendActionMsg GetPlayerMap(index), "I just won " & Value & " " & Item(itemnum).Name, Pink, ACTIONMSG_SCROLL, GetPlayerX(index) * 32, GetPlayerY(index) * 32

```
Link to comment
Share on other sites

Nice work. I read through the code but I found that this only rewards the player with the first item. Why not expand on this idea? Like the game maker can decide which item(s) to give, how many of those items to give, check for inventory space before giving the item and stuff.
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...