Jump to content

Inventory system and mining mini-game


Darth
 Share

Recommended Posts

First, yes the ores are from runescape.

Just showing the betas of the inventory system and mining minigame I'll be using for the RPG I'm working on.

the way the minigame works is, a tooltip will pop up with a letter and you need to press it before it disapears. do it a certain amount of times and you have a 50% chance of mining your selected ore. so far all you can do with the ores is sell them to the shop, but smelting and smithing will be added. also closing windows doesn't work yet, but it's not a top priorety at the moment so just exit from the tray icon. finally, a bunch of stuff is stored in an ini file incase you're wondering why one randomly appears.

comments and criticisms apretiatied

#include <GUIConstants.au3>
#include<array.au3>

$count = 0
$bob = 0
$char = 0
$minexp = IniRead("Player.ini","XP","mineXP",0)
$minelvl = IniRead("Player.ini","Stats","mineLevel",1)
$minetime = 0


$test = 15
$price = 7
$edit = 0
$g = 0
$shop = 0
$GS = 0
$PSI = 0
$PS = 0
$BI = 0
$buy = 0
$SI = 0
$sell = 0

Func Item_Read($Item)
    IniRead("Player.ini","Items",$Item,0)
EndFunc
Func Item_Write($Item)
    $Find = _ArraySearch($Items,$Item)
IniWrite("Player.ini","Items",$Items[$find],$playerstock[$find])
EndFunc

Dim $Items[10] = ["Copper","Tin","Iron","Silver","Coal","Gold","Mithril","Adamant","Runite","Potion"]
Dim $price[10] = [10,10,25,50,60,100,200,250,500,99]
Dim $shopstock[10] = [0,40,100,85,70,2,45,0,2,$test]
Dim $playerstock[10] = [Item_Read("Copper"),Item_Read("Tin"),Item_Read("Iron"),Item_Read("Silver"),Item_Read("Coal"),Item_Read("Gold"),Item_Read("Mithril"),Item_Read("Adamant"),Item_Read("Runite"),Item_Read("Potion")]


$pgold = 1000
$sgold = 200000


func bob()
    minetime()
    $bob = 1
    $count = 0
    While($bob=1)
        $char = Chr(Random(65,90,1))
        HotKeySet(chr(Asc($char)+32),"mine")
        ToolTip($char,Random(100,(@desktopwidth-100),1),random(100,(@desktopheight-100),1))
        sleep(2000)
        HotKeySet((chr(Asc($char)+32)))
        ToolTip("")
    WEnd
EndFunc

Func mine()
    HotKeySet((chr(Asc($char)+32)))
    ToolTip("")
    $count = $count + 1
    If $count >= $minetime Then
        $rand = random(1,10,1)
        If $rand > 5 Then
            orecheck()
            If $minexp >= (83 * 1.1^($minelvl-1)) Then
                $minexp = 0
                $minelvl = $minelvl + 1
                msgbox(0,"Level up", "Congratulations, you have reached level " & $minelvl &".")
                minecheck()
            EndIf
            $count = 0
            $bob = 0
        Else
            MsgBox(0,"","You failed to mine anything.")
            $count = 0
            $bob = 0
        EndIf   
    EndIf

    GUICtrlSetData($mxp,"Mining Xp: " & $minexp)
    GUICtrlSetData($mlvl,"Mining Level: " & $minelvl)
    save()
EndFunc
        
Opt("GUIOnEventMode", 1)    
GUICreate("",100,280)
$1 = GUICtrlCreateRadio("Tin ",5,5)
$2 = GUICtrlCreateRadio("Copper ",5,25)
$3 = GUICtrlCreateRadio("Iron ",5,45)
$4 = GUICtrlCreateRadio("Silver ",5,65)
$5 = GUICtrlCreateRadio("Coal ",5,85)
$6 = GUICtrlCreateRadio("Gold ",5,105)
$7 = GUICtrlCreateRadio("Mithril ",5,125)
$8 = GUICtrlCreateRadio("Adamant ",5,145)
$9 = GUICtrlCreateRadio("Runite ",5,165)

$invo = GUICtrlCreateButton("Inventory",5,185,50,15)
$shope = GUICtrlCreateButton("Shope",5,205,50,15)
$mine = GUICtrlCreateButton("Mine",5,225,50,15)
$mxp = GUICtrlCreateLabel("Mining Xp: " & $minexp,5,245) 
$mlvl = GUICtrlCreateLabel("Mining level: " & $minelvl,5,265)
GUICtrlSetState ( $1, $GUI_DISABLE )
GUICtrlSetState ( $2, $GUI_DISABLE )
GUICtrlSetState ( $3, $GUI_DISABLE )
GUICtrlSetState ( $4, $GUI_DISABLE )
GUICtrlSetState ( $5, $GUI_DISABLE )
GUICtrlSetState ( $6, $GUI_DISABLE )
GUICtrlSetState ( $7, $GUI_DISABLE )
GUICtrlSetState ( $8, $GUI_DISABLE )
GUICtrlSetState ( $9, $GUI_DISABLE )
minecheck()

Func minecheck()
If $minelvl >= 1 Then
    GUICtrlSetState ( $1, $GUI_Enable )
    GUICtrlSetState ( $2, $GUI_Enable )
EndIf
If $minelvl >= 15 Then
    GUICtrlSetState ( $3, $GUI_Enable )
EndIf

If $minelvl >= 20 Then
    GUICtrlSetState ( $4, $GUI_Enable )
EndIf

If $minelvl >= 30 Then
    GUICtrlSetState ( $5, $GUI_Enable )
EndIf

If $minelvl >= 40 Then
    GUICtrlSetState ( $6, $GUI_Enable )
EndIf

If $minelvl >= 55 Then
    GUICtrlSetState ( $7, $GUI_Enable )
EndIf

If $minelvl >= 70 Then
    GUICtrlSetState ( $8, $GUI_Enable )
EndIf

If $minelvl >= 85 Then
    GUICtrlSetState ( $9, $GUI_Enable )
EndIf
EndFunc
Func orecheck()
    If GUICtrlRead($1) = 1 Then
        MsgBox(0,"","You mined some Tin!")
        $playerstock[1] = $playerstock[1] + 1
        $count = 0
        $bob = 0
        $minexp = $minexp + 17.5
    ElseIf GUICtrlRead($2) = 1 Then
        MsgBox(0,"","You mined some Copper!")
        $playerstock[0] = $playerstock[0] + 1
        $count = 0
        $bob = 0
        $minexp = $minexp + 17.5
    ElseIf GUICtrlRead($3) = 1 Then
        MsgBox(0,"","You mined some Iron!")
        $playerstock[2] = $playerstock[2] + 1
        $count = 0
        $bob = 0
        $minexp = $minexp + 35
    ElseIf GUICtrlRead($4) = 1 Then
        MsgBox(0,"","You mined some Silver!")
        $playerstock[3] = $playerstock[3] + 1
        $count = 0
        $bob = 0
        $minexp = $minexp + 40      
    ElseIf GUICtrlRead($5) = 1 Then
        MsgBox(0,"","You mined some Coal!")
        $playerstock[4] = $playerstock[4] + 1
        $count = 0
        $bob = 0
        $minexp = $minexp + 50
    ElseIf GUICtrlRead($6) = 1 Then
        MsgBox(0,"","You mined some Gold!")
        $playerstock[5] = $playerstock[5] + 1
        $count = 0
        $bob = 0
        $minexp = $minexp + 65
    ElseIf GUICtrlRead($7) = 1 Then
        MsgBox(0,"","You mined some Mithril!")
        $playerstock[6] = $playerstock[6] + 1
        $count = 0
        $bob = 0
        $minexp = $minexp + 80      
            ElseIf GUICtrlRead($8) = 1 Then
        MsgBox(0,"","You mined some Adamant!")
        $playerstock[7] = $playerstock[7] + 1
        $count = 0
        $bob = 0
        $minexp = $minexp + 95
    ElseIf GUICtrlRead($9) = 1 Then
        MsgBox(0,"","You mined some Runite!")
        $playerstock[8] = $playerstock[8] + 1
        $count = 0
        $bob = 0
        $minexp = $minexp + 120     
    EndIf

EndFunc

Func minetime()
    If guictrlread($1) = 1 then
        $minetime = 2
    ElseIf guictrlread($2) = 1 then
        $minetime = 2
    ElseIf guictrlread($3) = 1 then 
        $minetime = 3
    ElseIf guictrlread($4) = 1 then 
        $minetime = 4
    ElseIf guictrlread($5) = 1 then 
        $minetime = 5
    ElseIf guictrlread($6) = 1 then 
        $minetime = 6   
    ElseIf guictrlread($7) = 1 then 
        $minetime = 7
    ElseIf guictrlread($8) = 1 then 
        $minetime = 8
    ElseIf guictrlread($9) = 1 then 
        $minetime = 10
    EndIf
EndFunc
GUICtrlSetOnEvent($invo,"Inventory")
GUICtrlSetOnEvent($shope,"Shop")
GUICtrlSetOnEvent($mine,"bob")
GUISetState(@SW_SHOW)

While(1)
    sleep(100)
WEnd


Func Save()
    IniWrite("Player.ini","XP","mineXP",$minexp)
    IniWrite("Player.ini","Stats","mineLevel",$minelvl)
    $cnt = 0
    Do
    Item_Write($Items[$cnt])
    $cnt = $cnt + 1
    Until $cnt = (UBound($Items)-1)
EndFunc

func inventory()
GUICreate("item test",200,180,-1,-1)
$edit = GUICtrlCreateEdit("",0,0,200,150,BitOr($ES_READONLY,$WS_VSCROLL))
$G = GUICtrlCreateLabel("Gold: " & $pGold,100,155)
Item_list($playerstock,10,$edit)
GUISetState (@SW_SHOW)
EndFunc

func shop()
GUICreate("Shop",200,230,-1,-1)
$shop = GUICtrlCreateEdit("",0,0,200,150,BitOr($ES_READONLY,$WS_VSCROLL))
$GS = GUICtrlCreateLabel("Gold: " & $sGold,0,155)
$PSI = GUICtrlCreateInput("",1,175)
$PS = GUICtrlCreateButton("Price",60,172)
$BI = GUICtrlCreateInput("",1,200,59,20)
$buy = guictrlcreatebutton("Buy",60,197)
$SI = GUICtrlCreateInput("",90,200,59,20)
$sell = GUICtrlCreateButton("Sell",144,197)
GUISetState (@SW_SHOW)
GUICtrlSetOnEvent($PS, "Price")
GUICtrlSetOnEvent($buy,"Buy")
GUICtrlSetOnEvent($sell,"Sell")
Item_list($shopstock,10,$shop)
EndFunc


Func Item_list($array,$output)
    $var = 0
    GUICtrlSetData($output,"")
    While ($var <= UBound($array)-1)
        If $array[$var] > 0 Then
            GUICtrlSetData($output,GUICtrlRead($output) & $Items[$var] & ": " & $array[$var] & @CRLF)
        
        EndIf
        $var = $var + 1
    WEnd
EndFunc

Func Price()
    $search = GUICtrlRead($PSI)
$find = _ArraySearch($Items,$search)
If $find = -1 Then 
    MsgBox(0,"","Invalid Item")
    Else
MsgBox(0,"","A " & $Items[$find] & " costs " & $price[$find] & " Gold. (Items sell for half of thier normal value.)")
EndIf
EndFunc

Func Buy()
    $search = GUICtrlRead($BI)
    $find = _ArraySearch($Items,$search)
    If $find = -1 Then
        msgbox(0,"","Invalid Item")
    ElseIf $shopstock[$find] = 0 Then
            MsgBox(0,"","The shop does not have any of that item")

    Else
        
        $ammount = InputBox("Buy","How many " & $Items[$Find] & "s would you like to buy?",""," M")
        $cost = ($ammount * $price[$find])
        If $ammount > $shopstock[$find] Then
            MsgBox(0,"","The shop does not have that many " & $Items[$find] & "(s).")
        Else
            
            If $cost > $pgold Then
                msgbox(0,"","You do not have enough gold.")
            Else
                $pgold = $pgold - $cost
                $sgold = $sgold + $cost
                $Shopstock[$find] = $Shopstock[$find] - $ammount    
                $playerstock[$find] = $playerstock[$find] + $ammount
                Item_list($playerstock,10,$edit)
                Item_list($Shopstock,10,$shop)
                GUICtrlSetData($g,"Gold: " & $pgold)
                GUICtrlSetData($GS,"Gold: " & $sgold)
                msgbox(0,"Buy","You bought " & $ammount & " " & $Items[$find] & "(s) for " & $cost & " gold.")
            EndIf
        EndIf
    EndIf
    save()
EndFunc

Func Sell()
    $search = GUICtrlRead($SI)
    $find = _ArraySearch($Items,$search)
    If $find = -1 Then
        msgbox(0,"","Invalid Item")
    ElseIf $playerstock[$find] = 0 Then
        MsgBox(0,"","You do not have any of that item")
        
        
    Else
        $ammount = InputBox("Sell","How many " & $Items[$Find] & "s would you like to sell?",""," M")
        $cost = int(($ammount * $price[$find])/2)
        If $ammount > $playerstock[$find] Then
            MsgBox(0,"","You do not have that many " & $Items[$find] & "s to sell.")
        Else
            
            If $cost > $sgold Then
                msgbox(0,"","The shop does not have enough gold.")
            Else
                $pgold = $pgold + $cost
                $sgold = $sgold - $cost
                $Shopstock[$find] = $Shopstock[$find] + $ammount    
                $playerstock[$find] = $playerstock[$find] - $ammount
                Item_list($playerstock,10,$edit)
                Item_list($Shopstock,10,$shop)
                GUICtrlSetData($g,"Gold: " & $pgold)
                GUICtrlSetData($GS,"Gold: " & $sgold)
                msgbox(0,"Buy","You sold " & $ammount & " " & $Items[$find] & "(s) for " & $cost & " gold.")
            EndIf
        EndIf
    EndIf
    save()
EndFunc
Edited by Darth
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...