Auction House Script

*Created by Taz.*

```
Using "RC_Core.rcm"
;By Tazco

  Function Main()
  ;AUCTION HOUSE
     ;NOTE INFO
           ;File is made, write item info to file. test by adding each info to its own line.
         ;Line 1 player name line 2 item name, line 3 amount of items, 4 item bid cost, 5 item buyout cost.
         ;using 5 lines,  line 6 would be a new item line 7 would be a third item and so on.

         ;when searching AH for items, will search items by name of players that have items up.
         ; when clicking on the name read there file to show what they have for sale.
         ;this way you will get to know peoples names that you buy from better.

;-------------------------------------------------------------
;------------- NOTES AND FUTURE UPDATES maybe ----------------
;-------------------------------------------------------------
; Add a item search option.
; dialog pics for items.
;
  ;
  ;
  ;-------------------------------------------------------------
;---------------- END TO DO LIST -----------------------------
;-------------------------------------------------------------

;000000000000000000000000000000000000000000000000000000000000000000000000
;000000000000000000000000000000000000000000000000000000000000000000000000
;000000000000000000000000000000000000000000000000000000000000000000000000
;>>>>>>>>>>>>>>>>>>>Coded and working features.<<<<<<<<<<<<<<<<<<<<<<<<<<
;Auction will have a 2% charge that will be taken from payment when recived.
;Multipale items is supported.
;Buyout item or 1 of an item quantitiy. (Will add option to buy more then 1 later)
;Bid on item, and will track highest bidder name. (Working on bid time system)
;Check your own auctions and collect payments.
;
  ;
  ;
  ;
  ;ADD THE REST LATER
;

  ;Bid would not work over 100, that has been fixed. June 5 2011
;fixed repeat for when a bid is to low. June 5 2011
;Player will now lose item that they have posted up for auction. June 6 2011
;fixed buyout cost, and auction house fees, will be a min of 1 gold. June 6 2011

;Testing an Auction House script
Player = Actor()
PName$ = Name(Player)
Target = Contextactor()
PMoney% = Money(Player)
Takeline% = 0 ;if set to 1 item has no more quntinity then set the write from temp to take a line away.

ScriptLog("Auction house script running by " + Pname)

;<<<<<<<<<<<<<<<<<<<<<<<AUCTION HOUSE>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;<<<<<<<<<<<<<<<<<<<<<<<<OPTIONS>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 NewAuctionFee# = .02 ;auction fee 2% of total earnings. change to amount the auction house fee should be.
 AuctionFee# = NewAuctionFee
 MaxBuycost# = .015  ;NOT ADDED YET. Will be 15 % more then the price set in the gue for an item. may change to higher.

;NewFee% = AuctionFee * 60

;OutPut(Player, "fee is " + NewFee)
;<<<<<<<<<<<<<<<<<<<<<<<AUCTION HOUSE>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;<<<<<<<<<<<<<<<<<<<<<<<<OPTIONS>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

ChatBox$ = OpenDialog(Player, Target, "Auction House", 521)

DialogOutPut(Player, ChatBox, "What would you like to do?", 200, 230, 25)
POption% = DialogInput(Player, ChatBox, "Search Auction,Post an Auction,Check Auctions,Nothing")

If (POption = 4) ;Close
    CloseDialog(Player, ChatBox)
    Return

  EndIf
  ;---------------------------------------------

If (POption = 1) ;Allow player to search the Auction.

          SellerCheck% = OpenFile("Auction-Sellers.txt")

            If (SellerCheck = 0) ;there is no sellers tell player.
                DialogOutPut(Player, ChatBox, "There is no auctions at this time.", 230, 145, 23)
                DialogInput(Player, Chatbox, "Close")
                CloseFile(SellerCheck)
                CloseDialog(Player, ChatBox)
                Return
            EndIf

        CloseFile(SellerCheck)

        CloseDialog(Player, ChatBox)
       ;check for sellers
            AuctionsAval% = 0 ;define AuctionsAval as 0
            sellerAuctions$ = ReadFile("Auction-Sellers.txt")

                Repeat
                  ;count names in file

                  fileCheck$ = ReadLine(sellerAuctions)
                  EndFile% = Eof(sellerAuctions)
                  Doevents(2)
                  AuctionsAval% = AuctionsAval + 1

                         If (EndFile = 1)
                            TotAuctionAval% = AuctionsAval ;total of names in list with auctions.
                          EndIf

                Until (EndFile = 1)
                CloseFile(sellerAuctions)
                closeFile(fileCheck)

                ChatBox1$ = OpenDialog(Player, Target, "Search Auction House", 521)

               sellerAuctions1$ = ReadFile("Auction-Sellers.txt")

               If (AuctionsAval <= 10) ;10 or less names show this one.
                    Ticks% = TotAuctionAval ;amount of lines to read
                    Repeat

                            Ticks% = Ticks - 1
                            fileCheck$ = ReadLine(sellerAuctions1)
                            DialogOutPut(Player, ChatBox1, fileCheck, 230, 145, 24)

                        DoEvents(4)
                    Until (Ticks = 0)

                        closeFile(fileCheck)

                EndIf

                 CloseFile(sellerAuctions1)

                If (AuctionsAval >= 11) ;11 or more name show this one

                ;need to add code for if auction list is bigger then ten
                EndIf

                ChatBox$ = OpenDialog(Player, Target, "Search Auction House", 521)
                Dialogoutput(Player, ChatBox, "List of names that currently have an auction running. Please type the name of the player to view there items. Note: move this window to see list of names.", 200, 132, 23)

             Sellname1$ = Input(Player, "Seller name", "", 0) ;seller file to open.
             Searchname$ = Sellname1 ;inputed name to use in the rest of script.
             CloseDialog(Player, ChatBox)
             CloseDialog(Player, ChatBox1)

                ;Search list for name that was inputed
                ChatBox$ = OpenDialog(Player, Target, "Search Auction House", 521)

                DialogOutput(Player, ChatBox, "--------- Searching Please Wait ---------", 255, 0, 0)
                Doevents(40)

                Auctionnames% = 0

                sellerAuctions2$ = OpenFile("Auction-Sellers.txt")
                Nameinfile% = 0
                CheckTick% = AuctionsAval
                Repeat
                DoEvents(5)
                  CheckTick% = CheckTick - 1
                  fileCheck$ = ReadLine(sellerAuctions2)

                                       ;not calling this, to show multiple names.
                       If (fileCheck = Searchname)
                            EndFile% = 1
                            Auctionnames% = 1
                            output(player, "test")
                       EndIf
                      EndFile% = Eof(sellerAuctions2)

                        CurrentName1$ = fileCheck
                Until (EndFile = 1)

                        CloseDialog(Player, ChatBox)
                        CloseFile(sellerAuctions2)
                        closeFile(fileCheck)

;if name in list show seller acutions.
 If Not (Auctionnames = 1)

                  ;---------------------------------------------------

               ;Name is not in the list.
      CloseDialog(Player, ChatBox)
      ChatBox$ = OpenDialog(Player, Target, "Search Auction House", 521)
      DialogOutPut(Player, ChatBox, "Name entered is not in the list. Check your spelling and try again.", 255, 50, 0)
      DialogInput(Player, ChatBox, "Close")
      CloseDialog(Player, ChatBox)

      Return

     Else ;Display all items in sellers list.
     PlayerAuctions3$ = ReadFile(+ Searchname + " Auctions.txt")
    Repeat
          CloseDialog(Player, ChatBox)
        ChatBox$ = OpenDialog(Player, Target, "Search Auction House", 521)
    ;Read sellers info
          Readline1$ = ReadString(PlayerAuctions3) ;seller name
          Readline2$ = ReadString(PlayerAuctions3) ;item name
          Readline3$ = ReadString(PlayerAuctions3) ;item qun
          Readline4$ = ReadString(PlayerAuctions3) ; bid cost
          Readline5$ = ReadString(PlayerAuctions3) ; buyout cost
          Readline6$ = Readstring(PlayerAuctions3) ; name of player that bid if any.

            SellerName$ = Readline1
            CurItemName$ = Readline2
            ItemQunty% = Readline3
            BidCost% = Readline4
            BuyoutCost% = Readline5
            Biddername$ = Readline6

            EndFile% = Eof(PlayerAuctions3)

         If (Biddername = 0) ; if there is no bider show this.

            DialogOutPut(Player, Chatbox, "Seller Name: " + SellerName, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "Item Name: " + CurItemName, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "Item Quantity: " + ItemQunty, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "Bid Cost: " + BidCost, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "BuyOut Cost: " + BuyoutCost, 200, 132, 23)

          Else ; if there is a bidder show this.
            DialogOutPut(Player, Chatbox, "Seller Name: " + SellerName, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "Item Name: " + CurItemName, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "Item Quantity: " + ItemQunty, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "Bid Cost: " + BidCost, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "BuyOut Cost: " + BuyoutCost, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "Current Bidder: " + Biddername, 200, 132, 23)
          EndIf

          If (Endfile = 1)
            DialogOutPut(Player, Chatbox, "Last item in list.", 244, 132, 23)
            BuyOption% = DialogInput(Player, ChatBox, "Bid,Buyout,Close")
            Nomoreauction = 1
        Else
              BuyOption% = DialogInput(Player, ChatBox, "Bid,Buyout,Close,Next")
            ;Options that will stop if player hits next loop will continue.
                If (BuyOption = 1)
                    Nomoreauction = 1
                EndIf

                If (BuyOption = 2)
                    Nomoreauction = 1
                EndIf

                If (BuyOption = 3)
                    Nomoreauction = 1
                EndIf

        EndIf

              Doevents(5)

     Until (Nomoreauction = 1)

           BidItemName$ = Readline2 ;item name that player has bid or will use as buyout.

           CloseFile(PlayerAuctions3)

    If (BuyOption = 1) ; place a bid
Repeat

                        ;player wants to bid change file to add there bid amount
                         CloseDialog(Player, ChatBox)
                         ChatBox$ = OpenDialog(Player, Target, "Search Auction House", 521)
                         DialogOutPut(Player, ChatBox, "How much would you like to bid for this item?", 200, 132, 23)
                         Closebid = 0
            ;--------------------------------------------
            ;set new bid
                      NewBidAmount% = Input(Player, "New Bid", "", 2)
                         Repeat

                            DoEvents(14)
                            ;Check if bid enter is the same or higher then bid stored

                             If (NewBidAmount > Pmoney) ; check if player has enough money to make this bid.
                                DialogOutPut(Player, ChatBox, "You do not have enough money to make this bid.", 255, 23, 123)
                                DialogInput(Player, ChatBox, "Close")
                                CloseDialog(Player, ChatBox)
                                Return
                             EndIf
                                Readline41% = Readline4 ; changing to a real number to see if its greater. well it works with this.

                          If (NewBidAmount > Readline41)
                               ;DeleteFile(+ Sellername + " Auctions.txt")
                               ;--------------------------------------
                               ;Count items
                              AuctionAmount% = 1 ;define AuctionsAval as 1 set to one, so it will read the last line LEAVE SET TO 1.
                              sellerAuctions1$ = ReadFile("Auction-Sellers.txt")
                           Repeat
                                ;count items in file

                                fileCheck$ = ReadLine(sellerAuctions1)
                                EndFile% = Eof(sellerAuctions1)
                                Doevents(2)
                                AuctionAmount% = AuctionAmount + 1

                                    If (EndFile = 1)
                                        TotAuctionAmount% = AuctionAmount ;total item in auction list.
                                    EndIf

                            Until (EndFile = 1)
                                CloseFile(sellerAuctions1)
                                CloseFile(fileCheck)
;---------------------------------------------------------------------------------------------
  ;-------------------------WRITE AUCTION TEMP FILE----------------------------------
  ;-----------------------------------------------------------------------------------
 ;---------------------------------------------------------------------------------------------
  ;-------------------------------------------------------------------------------------------

        ;----------Read amount of items in file -------
        ;----------------------------------------------
        Newbidfile1$ = OpenFile(+ Sellername + " Auctions.txt")
        ;Count items in seller auction
        SellerAuction3% = 0  ;when reading this need to be 0 if writing this needs to be 1
                  Repeat
                  ;count items in file

                  ;fileCheck$ = ReadLine(Newbidfile1)

                  Doevents(12)
                  SellerAuction3% = SellerAuction3 + 1

                                SellerName2$ = ReadString(Newbidfile1)
                                CurItemName2$ = ReadString(Newbidfile1)
                                ItemQunty2% = ReadString(Newbidfile1)
                                BidCost2% = ReadString(Newbidfile1)
                                BuyoutCost2% = ReadString(Newbidfile1)
                                BidderName2$ = ReadString(Newbidfile1)

                   EndFile% = Eof(Newbidfile1)

                         If (EndFile = 1)
                            TotSellerAuction3% = SellerAuction3 ;total of names in list with auctions.
                          EndIf

                Until (EndFile = 1)
                CloseFile(Newbidfile1)
                closeFile(fileCheck)
       ;---------------------------------------------
       ;---------------------------------------------

                               Newbidfile$ = ReadFile(+ Sellername + " Auctions.txt")
                               TempFile$ = WriteFile(+ Sellername + " Temp Auctions.txt") ;write to temp file then back to real file.

                             Repeat

                              TotSellerAuction3% = TotSellerAuction3 - 1
                               ;Rewrite file to add updates.
                               Doevents(2)

                                SellerName1$ = ReadString(Newbidfile)
                                CurItemName1$ = ReadString(Newbidfile)
                                ItemQunty1$ = ReadString(Newbidfile)
                                BidCost1$ = ReadString(Newbidfile)
                                BuyoutCost1$ = ReadString(Newbidfile)
                                BidderName1$ = ReadString(Newbidfile)

                                ;Change strings
                                SellerName2$ = SellerName1
                                CurItemName2$ = CurItemName1
                                ItemQunty2% = ItemQunty1
                                BidCost2% = BidCost1
                                BuyoutCost2% = BuyoutCost1
                                BidderName2$ = BidderName1
                                Doevents(2)

                             ;write to file based on if there is changes or not.
                               If (CurItemName1 = BidItemName)
                                ;If items is the item that was bid on then change bid price and add a string.
                                WriteString(TempFile, SellerName2)
                                WriteString(TempFile, CurItemName2)
                                WriteString(TempFile, ItemQunty2)
                                WriteString(TempFile, NewBidAmount) ;new bid to add to file.

                               ;   If (NewBidAmount > BuyoutCost)
                               ;     ;New bid is higher then buyout, set buyout to new bid.
                               ;     WriteString(TempFile, NewBidAmount)
                               ;    Endif

                                WriteString(TempFile, BidderName2)
                               Else

                                ;if item is not the item that was bid on then copy from text with no changes.
                                WriteString(TempFile, SellerName2)
                                WriteString(TempFile, CurItemName2)
                                WriteString(TempFile, ItemQunty2)
                                WriteString(TempFile, BidCost2)
                                WriteString(TempFile, BuyoutCost2)
                                WriteString(TempFile, BidderName2)
                               EndIf
                               ;Endfile% = Eof(Newbidfile)
                               ;Endfile1% = Eof(TempFile)

                             Until (TotSellerAuction3 = 0)

                              ; CloseFile(SellerName1)
                              ; CloseFile(CurItemName1)
                              ; CloseFile(ItemQunty1)
                              ; CloseFile(BidCost1)
                               ;CloseFile(BuyoutCost1)

                               CloseFile(Newbidfile)
                               CloseFile(TempFile)

                               DeleteFile(+ Sellername + " Auctions.txt") ; delete file so it can be re writen

;---------------------------------------------------------------------------------------------
;---------------------------------------------------------------------------------------------
 ;---------------------------------------------------------------------------------------------
;---------------COPY TEMP FILE MADE ABOVE BACK TO PLAYER AUCTION PLUS UPDATES------------------
 ;---------------------------------------------------------------------------------------------
;---------------------------------------------------------------------------------------------
 ;---------------------------------------------------------------------------------------------
  ;---------------------------------------------------------------------------------
  ;Rewrite player auction file with updates.

                               Newbidfile$ = ReadFile(+ Sellername + " Temp Auctions.txt")
                               TempFile$ = WriteFile(+ Sellername + " Auctions.txt") ;write to temp file then back to real file.

                             Repeat

                              SellerAuction3% = SellerAuction3 - 1
                               ;Rewrite file to add updates.
                               Doevents(2)

                                SellerName1$ = ReadString(Newbidfile)
                                CurItemName1$ = ReadString(Newbidfile)
                                ItemQunty1$ = ReadString(Newbidfile)
                                BidCost1$ = ReadString(Newbidfile)
                                BuyoutCost1$ = ReadString(Newbidfile)
                                BidderName1$ = ReadString(Newbidfile)
                                ;Change strings

                                SellerName2$ = SellerName1
                                CurItemName2$ = CurItemName1
                                ItemQunty2% = ItemQunty1
                                BidCost2% = BidCost1
                                BuyoutCost2% = BuyoutCost1
                                BidderName2$ = BidderName1
                                Doevents(2)

                             ;write to file based on if there is changes or not.
                               If (CurItemName1 = BidItemName)
                                 BidderName2$ = Pname ; set player name as bidder.
                                ;If items is the item that was bid on then change bid price and add a string.
                                WriteString(TempFile, SellerName2)
                                WriteString(TempFile, CurItemName2)
                                WriteString(TempFile, ItemQunty2)
                                WriteString(TempFile, NewBidAmount) ;new bid to add to file.
                                WriteString(TempFile, BuyoutCost2)
                                WriteString(TempFile, BidderName2)  ;Name of player that has bid on this item.
                               Else

                                ;if item is not the item that was bid on then copy from text with no changes.
                                WriteString(TempFile, SellerName2)
                                WriteString(TempFile, CurItemName2)
                                WriteString(TempFile, ItemQunty2)
                                WriteString(TempFile, BidCost2)
                                WriteString(TempFile, BuyoutCost2)
                                WriteString(TempFile, BidderName2) ;LINE 6 write extra line that will store current bidder.

                               EndIf
                               ;Endfile% = Eof(Newbidfile)
                               ;Endfile1% = Eof(TempFile)

                            Until (SellerAuction3 = 0)

                               CloseFile(Newbidfile)
                               CloseFile(TempFile)
                                DeleteFile(+ Sellername + " Temp Auctions.txt") ;delete temp file since it is not needed anymore.

 ;---------------------------------------------------------------------------------------------
;---------------------------------------------------------------------------------------------
 ;---------------------------------------------------------------------------------------------
;---------------------------------------------------------------------------------------------
 ;---------------------------------------------------------------------------------------------
;---------------------------------------------------------------------------------------------
 ;---------------------------------------------------------------------------------------------
;---------------------------------------------------------------------------------------------

                               PayBid% = PMoney - NewBidAmount
                               ChangeMoney(Player, PayBid)

                               CloseDialog(Player, ChatBox)
                               ChatBox$ = OpenDialog(Player, Target, "Search Auction House", 521)
                               DialogOutPut(Player, ChatBox, "Your bid has been accepted", 234, 26, 135)
                               DialogInput(Player, ChatBox, "Close")
                               CloseDialog(Player, ChatBox)
                               Return

                            Else ;bid is less then stored amount close bid or give another chance.
                                CloseDialog(Player, ChatBox)
                                ChatBox$ = OpenDialog(Player, Target, "Search Auction House", 521)
                                DialogOutPut(Player, ChatBox, "Bid needs to be the same or higher then current bid amount.", 200, 132, 23)
                                DialogOutPut(Player, Chatbox, "Current bid is " + Readline4 + " would you like to bid again?", 200, 132, 23)
                                Doevents(200)
                                POption% = DialogInput(Player, Chatbox, "No,Yes")

                                    If (POption = 1) ;stop repeat and close
                                       closebid = 1
                                       BidDone = 1
                                       CloseDialog(Player, ChatBox)

                                       Return
                                    EndIf

                                    If (POption = 2)
                                      closebid = 1
                                      BidDone = 0
                                    EndIf

                            EndIf
                        Until (closebid = 1)
Until(BidDone = 1)
;----------------------------------------------------------------------
;----------------------------------------------------------------------
                    ; Buyout item
;----------------------------------------------------------------------
;----------------------------------------------------------------------
       ElseIf (BuyOption = 2)

        ;Check if item has a quantity

               ;----------Read amount of items in file -------
        ;----------------------------------------------
        Newbidfile1$ = OpenFile(+ Sellername + " Auctions.txt")

            If (Newbidfile1 = 0) ;if there is no auctions then don`t open.
                OutPut(Player, "There are no auctions at this time.", 255, 24, 100)
                CloseDialog(Player, ChatBox)
                CloseFile(Newbidfile1)
                Return

            EndIf

           CountItems% = 0
        ;Count items in seller auction
              Repeat
                  ;count items in file

                  ;fileCheck$ = ReadLine(Newbidfile1)

                  Doevents(12)

                    CountItems% = CountItems + 1

                                SellerName2$ = ReadString(Newbidfile1)
                                CurItemName2$ = ReadString(Newbidfile1)
                                ItemQunty2% = ReadString(Newbidfile1)
                                BidCost2% = ReadString(Newbidfile1)
                                BuyoutCost2% = ReadString(Newbidfile1)
                                BidderName2$ = ReadString(Newbidfile1)

                                NSellerName$ = SellerName2
                                NCurItemName$ = CurItemName2
                                NItemQunty% = ItemQunty2
                                NBidCost% = BidCost2
                                NBuyoutCost% = BuyoutCost2
                                NBiddername$ = BidderName2

                   EndFile% = Eof(Newbidfile1)

                          If (CurItemName = NCurItemName) ; it name of item is same as buyout item.
                            If (ItemQunty2 > 1) ; if item quantity is greater then 1
                                BuyItemQ% = 1
                                NewItemQ$ = NItemQunty - 1

                            EndIf
                          EndIf

                Until (EndFile = 1)
                CloseFile(Newbidfile1)
                closeFile(fileCheck)
                ;---------------------------------------------
                ;---------------------------------------------

          CloseDialog(Player, ChatBox)
          ChatBox$ = OpenDialog(Player, Target, "Search Auction House", 521)
          DialogOutPut(Player, ChatBox, "Total cost for this item is " + BuyoutCost + " gold", 203, 123, 234)
          DialogOutPut(Player, ChatBox, "Are you sure you would like to buy out this item?", 203, 123, 234)

              Buyitem$ = DialogInput(Player, ChatBox, "No,Yes")

                If (Buyitem = 1) ;close

                CloseDialog(Player, Chatbox)
                Return
                EndIf

          ;Check if player has enough money to buy out item.
          If (Pmoney >= NBuyoutCost)
            If (NItemQunty > 0)

                ;Player only has one of this item file can be deleted.
                TakeMoney% = Pmoney - BuyoutCost
                Giveitem(Player, BidItemName) ; give buy out item
                ChangeMoney(Player, TakeMoney)

                DialogOutPut(Player, ChatBox, "You have bought " + BidItemName + " for " + BuyoutCost + " gold", 203, 123, 234)
                DoEvents(1300)

                sellerAuctions$ = ReadFile("Auction-Sellers.txt")
                AuctionsAval1% = 0
                Repeat
                  ;count names in file

                  fileCheck$ = ReadLine(sellerAuctions)

                  Doevents(2)
                  AuctionsAval1% = AuctionsAval1 + 1

                     EndFile% = Eof(sellerAuctions)
                          If (EndFile = 1)
                            TotAuctionAval1% = AuctionsAval1 ;total of names in list with auctions.
                          EndIf

                Until (EndFile = 1)
                CloseFile(sellerAuctions)
                closeFile(fileCheck)
               ;---------------------------------------------

  ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
   ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
         ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 ;changed TotAuctionAval1 in if statment below to CountItems need to find out where player auction file is getting deleted
 ;also need to fix part for seller list will not be removed when player still has items or quantitiy.

           If (TotAuctionAval1 <= 0) ;player has no more auctions. Delete file

                  If (NItemQunty <= 0)

                    DeleteFile(+ Searchname + " Auctions.txt")
                EndIf
                DoEvents(300)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
         ;-----------------------------------------------------------------------------
                  ;Make new payment files if they are not present.
         ;-----------------------------------------------------------------------------
                PlayerPaymentfile$ = OpenFile(+ Searchname + "Payment.txt")

                   If (PlayerPaymentfile = 0) ;Make files needed.
                        Newbidfile5$ = WriteFile(+ Searchname + "Payment.txt")
                         TotPayamount% = Payamount + NBuyoutCost

                        ;add info to list.
                        WriteLine(Newbidfile5, TotPayamount)

                        Doevents(10)
                        CloseFile(Newbidfile5)
                        CloseFile(PlayerPaymentfile)

                    Else ;change payment file amount

                        Repeat
                            Payamount% = ReadLine(PlayerPaymentfile)
                            Endfile% = Eof(PlayerPaymentfile)
                            DoEvents(10)
                        Until (Endfile = 1)

                          ;add money in payment plus buyout price.
                             TotPayamount% = Payamount + NBuyoutCost

                            DoEvents(10)

                            DeleteFile(+ Searchname + "Payment.txt") ;delete file so it can be remade with changes
                            DoEvents(10)

                            Newbidfile5$ = WriteFile(+ Searchname + "Payment.txt")
                            WriteLine(Newbidfile5, TotPayamount)

                        CloseFile(Newbidfile5)
                        CloseFile(PlayerPaymentfile)
                       Return
                    EndIf
 CloseDialog(Player, ChatBox)

              Else  ;player still has auctions remake file.
              ;Make payment file for quntity items.
         ;-----------------------------------------------------------------------------
                  ;Make new payment files if they are not present.
         ;-----------------------------------------------------------------------------

                 PlayerPaymentfile$ = OpenFile(+ Searchname + "Payment.txt")

                    If (PlayerPaymentfile = 0) ;Make files needed.
                        Newbidfile5$ = WriteFile(+ Searchname + "Payment.txt")
                         TotPayamount% = Payamount + NBuyoutCost

                        ;add info to list.
                        WriteLine(Newbidfile5, TotPayamount)

                        Doevents(10)
                         CloseFile(Newbidfile5)
                        CloseFile(PlayerPaymentfile)

                    Else ;change payment file amount

                        Repeat
                            Payamount% = ReadLine(PlayerPaymentfile)
                            Endfile% = Eof(PlayerPaymentfile)
                            DoEvents(10)
                        Until (Endfile = 1)

                          ;add money in payment plus buyout price.
                             TotPayamount% = Payamount + NBuyoutCost

                            DoEvents(10)

                            DeleteFile(+ Searchname + "Payment.txt") ;delete file so it can be remade with changes
                            DoEvents(10)

                            Newbidfile5$ = WriteFile(+ Searchname + "Payment.txt")
                            WriteLine(Newbidfile5, TotPayamount)

                        CloseFile(Newbidfile5)
                        CloseFile(PlayerPaymentfile)

                    EndIf

        CloseDialog(Player, ChatBox)

;---------------------------------------------------------------------------------------------
;------------------------- --------------buyout------------
;-------------------------------------------------------------------------------------------

        ;----------Read amount of items in file -------
        ;----------------------------------------------
        Newbidfile1$ = OpenFile(+ Sellername + " Auctions.txt")

              If (Newbidfile1 = 0) ;save a crash and just end the script.
                ScriptLog(+ Sellername + " Auctions.txt was not found for " + Pname)
                Closedialog(Player, Chatbox)
                Return
            EndIf

          ;Count items in seller auction
        SellerItemLeft% = 0
        SellerAuction% = 0 ;when reading this need to be 0 if writing this needs to be 1

                Repeat
                  ;count items in file

                  ;fileCheck$ = ReadLine(Newbidfile1)
                    SellerAuction% = SellerAuction + 1
                  Doevents(12)

                                SellerName2$ = ReadString(Newbidfile1)
                                CurItemName2$ = ReadString(Newbidfile1)
                                ItemQunty2% = ReadString(Newbidfile1)
                                BidCost2% = ReadString(Newbidfile1)
                                BuyoutCost2% = ReadString(Newbidfile1)
                                BidderName2$ = ReadString(Newbidfile1)

                         EndFile% = Eof(Newbidfile1)

                  If (EndFile <= 0) ;only add to item amount if the file is not at the end.
                    SellerItemLeft% = SellerItemLeft + 1
                  EndIf

                        TotSellerItemLeft% = SellerItemLeft

                         If (EndFile = 1)
                            TotSellerAuction% = SellerAuction ;total of names in list with auctions.
                            TotSellerAuction2% = SellerAuction
                          EndIf

                            If (CurItemName2 = BidItemName)
                                ItemHasQ% = ItemQunty2 - 1 ;amount left from item when 1 has been bought
                                EndFile = 1
                            EndIf

                Until (EndFile = 1)
                CloseFile(Newbidfile1)
                ;closeFile(fileCheck)

 ;--------------COUNT NUMBER OF AUCTIONS PLAYER HAS LEFT---------------
       ;---------------------------------------------
       Newbidfile$ = ReadFile(+ Sellername + " Auctions.txt")

                  If (ItemHasQ = 0)
                      CountItemLeft% = - 6 ; take away 6 since this item has been bougt so don`t count it.
                     NewCount% = - 6 ; take away 6 since this item has been bougt so don`t count it.
                Else
                     CountItemLeft% = 0 ; set to zero since there is still auctions.
                     NewCount% = 0
                EndIf

                        Repeat
                           CountItemLeft% = CountItemLeft + 1
                           NewCount% = NewCount + 1
                           Doevents(2)
                           Hasauction1% = ReadString(Newbidfile)

                            If (NewCount = 0)
                              If (ItemHasQ = 0)
                                CountItemLeft% = 0
                                EndFile% = 1
                               EndIf
                            EndIf

                             EndFile% = Eof(Newbidfile)
                      Until (EndFile = 1)

                CloseFile(Newbidfile)

                OutPut(Player, "CountItemLeft " + CountItemLeft + " ItemHasQ " + ItemHasQ + " NewCount " + NewCount)

                           If (NewCount = 0)

                            If (ItemHasQ <= 0)
                                ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                                 DeleteFile(+ Sellername + " Auctions.txt") ;Delete player auction file if there is nothing left in it.
                            EndIf
                           EndIf

        ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

          If (CountItemLeft = 0)

                 ;Remove player name from sellers list.
               ;delete seller list if there is no more names in it, or take sellers name out.
;-----Here-------
                    Amountofnames% = 0
                    Nosellers% = 0

                  OpenSeller$ = OpenFile("Auction-Sellers.txt")

                    ;check if there is any other sellers
                        Repeat
                            DoEvents(10)
                              CountName1$ = Readline(OpenSeller)

                               If (CountName1 = Sellername)
                                  If (CountItemLeft = 0)
                                    EndFile% = 1
                                    Nosellers% = 1
                                  EndIf
                               EndIf

                            Endfile% = Eof(OpenSeller)
                         Until (Endfile = 1)

                           CloseFile(OpenSeller)
                           CloseFile(CountName1)

                         ;...................................................................
                            If (Nosellers = 1) ;delete seller list
                             If (ItemHasQ = 0)
                              If (NewCount = 0)
                                ;delete auction seller names file if there is no items left.
                                DeleteFile("Auction-Sellers.txt")

                                Return
                               EndIf
                              EndIf
;-----to here---------
                            Else ;there is still names in the list rewrite file with names that are left.

  ;...................................................................
  ;...................................................................
  ;...................................................................
  ;...................................................................
  ;...................................................................
  ;...................................................................
  ;...................................................................
  ;...................................................................

                    OpenSeller$ = OpenFile("Auction-Sellers.txt")
                      ;---------------------------------------------------------
                        ;Count amount of players in list.
                        Countnametotal% = 0
                      ;Count seller names.
                        Repeat
                            DoEvents(10)
                              CountName$ = Readline(OpenSeller)
                                Countnametotal% = Countnametotal + 1
                                Totcountname% = Countnametotal
                            Endfile% = Eof(OpenSeller)
                        Until (Endfile = 1)
                        ;---------------------------------------------------------

                          CloseFile(OpenSeller)

                            ;Write a temp seller file.
                            ReadMainFile$ = OpenFile("Auction-Sellers.txt")
                            WriteTempFile$ = WriteFile("Temp-Auction-Sellers.txt")

                                Repeat
                                Totcountname% = Totcountname - 1
                                DoEvents(10)

                                Name1$ = Readline(ReadMainFile)

                                    If (Name1 = Sellername) ; if name read is the same as seller don`t write line.
                                    ;Do nothing
                                    Else
                                    WriteLine(ReadMainFile, Name1)

                                    EndIf

                                Until (Totcountname = 0)

                                    CloseFile(ReadMainFile)
                                    CloseFile(WriteTempFile)

                                ;Rewrite temp to real file.
                                    ReadMainFile$ = OpenFile("Temp-Auction-Sellers.txt")
                                    WriteTempFile$ = WriteFile("Auction-Sellers.txt")

                                Repeat
                                Countnametotal% = Countnametotal - 1

                                Name1$ = Readline(ReadMainFile)
                                DoEvents(10)

                                    WriteLine(ReadMainFile, Name1)

                                Until (Countnametotal = 0)

                                    CloseFile(ReadMainFile)
                                    CloseFile(WriteTempFile)

                               EndIf ;end seller check and rewrite.

             return
           Else ;seller still has items in list countine with script.
;output(player, "_-----_---debug-----_-----")

                               Newbidfile$ = ReadFile(+ Sellername + " Auctions.txt")
                               TempFile$ = WriteFile(+ Sellername + " Temp Auctions.txt") ;write to temp file then back to real file.

                        Repeat
        ;----------------------------------------------------------------------------------------
        ;----------------------------------------------------------------------------------------
        ;----------------------------------------------------------------------------------------
        ;----------------------------------------------------------------------------------------

                               TotSellerAuction% = TotSellerAuction - 1
                               ;Rewrite file to add updates.
                               Doevents(2)

                                SellerName1$ = ReadString(Newbidfile)
                                CurItemName1$ = ReadString(Newbidfile)
                                ItemQunty1$ = ReadString(Newbidfile)
                                BidCost1$ = ReadString(Newbidfile)
                                BuyoutCost1$ = ReadString(Newbidfile)
                                BidderName1$ = ReadString(Newbidfile)
                                ;Change strings

                                SellerName2$ = SellerName1
                                CurItemName2$ = CurItemName1
                                ItemQunty2% = ItemQunty1
                                BidCost2% = BidCost1
                                BuyoutCost2% = BuyoutCost1
                                BidderName2$ = BidderName1
                                Doevents(2)

                              ;write to file based on if there is changes or not.
                               If (CurItemName = CurItemName2)

                                 TakeItemQ% = ItemQunty2 - 1
                                 If (TakeItemQ <= 0)
                                 Takeline% = 1 ;if item has no more qun then set the write from temp to take a line away.
                                 ;output(player, "No item left")
                                 Else
                                        WriteString(TempFile, SellerName2)
                                        WriteString(TempFile, CurItemName2)
                                        WriteString(TempFile, TakeItemQ)
                                        WriteString(TempFile, BidCost2)
                                        WriteString(TempFile, BuyoutCost2)
                                        WriteString(TempFile, BidderName2) ;LINE 6 write extra line that will store current bidder.
                                 EndIf

                               Else

                                ;if item is not the item that has been bought then copy from text with no changes.
                                WriteString(TempFile, SellerName2)
                                WriteString(TempFile, CurItemName2)
                                WriteString(TempFile, ItemQunty2)
                                WriteString(TempFile, BidCost2)
                                WriteString(TempFile, BuyoutCost2)
                                WriteString(TempFile, BidderName2) ;LINE 6 write extra line that will store current bidder.

                               EndIf
                               ;Endfile% = Eof(Newbidfile)
                               ;Endfile1% = Eof(TempFile)

                       Until (TotSellerAuction = 0)

                               CloseDialog(Player, ChatBox)

                               CloseFile(Newbidfile)
                               CloseFile(TempFile)
;------------------------------------------------------------------------------------------
;------------------------------MAKE NEW AUCTION FILE----------BUY OUT----------------------

;---------------------------------------------------------------------------------------------
 ;---------------------------------------------------------------------------------------------
  ;---------------------------------------------------------------------------------
  ;Rewrite player auction file with updates.
                               DeleteFile(+ Sellername + " Auctions.txt") ; delete file so it can be re writen
                                If (Takeline% = 1)
                                    TotSellerAuction2% = TotSellerAuction2 - 1
                                Else ;there is still quntinity for this item so make sure to add it.
                                    TotSellerAuction2% = TotSellerAuction2
                                EndIf
                               Newbidfile$ = ReadFile(+ Sellername + " Temp Auctions.txt")
                               TempFile$ = WriteFile(+ Sellername + " Auctions.txt") ;write to temp file then back to real file.

                             Repeat

                              TotSellerAuction2% = TotSellerAuction2 - 1
                               ;Rewrite file to add updates.
                               Doevents(2)

                                SellerName1$ = ReadString(Newbidfile)
                                CurItemName1$ = ReadString(Newbidfile)
                                ItemQunty1$ = ReadString(Newbidfile)
                                BidCost1$ = ReadString(Newbidfile)
                                BuyoutCost1$ = ReadString(Newbidfile)
                                BidderName1$ = ReadString(Newbidfile)
                                ;Change strings

                                SellerName2$ = SellerName1
                                CurItemName2$ = CurItemName1
                                ItemQunty2% = ItemQunty1
                                BidCost2% = BidCost1
                                BuyoutCost2% = BuyoutCost1
                                BidderName2$ = BidderName1
                                Doevents(2)

                             ;write to file based on if there is changes or not.

                                ;if item is not the item that was bid on then copy from text with no changes.
                                WriteString(TempFile, SellerName2)
                                WriteString(TempFile, CurItemName2)
                                WriteString(TempFile, ItemQunty2)
                                WriteString(TempFile, BidCost2)
                                WriteString(TempFile, BuyoutCost2)
                                WriteString(TempFile, BidderName2) ;LINE 6 write extra line that will store current bidder.

                               ;Endfile% = Eof(Newbidfile)
                               ;Endfile1% = Eof(TempFile)

                            Until (TotSellerAuction2 = 0)

                               CloseFile(Newbidfile)
                               CloseFile(TempFile)

;-------------------------------End buy out remake file-------------------------------------
;------------------------------------------------------------------------------------------
                    EndIf ;end if for seller item cheak delete if there is no items left to add.

                DeleteFile(+ Sellername + " Temp Auctions.txt") ;delete temp file since it is not needed anymore.
                Return
              EndIf ;end remake auction file
            Return
            EndIf ;end item quntity check

          Else
              DialogOutPut(Player, ChatBox, "You do not have enough gold for this item.", 203, 123, 234)
            DialogInput(Player, ChatBox, "Close")
            CloseDialog(Player, Chatbox)
          ;  CloseFile(PlayerAuctions1)
            Return
          EndIf

      Elseif (BuyOption = 3) ; Close
      CloseDialog(Player, ChatBox)
      Return
      EndIf

   EndIf
  Return
  EndIf

  ;------------POST AUCTION----------------
If (POption = 2)); Allow player to post an action

        CloseDialog(Player, ChatBox)
        ChatBox$ = OpenDialog(Player, Target, "Auction House", 521)
        DialogOutPut(Player, ChatBox, "What item would you like to place on the Auction House?", 200, 230, 25)
        DoEvents(250)
        DialogOutput(Player, Chatbox, "Please type in the name of the item, you would like to add to the auction.", 200, 230, 25)

        PInput$ = Input(Player, "Auction Item", "", 0)
        AHItemName$ = PInput
        OutPut(Player, "You have entered " + PInput, 245, 456, 23)

        ;----------Read amount of items in file -------
        ;----------------------------------------------
        Newbidfile1$ = OpenFile(+ Pname + " Auctions.txt")

            If (Newbidfile1 = 0) ;write new auction file for player.
                MakeAuction$ = WriteFile(+ Pname + " Auctions.txt")
                CloseFile(MakeAuction)
                SellerAuction = 0

             Else

        ;Count items in auction
        SellerAuction% = 0  ;when reading this need to be 0 if writing this needs to be 1

                Repeat
                  ;count items in file

                  ;fileCheck$ = ReadLine(Newbidfile1)

                  Doevents(12)
                  SellerAuction% = SellerAuction + 1

                                SellerName2$ = ReadString(Newbidfile1)
                                CurItemName2$ = ReadString(Newbidfile1)
                                ItemQunty2% = ReadString(Newbidfile1)
                                BidCost2% = ReadString(Newbidfile1)
                                BuyoutCost2% = ReadString(Newbidfile1)
                                BidderName2$ = ReadString(Newbidfile1)

                             ;Change strings
                                SellerName3$ = SellerName2
                                CurItemName3$ = CurItemName2
                                ItemQunty3% = ItemQunty2
                                BidCost3% = BidCost2
                                BuyoutCost3% = BuyoutCost2
                                BidderName3$ = BidderName2

                   EndFile% = Eof(Newbidfile1)

                         If (EndFile = 1)
                                EndFile = 1
                          EndIf

                       If (CurItemName3 = AHItemName)
                            ItemtoaddQ$ = CurItemName3
                            EndFile = 1
                            TotSellerAuction% = SellerAuction + 1 ;total of names in list with auctions.
                            TotSellerAuction2% = SellerAuction + 1
                        EndIf

                Until (EndFile = 1)
                CloseFile(Newbidfile1)
               ; closeFile(fileCheck)
       ;---------------------------------------------
       ;---------------------------------------------

             EndIf ; end write file

        ;Check if player has item
        PHasItem$ = HasItem(Player, PpInput, 1)

            If Not (HasItem(Player, PInput, 1))

                        DialogOutput(Player, ChatBox, "You do not have that item.", 200, 230, 25)
                        DialogInput(Player, ChatBox, "Ok")
                        CloseDialog(Player, ChatBox)
                        Return
             EndIf

                If (ItemtoaddQ = AHItemName) ;tell player that the bid amount and buyout will stay the same as the first item that was added to there auction list.
                DoEvents(100)
                CloseDialog(Player, ChatBox)
                ChatBox$ = OpenDialog(Player, Target, "Auction House", 521)

                    DialogOutPut(Player, ChatBox, "Bid and buyout amounts will stay the same as item curently in the list.", 200, 230, 25)
                    DialogInput(player, ChatBox, "Close")

                EndIf

                DoEvents(400)
                CloseDialog(Player, ChatBox)
                ChatBox$ = OpenDialog(Player, Target, "Auction House", 521)
                DialogOutPut(Player, ChatBox, "How many " + PInput + " would you like to place up for auction?", 200, 230, 25)
                ItemAmt% = Input(Player, "Item Quantity", "", 2)

                ;check if player has amount imputed.
                Totheld% = HasItem(Player, ItemAmt)

                    If Not (HasItem(Player, PInput, ItemAmt))

                            DialogOutPut(Player, ChatBox, "You do not have that many " + PInput, 255, 200, 26)
                            DialogInput(Player, ChatBox, "Ok")
                            DoEvents(800)
                            CloseDialog(Player, ChatBox)

                        Return
                    EndIf

                        DialogOutPut(Player, ChatBox, "Enter amount for bid price.", 225, 200, 26)
                        BidCost% = Input(Player, "Bid Price", "", 2)

                        DialogOutPut(Player, ChatBox, "What would you like the buyout cost to be?", 225, 200, 26)
                        BuyOutCost% = Input(Player, "Buyout Price", "", 2)

                        Doevents(500)

                        CloseDialog(Player, ChatBox)
                        ChatBox$ = OpenDialog(Player, Target, "Auction House", 521)

                        DialogOutPut(Player, Chatbox, "Please wait a second while, this info is tallyed for you.", 225, 200, 26)
                        DialogOutPut(Player, Chatbox, "A new window will popup for you to confirm your item post.", 225, 200, 26)
                        DialogInput(Player, ChatBox, "Ok")
                        CloseDialog(Player, ChatBox)

                        ChatBox$ = OpenDialog(Player, Target, "Auction House", 521)
                        DialogOutPut(Player, Chatbox, "Is this info correct?", 225, 200, 26)

                        ChatBox1$ = OpenDialog(Player, Target, "Confirm info", 521) ;confirm info

                        DialogOutPut(Player, ChatBox1, "Seller: " + PName, 145, 76, 165)
                        DialogOutPut(Player, ChatBox1, "Item Name: " + PInput  , 45, 76, 165)
                        DialogOutPut(Player, ChatBox1, "Item Amount: " + ItemAmt, 145, 76, 165)
                        DialogOutPut(Player, ChatBox1, "Item Bid Price: " + BidCost, 145, 76, 165)
                        DialogOutPut(Player, ChatBox1, "Item Buyout Price: " + BuyOutCost, 145, 76, 165)

                        POption1% = DialogInput(Player, ChatBox, "No,Yes")

                            If (POption1 = 1) ;close player had wrong info or cancled post.
                               DialogInput(Player, ChatBox, "Close")
                               CloseDialog(Player, ChatBox)
                               Return
                            EndIf

                            GiveItem(player, PInput, - ItemAmt)
                            CloseDialog(Player, ChatBox)
                            CloseDialog(Player, ChatBox1)
                            ;Continue with script.
                            PlayerAuctions2$ = OpenFile(+ PName + " Auctions.txt")

                                If (PlayerAuctions2 = 0) ;Player has no Auctions, make them a file.
                                    PAuctionsFile$ = WriteFile(+ PName + " Auctions.txt")
                                    DoEvents(500) ;wait 1 sec then close files

                                    WriteString(PAuctionsFile, + Pname) ;seller name
                                    WriteString(PAuctionsFile, + PInput) ;item name
                                    WriteString(PAuctionsFile, + ItemAmt) ;item amount
                                    WriteString(PAuctionsFile, + BidCost) ;bid price
                                    WriteString(PAuctionsFile, + BuyOutCost) ;buyout cost
                                    WriteString(PAuctionsFile, 0) ;LINE 6 write extra line that will store current bidder.
                                    CloseFile(PAuctionsFile) ;close  file that is made
                                 Else
                                    CloseFile(PlayerAuctions2) ;close open file
                                    CloseFile(PAuctionsFile)

;---------------------------------------------------
 ;player has an auction already, so add to the file.

 ;---------------------------------------------
               If (ItemtoaddQ = AHItemName)       ;if players item is not in the list then add a freah one.
                        ;ADD QUANTITY TO ITEMS ALREADY IN AUCTIONS.
;---------------------------------------------------------------------------------------------
;------------------------- MAKE TEMP FILE ------------------POST AUCTION-----------
;-----------------------------------------------------------ADD QUANTITIY TO ITEMS IN LIST-----

                               Newbidfile5$ = ReadFile(+ PName + " Auctions.txt")
                               TempFile5$ = WriteFile(+ PName + " Temp Auctions.txt") ;write to temp file then back to real file.
                                TotSellerAuction1% = 0
                             Repeat

                               SellerAuction% = SellerAuction - 1
                               ;Rewrite file to add updates.
                               Doevents(2)

                                SellerName1$ = ReadString(Newbidfile5)
                                CurItemName1$ = ReadString(Newbidfile5)
                                ItemQunty1$ = ReadString(Newbidfile5)
                                BidCost1$ = ReadString(Newbidfile5)
                                BuyoutCost1$ = ReadString(Newbidfile5)
                                BidderName1$ = ReadString(Newbidfile5)

                                ;Change strings
                                SellerName2$ = SellerName1
                                CurItemName2$ = CurItemName1
                                ItemQunty2% = ItemQunty1
                                BidCost2% = BidCost1
                                BuyoutCost2% = BuyoutCost1
                                BidderName2$ = BidderName1
                                Doevents(2)
                            TotSellerAuction1% = TotSellerAuction1 + 1
                             ;write to file based on if there is changes or not.

                               If (ItemtoaddQ = CurItemName2)
                                 TotItemQ% = ItemQunty2 + ItemAmt

                                ;If items is the item that was bid on then change bid price and add a string.
                                WriteString(TempFile5, SellerName2)
                                WriteString(TempFile5, CurItemName2)
                                WriteString(TempFile5, TotItemQ) ;new bid to add to file.
                                WriteString(TempFile5, BidCost2)
                                WriteString(TempFile5, BuyoutCost2)
                                WriteString(TempFile5, BidderName2)

                               Else

                                ;if item is not the item that was bid on then copy from text with no changes.
                                WriteString(TempFile5, SellerName2)
                                WriteString(TempFile5, CurItemName2)
                                WriteString(TempFile5, ItemQunty2)
                                WriteString(TempFile5, BidCost2)
                                WriteString(TempFile5, BuyoutCost2)
                                WriteString(TempFile5, BidderName2)
                               EndIf
                               ;Endfile% = Eof(Newbidfile)
                               ;Endfile1% = Eof(TempFile)

                             Until (SellerAuction = 0)
                                TotSellerAuction2% = TotSellerAuction1
                              ; CloseFile(SellerName1)
                              ; CloseFile(CurItemName1)
                              ; CloseFile(ItemQunty1)
                              ; CloseFile(BidCost1)
                               ;CloseFile(BuyoutCost1)
                             CloseFile(TempFile5)
                               CloseFile(Newbidfile5)

                              DeleteFile(+ PName + " Auctions.txt") ; delete file so it can be re writen

                  Doevents(30)

                  ;---------------------------------------------------------------------------------------------
 ;---------------------------------------------------------------------------------------------
  ;---------------------------------------------------------------------------------
  ;Rewrite player auction file with updates.

                               Output(player, " amount to write " + TotSellerAuction2)
                               Newbidfile1$ = ReadFile(+ PName + " Temp Auctions.txt")
                               TempFile1$ = WriteFile(+ PName + " Auctions.txt") ;write to temp file then back to real file.

                             Repeat

                               TotSellerAuction2% = TotSellerAuction2 - 1
                               ;Rewrite file to add updates.
                               Doevents(2)

                                SellerName1$ = ReadString(Newbidfile1)
                                CurItemName1$ = ReadString(Newbidfile1)
                                ItemQunty1$ = ReadString(Newbidfile1)
                                BidCost1$ = ReadString(Newbidfile1)
                                BuyoutCost1$ = ReadString(Newbidfile1)
                                BidderName1$ = ReadString(Newbidfile1)

                                ;Change strings
                                SellerName2$ = SellerName1
                                CurItemName2$ = CurItemName1
                                ItemQunty2% = ItemQunty1
                                BidCost2% = BidCost1
                                BuyoutCost2% = BuyoutCost1
                                BidderName2$ = BidderName1
                                Doevents(2)

                             ;write to file based on if there is changes or not.
                              ; If (PInput = ItemtoaddQ)
                              ;   TotItemQ% = ItemQunty2 + ItemAmt

                                ;If items is the item that was bid on then change bid price and add a string.
                              ;  WriteString(TempFile, SellerName2)
                              ;  WriteString(TempFile, CurItemName2)
                              ;  WriteString(TempFile, TotItemQ)
                              ;  WriteString(TempFile, BidCost2) ;new bid to add to file.
                              ;  WriteString(TempFile, BuyoutCost2)
                              ;  WriteString(TempFile, BidderName2)
                              ; Else

                                ;if item is not the item that was bid on then copy from text with no changes.
                                WriteString(TempFile1, SellerName2)
                                WriteString(TempFile1, CurItemName2)
                                WriteString(TempFile1, ItemQunty2)
                                WriteString(TempFile1, BidCost2)
                                WriteString(TempFile1, BuyoutCost2)
                                WriteString(TempFile1, BidderName2)
                              ; Endif
                               ;Endfile% = Eof(Newbidfile)
                               ;Endfile1% = Eof(TempFile)

                             Until (TotSellerAuction2 <= 0)

                              ; CloseFile(SellerName1)
                              ; CloseFile(CurItemName1)
                               CloseFile(TempFile1)
                               CloseFile(Newbidfile1)

                                DeleteFile(+ Pname + " Temp Auctions.txt") ;delete temp file since it is not needed anymore.

                        CloseDialog(Player, ChatBox)

 ;---------------------------------------------------------------------------------------------
;---------------------------------------------------------------------------------------------
 ;---------------------------------------------------------------------------------------------
;---------------------------------------------------------------------------------------------
 ;---------------------------------------------------------------------------------------------

                     EndIf ;item inputed is not in players auction list.

                    ;Contiue script players item is not in list.

        ;-------Make file and add player name to auction list.------------------------

                                PlayerAuctions1$ = OpenFile(+ PName + " Auctions.txt")

                                    Repeat

                                        fileCheck$ = ReadLine(PlayerAuctions1)
                                        EndFile% = Eof(PlayerAuctions1)
                                        Doevents(10)
                                    Until (EndFile = 1)

                                    WriteString(PlayerAuctions1, + Pname) ;seller name
                                    WriteString(PlayerAuctions1, + PInput) ;item name
                                    WriteString(PlayerAuctions1, + ItemAmt) ;item amount
                                    WriteString(PlayerAuctions1, + BidCost) ;bid price
                                    WriteString(PlayerAuctions1, + BuyOutCost) ;buyout cost
                                    WriteString(PlayerAuctions1, 0) ;LINE 6 write extra line that will store current bidder.

                                    Closefile(fileCheck)
                                    CloseFile(PlayerAuctions1) ;close open file
;---------------------------------------------------
                                    ;no need to stop script just wait a few seconds then continue
                                    DoEvents(200)
                                 EndIf

                  EndIf
        ;--------------------------------------------------------------------
        ;--------------------------------------------------------------------
        ;--------------------------------------------------------------------
        ;make auction file to keep track of names of sellers.

                            sellerAuctions$ = OpenFile("Auction-Sellers.txt")

                            If (sellerAuctions = 0)
                      ;Make auction file
                                AuctionsSellerFile$ = WriteFile("Auction-Sellers.txt")
                                WriteLine(AuctionsSellerFile, + Pname) ;seller name
                                DoEvents(500) ;wait 1 sec then close files
                                CloseFile(AuctionsSellerFile)
                            Else
                     ;if player does not have a auction then add there name to the list.
                                AddName% = 0
                                Repeat
                                  fileCheck$ = ReadLine(sellerAuctions)

                                  Doevents(10)

                                    If (fileCheck = PName) ;check if player is in the list

                                        EndRe = 1
                                    Else
                                        EndRe%= 1
                                        AddName% = 1
                                    EndIf

                                    EndRe% = Eof(sellerAuctions)

                                Until (EndRe = 1)

                                    If (AddName = 1)
                                       output(player, "Write name")
                                        ;player is not in the list so add there name to it.
                                        WriteLine(sellerAuctions, PName) ;seller name
                                    EndIf
                            EndIf

;--------------------------------------------------------------------
              CloseFile(sellerAuctions)
              CloseDialog(Player, ChatBox)

If (POption = 3) ;check if any Auctions sold and recive payment.
    ;Show options based on if player has money waiting or not.

     PlayerPaymentfile$ = OpenFile(+ Pname + "Payment.txt")

    If (PlayerPaymentfile = 0) ;if there is no payment for player then show this dialog.
        CloseDialog(Player, ChatBox)
        ChatBox$ = OpenDialog(Player, Target, + Pname + "s Auctions", 521)

    Else ;if there is a payment show this.
        TOPayamount% = ReadLine(PlayerPaymentfile)

          CloseDialog(Player, ChatBox)
        ChatBox$ = OpenDialog(Player, Target, + TOPayamount + " Gold is waiting!!!", 521)
        DialogOutPut(Player, ChatBox, "Would you like to collect your money?", 230, 145, 45)
        POption% = DialogInput(Player, ChatBox, "No,Yes")

            If (POption = 2) ;Give player payment then continue with script.
                CloseDialog(Player, ChatBox)
                ChatBox$ = OpenDialog(Player, Target, "", 521)
               ;AUCTION FEES 2%
                TotAHFee% = AuctionFee * TOPayamount

                    If (TotAHFee <= 0) ;set AH fee to min 1 gold
                     TotAHFee% = 1
                    EndIf

                  Totauctionfee% = TOPayamount - TotAHFee ; auction fee set in options part at begining.
                NewMoneyAmount% = Totauctionfee + Pmoney
                 ;give payment - auction fees
                  DialogOutPut(Player, chatBox, "You have " + TOPayamount + " gold that is owed to you, the auction fees on this will be " + TotAHFee + " gold", 230, 145, 234)
                  DialogInput(Player, ChatBox, "Recive Payment")

                  DialogOutPut(Player, ChatBox, "You have recived a Payment of " + Totauctionfee + " Gold", 230, 45, 245)
                  SetMoney(Player, NewMoneyAmount)
                  DialogInput(Player, ChatBox, "Close")
                  DoEvents(30)
                  CloseDialog(Player, ChatBox)
                  CloseFile(PlayerPaymentfile) ;close payment file above
                  DeleteFile(+ Pname + "Payment.txt") ; delete payment file since player has been payed.
                  ;Countinue and show player the auctions
            EndIf

    EndIf

          PlayerPaymentfile$ = OpenFile(+ Pname + "Payment.txt")

    If (PlayerPaymentfile = 1) ;if there is a payment file then close it.
        CloseFile(PlayerPaymentfile) ;close payment file above
    EndIf

            HasAuction$ = ReadFile(+ Pname + " Auctions.txt")

        If (HasAuction = 0) ; player has no auctions.
         CloseDialog(Player, ChatBox)
          ChatBox$ = OpenDialog(Player, Target, + Pname + "s Auctions", 521)
          DialogOutPut(Player, ChatBox, "You do not have any auctions to show.", 230, 145, 23)
          DialogInPut(Player, Chatbox, "Close")
          CloseDialog(Player, ChatBox)
          DeleteFile("Auction-Sellers.txt")
          CloseFile(HasAuction)
        Return
          EndIf

        CloseFile(HasAuction)

     ;Countinue script and show player there auctions.

     PlayerAuctions3$ = ReadFile(+ Pname + " Auctions.txt")
    Repeat
          CloseDialog(Player, ChatBox)
        ChatBox$ = OpenDialog(Player, Target, "Search Auction House", 521)
    ;Read sellers info
          Readline1$ = ReadString(PlayerAuctions3) ;seller name
          Readline2$ = ReadString(PlayerAuctions3) ;item name
          Readline3$ = ReadString(PlayerAuctions3) ;item qun
          Readline4$ = ReadString(PlayerAuctions3) ; bid cost
          Readline5$ = ReadString(PlayerAuctions3) ; buyout cost
          Readline6$ = Readstring(PlayerAuctions3) ; name of player that bid if any.

            SellerName$ = Readline1
            CurItemName$ = Readline2
            ItemQunty% = Readline3
            BidCost% = Readline4
            BuyoutCost% = Readline5
            Biddername$ = Readline6

            EndFile% = Eof(PlayerAuctions3)

         If (Biddername = 0) ; if there is no bider show this.

            DialogOutPut(Player, Chatbox, "Seller Name: " + SellerName, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "Item Name: " + CurItemName, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "Item Quantity: " + ItemQunty, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "Bid Cost: " + BidCost, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "BuyOut Cost: " + BuyoutCost, 200, 132, 23)

                        If (Endfile = 1)
                            DialogOutPut(Player, Chatbox, "Last item in list.", 244, 132, 23)
                            DialogInput(Player, ChatBox, "Close")
                        Else
                            DialogInput(Player, ChatBox, "Next")
                        EndIf

          Else ; if there is a bidder show this.
            DialogOutPut(Player, Chatbox, "Seller Name: " + SellerName, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "Item Name: " + CurItemName, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "Item Quantity: " + ItemQunty, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "Bid Cost: " + BidCost, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "BuyOut Cost: " + BuyoutCost, 200, 132, 23)
            DialogOutPut(Player, Chatbox, "Current Bidder: " + Biddername, 200, 132, 23)
                        If (Endfile = 1)
                            DialogOutPut(Player, Chatbox, "Last item in list.", 244, 132, 23)
                            DialogInput(Player, ChatBox, "Close")
                        Else
                            DialogInput(Player, ChatBox, "Next")
                        EndIf
          EndIf

              Doevents(5)

     Until (Endfile = 1)
           CloseDialog(Player, ChatBox)
           CloseFile(PlayerAuctions3)

EndIf ;end show player there auctions and give payment

End Function

```