[SOURCE] Text-Based RPG Battle Engine
About:
I was really into making my own RPG at some point, so I made a battle system then never got around to finishing the rest. So, here it is. Massive credits to Terrankiller for his RandomInt function.
What this does is player 1 clicks their turn button. A random number is picked between 1 and 10, and the opponent suffers that damage. Then, the opponent's button has to be clicked, then they do damage between 1 and 10 to the player. The first one to reach 0 HP loses.
WHAT YOU NEED
-Label (4)
1: name = playerhp
2: name = opphp
3: name = dmgplayer
4: name = dmgopp
-Command Button (2)
1: name = oppgo, enabled = false
2: name = playergo
-Timer (1)
1: name = tmrDmg
This is Terrankiller's RandomInt function. It randomly picks a number between Low and High. Add it into a module:
Now make a normal form and add this into it's code:
About:
I was really into making my own RPG at some point, so I made a battle system then never got around to finishing the rest. So, here it is. Massive credits to Terrankiller for his RandomInt function.
What this does is player 1 clicks their turn button. A random number is picked between 1 and 10, and the opponent suffers that damage. Then, the opponent's button has to be clicked, then they do damage between 1 and 10 to the player. The first one to reach 0 HP loses.
WHAT YOU NEED
-Label (4)
1: name = playerhp
2: name = opphp
3: name = dmgplayer
4: name = dmgopp
-Command Button (2)
1: name = oppgo, enabled = false
2: name = playergo
-Timer (1)
1: name = tmrDmg
This is Terrankiller's RandomInt function. It randomly picks a number between Low and High. Add it into a module:
Code:
'RandomInt Function by Terrankiller, http://www.terrankiller.com/
Public Function RandomInt(ByVal Low As Long, ByVal High As Long) As Long
Randomize: RandomInt = Int((High - Low + 1) * Rnd) + Low
End Function
Now make a normal form and add this into it's code:
Code:
Option Explicit
Dim oppdmg As Integer
Dim plrdmg As Integer
Private Sub Form_Load()
playerhp.Caption = 20
opphp.Caption = 20
End Sub
Private Sub oppgo_Click()
playerhp.Caption = playerhp.Caption - oppdmg
oppgo.Enabled = False
playergo.Enabled = True
dmgopp.Caption = oppdmg
If playerhp.Caption <= 0 Then
playerhp.Caption = "0"
MsgBox "You died.", vbCritical, ":("
Unload Me
End If
End Sub
Private Sub playergo_Click()
dmgplayer.Caption = plrdmg
opphp.Caption = opphp.Caption - plrdmg
playergo.Enabled = False
oppgo.Enabled = True
If opphp.Caption <= 0 Then
opphp.Caption = "0"
MsgBox "You won!", vbExclamation, ":)"
Unload Me
End If
End Sub
Private Sub tmrDmg_Timer()
oppdmg = RandomInt(1, 10)
plrdmg = RandomInt(1, 10)
End Sub














