Jump to content
Sign in to follow this  
satanttin

How do i make a battle system in MY game?

Recommended Posts

satanttin

Hello i'm trying to create a simple text game to teach myself autoit.

and i am wondering to to make a simple battle system.

i already got some stats like vitality, strength, dexterity and exp gain on each mob just well xD i feel newb:')

here is the code of the battle gui:

Func guibattle()
$GBattle = GUICreate("Battle", 518, 421, 192, 124)
$LMHP = GUICtrlCreateLabel("Health: "&$MobHP, 16, 104, 125, 17)
$BSelectMob = GUICtrlCreateButton("Select", 272, 40, 75, 25)
$LMSTR = GUICtrlCreateLabel("Strenght:"&$MobSTR, 16, 128, 125, 17)
$LMAGE = GUICtrlCreateLabel("Age:"&$MobAGE, 16, 152, 125, 17)
$CMobSelect = GUICtrlCreateCombo("001-rat", 24, 40, 241, 25)
GUICtrlSetData(-1, "002-goblin|003-orc|004-elf")
$Label1 = GUICtrlCreateLabel("Select monster:", 24, 24, 77, 17)
$BBattleMob = GUICtrlCreateButton("Battle", 432, 368, 81, 49)
$GMobStats = GUICtrlCreateGroup("Monster Stats", 8, 72, 417, 345)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$LMobEXP = GUICtrlCreateLabel("EXP:"&$MobEXP, 16, 176, 125, 17)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUICtrlSetOnEvent($BBattleMob, "Fight")
GUICtrlSetOnEvent($BSelectMob, "selectmob")
GUISetState()
EndFunc

and the function where i select the mob/data from .ini:

Func selectmob()
$Fight = GUICtrlRead ($CMobSelect)
$MobHP = IniRead(@scriptdir & "\" & "Mobs.ini", $Fight, "Health","Error")
$MobSTR = IniRead(@scriptdir & "\" & "Mobs.ini", $Fight, "Strength","Error")
$MobAGE = IniRead(@scriptdir & "\" & "Mobs.ini", $Fight, "Age","Error")
$MobEXP = IniRead(@scriptdir & "\" & "Mobs.ini", $Fight, "Exp","Error")
MsgBox (0, "title", "u selected "&$Fight)
GUIDelete ($GBattle)
guibattle()
EndFunc

that part works as intented. just now i would like to when i press battle i battle the selected monster. meaning each point in str gives 1 dmg and dex gives 1% dodge per point. vit gives 10 health per point i added that just for the rest i didn't do yet because of not knowing how i can make the battle system. can someone please give me tips like first make a damage variable where $dmg = $str*1 or something cause i am just lost. and i can figure out when u defeat it to gives exp so that's fine.

Hop that this post is clear and u can follow it otherwise just ask me anything u like to know and i discribe it better.

Greetz

Edited by satanttin

Share this post


Link to post
Share on other sites
satanttin

I'm trying to calculate how many hits u need to kill a creature. then i try to calculate how many times he hits me.

and then i know if i win the battle yes or no.

just don't know how to begin:( btw i deleted the dex stat because that's way too hard for now so might do that when everything else works.

Share this post


Link to post
Share on other sites
satanttin

How to you define when you are damaged?

how do you define when opponent is damaged?

i'm sorry what do you mean?

what i mean is when my dmg/health is better than the selected monster i get exp otherwise i get a message with u died or some kind.

Share this post


Link to post
Share on other sites
satanttin

This is what i come up with just gave me an error "F:codingtest.au3 (113) : ==> Error in expression.:"

can someone tell me what i did wrong here?

Func Fight()
If $Health/$DMG ==> $MobHP/$MobDMG Then
$EXP = $EXP+$MobEXP
Else
MsgBox (0, "Lose", "U lost against "&$Fight)
EndIf
save()
GUIDelete ($GBattle)
guibattle()
EndFunc

Share this post


Link to post
Share on other sites
kaotkbliss

Here's how I would start the battle system (perhaps evolving/improving it later)

I would work on a percent system as it is easy to calculate.

You and monster would have a base % score to hit, say 50% chance to hit or miss

Then you would use Random() to get a random number between 1-100.

If Random > or = 50%, then you hit.

Now you could add modifiers in there say for Dex. Maybe something like each point in dex gives you +5% to hit

So you would do Random() + Dex*5

or you could work it the oposite way where their dex lowers your chance

Random() - monster Dex*5

So you have Random() > 50%

you could do Vitality -= (Base Dmg + Str)

if Vitality <= 0 you died


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites
satanttin

What does "==>" mean?

it suppose to be if that is larger than just don't know what i should put there to make it work like that:(

Share this post


Link to post
Share on other sites
satanttin

Here's how I would start the battle system (perhaps evolving/improving it later)

I would work on a percent system as it is easy to calculate.

You and monster would have a base % score to hit, say 50% chance to hit or miss

Then you would use Random() to get a random number between 1-100.

If Random > or = 50%, then you hit.

Now you could add modifiers in there say for Dex. Maybe something like each point in dex gives you +5% to hit

So you would do Random() + Dex*5

or you could work it the oposite way where their dex lowers your chance

Random() - monster Dex*5

So you have Random() > 50%

you could do Vitality -= (Base Dmg + Str)

if Vitality <= 0 you died

seems okay just bit complicated and well if i know how this works it will work good enough for my battle system :P for this game that is:)

but thanks for the reply ^^

Share this post


Link to post
Share on other sites
careca

What does "==>" mean?

hmm... strings are equal or bigger than... LOL

satanttin: search in the help file for "operators"

There's a list of them, might help.

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
MattTheHuman

First you gotta decide how complex you wanna go on the script.

A simple example of the way I would do this is:

Opt("GUIResizeMode", 802)
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
Global $Main = GUICreate("Player Battle", 125, 80)
Global $Turn = GUICtrlCreateButton("Turn", 35, 50, 50, 25)
Global $Player = GUICtrlCreateLabel("Player", 10, 10, 50, 17)
Global $PlayerHP = GUICtrlCreateLabel("HP:", 10, 27, 20, 17)
Global $PlayerHPDisplay = GUICtrlCreateLabel("", 30, 27, 20, 17)
Global $Monster = GUICtrlCreateLabel("Monster", 60, 10, 50, 17, $SS_RIGHT)
Global $MonsterHP = GUICtrlCreateLabel("HP:", 70, 27, 20, 17, $SS_RIGHT)
Global $MonsterHPDisplay = GUICtrlCreateLabel("", 90, 27, 15, 17, $SS_RIGHT)
Global $Winner = GUICtrlCreateLabel("Winner!", 0, 53, 125, 17, $SS_CENTER)
GUICtrlSetState(-1, $GUI_HIDE)
Global $Loser = GUICtrlCreateLabel("Loser!", 0, 53, 125, 17, $SS_CENTER)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

; Player Variables.
$playerStr = 15
$playerHealth = $playerStr*2
$playerAttackLower = 3
$playerAttackHigher = 5
$playerDefenceLower = 1
$playerDefenceHigher = 3

; Monster Variables.
$monsterStr = 10
$monsterHealth = $monsterStr*2
$monsterAttackLower = 2
$monsterAttackHigher = 4
$monsterDefenceLower = 1
$monsterDefenceHigher = 3

; Setting the labels.
GUICtrlSetData($PlayerHPDisplay, $playerHealth)
GUICtrlSetData($MonsterHPDisplay, $monsterHealth)

Func PlayerAttack()
    $dmg = (Random($playerAttackLower, $playerAttackHigher, 1) - Random($monsterDefenceLower, $monsterDefenceHigher, 1))
    if $dmg <= 0 then
       MsgBox(0, "Player", "Player did no damage.")
       Return 0
       Exit
    Else
       MsgBox(0, "Player", "Player hits for " & $dmg & " damage.")
       $monsterHealth = $monsterHealth - $dmg
       GUICtrlSetData($MonsterHPDisplay, $monsterHealth)
    EndIf
 EndFunc

 Func MonsterAttack()
    $dmg = (Random($monsterAttackLower, $monsterAttackHigher, 1) - Random($playerDefenceLower, $playerDefenceHigher, 1))
    if $dmg <= 0 Then
       MsgBox(0, "Monster", "Monster did no damage.")
       Return 0
       Exit
    Else
       MsgBox(0, "Monster", "Monster hits for " & $dmg & " damage.")
       $playerHealth = $playerHealth - $dmg
       GUICtrlSetData($PlayerHPDisplay, $playerHealth)
    EndIf
 EndFunc

 Func Battle()
    ; Player attacks first.
    PlayerAttack()
    MonsterAttack()
    If $playerHealth <= 0 Then
       MsgBox(0, "Game Over", "You died. Game Over.")
       GUICtrlSetState($Turn, $GUI_HIDE)
       GUICtrlSetState($Loser, $GUI_SHOW)
    EndIf
    If $monsterHealth <= 0 Then
       MsgBox(0, "Congrats", "You won. Congratulations.")
       GUICtrlSetState($Turn, $GUI_HIDE)
       GUICtrlSetState($Winner, $GUI_SHOW)
    EndIf
 EndFunc

 While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Turn
            Battle()

    EndSwitch
WEnd

I say its simple cause its not including all the fancy Dex and other factors you could include in such a game. Feel free to use the code and change anything you would want to. If you need help understanding any of it feel free to reply. Hope it helped.

Edited by MattTheHuman

Share this post


Link to post
Share on other sites
satanttin

First you gotta decide how complex you wanna go on the script.

A simple example of the way I would do this is:

Opt("GUIResizeMode", 802)
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
Global $Main = GUICreate("Player Battle", 125, 80)
Global $Turn = GUICtrlCreateButton("Turn", 35, 50, 50, 25)
Global $Player = GUICtrlCreateLabel("Player", 10, 10, 50, 17)
Global $PlayerHP = GUICtrlCreateLabel("HP:", 10, 27, 20, 17)
Global $PlayerHPDisplay = GUICtrlCreateLabel("", 30, 27, 20, 17)
Global $Monster = GUICtrlCreateLabel("Monster", 60, 10, 50, 17, $SS_RIGHT)
Global $MonsterHP = GUICtrlCreateLabel("HP:", 70, 27, 20, 17, $SS_RIGHT)
Global $MonsterHPDisplay = GUICtrlCreateLabel("", 90, 27, 15, 17, $SS_RIGHT)
Global $Winner = GUICtrlCreateLabel("Winner!", 0, 53, 125, 17, $SS_CENTER)
GUICtrlSetState(-1, $GUI_HIDE)
Global $Loser = GUICtrlCreateLabel("Loser!", 0, 53, 125, 17, $SS_CENTER)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

; Player Variables.
$playerStr = 15
$playerHealth = $playerStr*2
$playerAttackLower = 3
$playerAttackHigher = 5
$playerDefenceLower = 1
$playerDefenceHigher = 3

; Monster Variables.
$monsterStr = 10
$monsterHealth = $monsterStr*2
$monsterAttackLower = 2
$monsterAttackHigher = 4
$monsterDefenceLower = 1
$monsterDefenceHigher = 3

; Setting the labels.
GUICtrlSetData($PlayerHPDisplay, $playerHealth)
GUICtrlSetData($MonsterHPDisplay, $monsterHealth)

Func PlayerAttack()
$dmg = (Random($playerAttackLower, $playerAttackHigher, 1) - Random($monsterDefenceLower, $monsterDefenceHigher, 1))
if $dmg <= 0 then
MsgBox(0, "Player", "Player did no damage.")
Return 0
Exit
Else
MsgBox(0, "Player", "Player hits for " & $dmg & " damage.")
$monsterHealth = $monsterHealth - $dmg
GUICtrlSetData($MonsterHPDisplay, $monsterHealth)
EndIf
EndFunc

Func MonsterAttack()
$dmg = (Random($monsterAttackLower, $monsterAttackHigher, 1) - Random($playerDefenceLower, $playerDefenceHigher, 1))
if $dmg <= 0 Then
MsgBox(0, "Monster", "Monster did no damage.")
Return 0
Exit
Else
MsgBox(0, "Monster", "Monster hits for " & $dmg & " damage.")
$playerHealth = $playerHealth - $dmg
GUICtrlSetData($PlayerHPDisplay, $playerHealth)
EndIf
EndFunc

Func Battle()
; Player attacks first.
PlayerAttack()
MonsterAttack()
If $playerHealth <= 0 Then
MsgBox(0, "Game Over", "You died. Game Over.")
GUICtrlSetState($Turn, $GUI_HIDE)
GUICtrlSetState($Loser, $GUI_SHOW)
EndIf
If $monsterHealth <= 0 Then
MsgBox(0, "Congrats", "You won. Congratulations.")
GUICtrlSetState($Turn, $GUI_HIDE)
GUICtrlSetState($Winner, $GUI_SHOW)
EndIf
EndFunc

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Turn
Battle()

EndSwitch
WEnd

I say its simple cause its not including all the fancy Dex and other factors you could include in such a game. Feel free to use the code and change anything you would want to. If you need help understanding any of it feel free to reply. Hope it helped.

tested this script and ghehe that's nice^^ just i wanted a simple battle system that just calculates if u win or don't win:P so the script will be not that long and stuff O.o and not that complicated:P still thank for the scipt^^ and might do something like that later on if my idea failed.

hmm... strings are equal or bigger than... LOL

satanttin: search in the help file for "operators"

There's a list of them, might help.

yeah i looked that up just when i did
If $BattleP >= $BattleM Then
$EXP = $EXP+$MobEXP
Else
MsgBox (0, "Lose", "U lost against "&$Fight)
EndIf

it didn't worked i tried >= and > even < and <= xD i just feel so lame right now:O

Share this post


Link to post
Share on other sites
MattTheHuman

Feel free to use as much or as little of that script you like. I'll be honest, I had fun writing it :) If theres anything else I can help with feel free to let me know.

Share this post


Link to post
Share on other sites
satanttin

Feel free to use as much or as little of that script you like. I'll be honest, I had fun writing it :) If theres anything else I can help with feel free to let me know.

good to hear u liked writing it^^ and seems like a nice script to me ^^

and thanks :)

Share this post


Link to post
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
Sign in to follow this  

×