PVP Battle Organizer Script

*Created by Taz.*

```
Using "RC_Core.rcm"
; testingrc1 1.26
; Date/Time: 3:53:32 PM on 1/2/2012
; By Naddaz on NADCO
; Pvp Battleground organizer

;Superglobal 2 will store name of player to start pvp battle
;using super global 3 for hold flag

;only going to allow for 1 inctance right now

;Note remember to set supergloabl 2 back to 0 or ""

Function Main()

Player = Actor()
Target = ContextActor()
BgName$ = "Pvp Zone" ;name of pvp zone

        ;bg kill count to 0
        Bgkills% = Split(ActorGlobal(Player, 3), 20, "|")

                If (Bgkills > 0)

                ;-----------------------------------------------------------------------------------------------------------
    ;Set changes to delimiter

             HealthStat% = Split(ActorGlobal(Player, 3), 1, "|")
            ManaStat% = Split(ActorGlobal(Player, 3), 2, "|")
            StrStat% = Split(ActorGlobal(Player, 3), 3, "|")
            TouStat% = Split(ActorGlobal(Player, 3), 4, "|")
            DefStat% = Split(ActorGlobal(Player, 3), 5, "|")
            AgiStat% = Split(ActorGlobal(Player, 3), 6, "|")
            WizStat% = Split(ActorGlobal(Player, 3), 7, "|")
            StatsCurr% = Split(ActorGlobal(Player, 3), 8, "|")
            StBak% = Split(ActorGlobal(Player, 3), 9, "|")
            RepCurr% = Split(ActorGlobal(Player, 3), 10, "|")     ;player rep
            Gamble% = Split(ActorGlobal(Player, 3), 11, "|")      ;used in gambling
            ClassStored% = Split(ActorGlobal(Player, 3), 12, "|") ;stores melee, ranging and magic
            InOutCombat% = Split(ActorGlobal(Player, 3), 13, "|")  ;use in tracker in and out of combat
            ;extra delimters for things that mybe needed later.
            Extra1% = Split(ActorGlobal(Player, 3), 14, "|")
            Extra2% = Split(ActorGlobal(Player, 3), 15, "|")
            Extra3% = Split(ActorGlobal(Player, 3), 16, "|")
            Extra4% = Split(ActorGlobal(Player, 3), 17, "|")
            Extra5% = Split(ActorGlobal(Player, 3), 18, "|")
            Extra6% = Split(ActorGlobal(Player, 3), 19, "|")
            Extra7% = 0
            Extra8% = Split(ActorGlobal(Player, 3), 21, "|")

        SetActorGlobal(Player, 3, OtherThingsToStore) ;set dilimiter to actor global 3

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

     Chatbox$ = OpenDialog(Player, Target, "Pvp Organizer")
    DialogOutPut(Player, ChatBox, "Entering you in queue")

   PvpBgStarted% = ZoneInstanceExists(BgName, 1) ;check if there is an pvp inctance already, if there is make a new one.
OutPut(Player, "Zone = " + PvpBgStarted)
 CloseDialog(Player, Chatbox) ;close chatbox
        If (PvpBgStarted = 1) ;there is a pvp zone already, see if there is room or if a new one should be made.
            ;there is a pvp inctance already see if there is room and add player if there is
            ;make new inctance here when ready to add extras
             OutPut(Player, "There is an inctance already", 255, 0, 0)
                         ;Make super global delimiter if there is no pvp zones made yet.
                ;Set changes to delimiter

             Pvpname1$ = 0
            Pvpname2$ = 0
            Pvpname3$ = 0
            Pvpname4$ = 0
            Pvpname5$ = 0
            Pvpname6$ = 0
            Pvpname7$ = 0
            Pvpname8$ = 0
            Pvpname9$ = 0
            Pvpname10$ = 0

        SetSuperGlobal(2, PvpZoneLeaders) ;set dilimiter to super global 2
             Return

         EndIf

     If (PvpBgStarted = 0) ;there is no inctance make one.

        ; PlayerCurrInc% = Split(ActorGlobal(Player, 3), 19, "|")

           ;      If (PlayerCurrInc > 0) ;player is in q already or in an inctance already
          ;          OutPUt(Player, "You are already in queue for a pvp battleground.")
          ;          CloseDialog(Player, Chatbox)
          ;          Return
          ;      Endif

     ;Make inctance text file to hold player names
        Pname$ = Split(SuperGlobal(2), 1, "|")  ;Retrive leader and name of master list
            If (Pname = "") or (Pname = 0) ;if there is no stored name then use players name and set it.
               Pname$ = Name(Player) ;will be leader and name of master list
            ;Make super global delimiter if there is no pvp zones made yet.
                ;Set changes to delimiter

             Pvpname1$ = Pname
            Pvpname2$ = 0
            Pvpname3$ = 0
            Pvpname4$ = 0
            Pvpname5$ = 0
            Pvpname6$ = 0
            Pvpname7$ = 0
            Pvpname8$ = 0
            Pvpname9$ = 0
            Pvpname10$ = 0

        SetSuperGlobal(2, PvpZoneLeaders) ;set dilimiter to super global 2
            EndIf

            OutPut(Player, "Name of file check " + Pname)
        ;Pname$ = Name(player)
        PvpFileName$ = + Pname + "Master PvPBg.Txt"
        PvpFileCheck$ = OpenFile(PvpFileName)

             If (PvpFileCheck >= 1) ;add player to list
                  ;make sure player is not in list before addeding
  ;output(player, "adding you to list")
                  CurrPname$ = Name(Player)
                  Repeat
                    CheckName$ = ReadLine(PvpFileCheck)

                      If (CheckName = CurrPname) ;tell player they are already in queue
                            OUtPUt(Player, "You are already in queue, you will be notified when there is enough players.", 255, 200, 8)
                            CloseFile(PvpFileCheck)
                           Return
                      EndIf
                  OUtpUT(Player, "checking list")

                    DoEvents(10)
                   EndofFile% = Eof(PvpFileCheck)
                  Until (EndofFile = 1)

                  WriteLine(PvpFileCheck, CurrPname) ;write players name to next line.
                 CloseFile(PvpFileCheck) ;close opened file above

            Else ;make master file if super global 2 is empty
                output(Player, "Making new file")
                CloseFile(PvpFileCheck) ;close opened file above
                FileWrite$ = WriteFile(+ Pname + "Master PvPBg.Txt") ;make file

                CloseFile(FileWrite)

                PvpFileName$ = + Pname + "Master PvPBg.Txt"
                PvpFileCheck3$ = OpenFile(PvpFileName)

                WriteLine(PvpFileCheck3, Pname) ;write leader name on line one.

                CloseFile(PvpFileCheck3) ;close opened file above
                ;set first player to leader for pvp instance
                 ;OutPut(Player, "Made new file")
                 Chatbox$ = OpenDialog(Player, Target, "Pvp Organizer")
                 DialogOutPut(Player, ChatBox, "You have been added to the queue, you will be warped to the pvp zone when there is enough players.")
                 DialogInput(Player, ChatBox, "Close")
                 CloseDialog(Player, Chatbox) ;close chatbox
                 Return

            EndIf

            CloseDialog(Player, Chatbox) ;close chatbox
    EndIf ;end make inctance if none

     ;Count players waiting in queue
        Pname$ = Split(SuperGlobal(2), 1, "|") ;Retrive leader and name of master list
        PvpFileName$ = + Pname + "Master PvPBg.Txt"
        PvpFileCheck$ = OpenFile(PvpFileName)
        AmountReady% = 0
        rewritelist% = 0
                Repeat
                    PvpQue$ = ReadLine(PvpFileCheck) ; read name from file

                    OutPut(Player, "Name to read " + PvpQue)
                    FinePlayer$ = FindActor(PvpQue, 1)
                    PlayerOnline% = PlayerInGame(FinePlayer)

                           If (PvpQue = "") ;if not reading a blank line then player is offline.
                                EndFile = 1
                                PlayerOnline = 0
                            EndIf

                        If (PlayerOnline >= 1) ;if player in list online add 1 to count
                           If (EndFile = 0)
                            AmountReady% = AmountReady + 1
                             OutPut(Player, "Name to read is online")
                           EndIf
                        Else    ;player in list is offline rewrite file - player in list.

                            If (EndFile = 0)

                              rewritelist% = 1
                              PlayerOffline$ = PvpQue
                              EndFile = 1
                            EndIf
                        EndIf ;end rewrite of players in queue

                  DoEvents(10)
             ;    EndFile% = Eof(PvpFileCheck)

                 Until (EndFile = 1)

         CloseFile(PvpFileCheck) ;close opened file above

         If (rewritelist = 1) ;player in list is offline rewrite file

                 Pname$ = Split(SuperGlobal(2), 1, "|")  ;Retrive leader and name of master list

                PvpFileName$ = + Pname + "Master PvPBg.Txt"
                PvpFileCheck$ = OpenFile(PvpFileName)

                 TempPvpFileName$ = + Pname + "TempMaster PvPBg.Txt"
                MakeTempFile$ = WriteFile(+ Pname + "TempMaster PvPBg.Txt") ;write new temp list
                CloseFile(MakeTempFile)

                TempPvpFileCheck$ = OpenFile(TempPvpFileName)
               ; WriteLine(TempPvpFileCheck, Name(Player)) ;add curr player to list
                AmountReady3 = AmountReady
                Countforrewrite% = AmountReady - 1
                    Repeat
           ; output(Player, "Player in list is offline")
                        ReadCurrLine$ = ReadLine(PvpFileCheck)

                    If Not (PlayerOffline = Pname) ;if offline player is leader dont add the name
                        If Not (ReadCurrLine = PlayerOffline)
                            WriteLine(TempPvpFileCheck, ReadCurrLine)
                            Countforrewrite% = Countforrewrite - 1
                        EndIf ;change leader name since leader is offline
                    EndIf

                        If (ReadCurrLine = "")
                            Countforrewrite = 0
                        EndIf

                         Doevents(10)
                    Until (Countforrewrite = 0)

                    CloseFile(PvpFileCheck)
                    CloseFile(TempPvpFileCheck)

                    DeleteFile(+ Pname + "Master PvPBg.Txt")

                TempPvpFileName$ = + Pname + "TempMaster PvPBg.Txt"
                Pname5$ = Split(SuperGlobal(2), 1, "|")
                MakeTempFile$ = OpenFile(TempPvpFileName) ;open temp folder before changing name

                    If Not (PlayerOffline = Pname5) ;leader is stilll online
                    OutPut(Player, "Keep old leader.")
                         MakeNewFile$ = WriteFile(+ Pname5 + "Master PvPBg.Txt")
                        CloseFile(MakeNewFile)
                        PvpFileName$ = + Pname5 + "Master PvPBg.Txt"
                        PvpFileCheck$ = OpenFile(PvpFileName)

                    Else ;if offline player is leader change txt name
                    OutPut(Player, "Write new leader.")
                            Pname$ = Name(Player)
                           MakeNewFile$ = WriteFile(+ Pname + "Master PvPBg.Txt")
                            CloseFile(MakeNewFile)
                            PvpFileName$ = + Pname + "Master PvPBg.Txt"
                            PvpFileCheck$ = OpenFile(PvpFileName)
                            WriteLine(PvpFileCheck, Pname)
                                        ;Make super global delimiter if there is no pvp zones made yet.
                ;Set changes to delimiter

                             Pvpname1$ = Pname
                            Pvpname2$ = Split(SuperGlobal(2), 2, "|")
                            Pvpname3$ = Split(SuperGlobal(2), 3, "|")
                            Pvpname4$ = Split(SuperGlobal(2), 4, "|")
                            Pvpname5$ = Split(SuperGlobal(2), 5, "|")
                            Pvpname6$ = Split(SuperGlobal(2), 6, "|")
                            Pvpname7$ = Split(SuperGlobal(2), 7, "|")
                            Pvpname8$ = Split(SuperGlobal(2), 8, "|")
                            Pvpname9$ = Split(SuperGlobal(2), 9, "|")
                            Pvpname10$ = Split(SuperGlobal(2), 10, "|")

                        SetSuperGlobal(2, PvpZoneLeaders) ;set dilimiter to super global 2
                    EndIf

                    Repeat

                        ReadCurrLine$ = ReadLine(MakeTempFile)

                            WriteLine(PvpFileCheck, ReadCurrLine)
                           Countforrewrite% = Eof(MakeTempFile)

                        Doevents(10)
                    Until (Countforrewrite = 1)
                CloseFile(PvpFileCheck)
                CloseFile(MakeTempFile)

                DeleteFile(+ Pname5 + "TempMaster PvPBg.Txt")

           EndIf ;end offline rewrite

        ;All players in list are still online, check if there is enough to start the match.
        AmountNeeded% = 5 ;amount of people needed to start a new inctance.
        AmountReady% = AmountReady ;amount of players in list from above online count.
                ;check if enough players to send to inctance.
            If (AmountReady = AmountNeeded) ;if there is enough players then make and send them to the inctance.
                ;Output(Player, "There is enough players make inctance, and tell all players. make emitter apper for player only when queue is ready, have them be able to type joinpvp or something when emitter is there.")
                CreateZoneInstance("pvp zone", 1) ;make inctance

                    ZoneNumSpawn% = 1
                    DoorID$ = ActorID("Block", "")
                    Spawn(DoorID, "pvp zone", 445.155, 30.3406, -3.94855, "", "", ZoneNumSpawn)

                    ;Get name of player in list, to tell them that the inctance is ready.
                    ;2 players for testing will be 5 players to go to inctance.

                    Pname$ = Split(SuperGlobal(2), 1, "|")  ;Retrive leader and name of master list

                        PvpFileName$ = + Pname + "Master PvPBg.Txt"
                        PvpFileCheck$ = OpenFile(PvpFileName)

                        ReadName1$ = ReadLine(PvpFileCheck)
                        ReadName2$ = ReadLine(PvpFileCheck)
                        ReadName3$ = ReadLine(PvpFileCheck)
                        ReadName4$ = ReadLine(PvpFileCheck)
                        ReadName5$ = ReadLine(PvpFileCheck)

                        CloseFile(PvpFileCheck)
                            FindName1$ = FindActor(ReadName1) ;find firt name in list
                        Chatbox$ = OpenDialog(FindName1, Target, "Pvp Organizer")
                        DialogOutPut(FindName1, ChatBox, "Click OK to enter the pvp battle ground", 255, 45, 234)
                        SetAttribute(FindName1, "PVPBG Points", 0) ;set to zero for bg
                        DialogInput(FindName1, ChatBox, "OK")
                        CloseDialog(FindName1, ChatBox)
                        Warp(FindName1, BgName, "StartBg", 1) ;Warp 1st player
                        DoEvents(1000)
                       ; PlayMusic(FindName1, 3, 0)
                        ;Tell 2nd player
                        FindName2$ = FindActor(ReadName2) ;find firt name in list
                        Chatbox$ = OpenDialog(FindName2, Target, "Pvp Organizer")
                        DialogOutPut(FindName2, ChatBox, "Click OK to enter the pvp battle ground", 255, 45, 234)
                         SetAttribute(FindName2, "PVPBG Points", 0) ;set to zero for bg
                        DialogInput(FindName2, ChatBox, "OK")
                        CloseDialog(FindName2, ChatBox)
                        Warp(FindName2, BgName, "StartBg", 1) ;Warp 2nd player
                        DoEvents(1000)
                        ;PlayMusic(FindName2, 3, 0)
                        ;Tell 3rd player
                        FindName3$ = FindActor(ReadName3) ;find firt name in list
                        Chatbox$ = OpenDialog(FindName3, Target, "Pvp Organizer")
                        DialogOutPut(FindName3, ChatBox, "Click OK to enter the pvp battle ground", 255, 45, 234)
                         SetAttribute(FindName3, "PVPBG Points", 0) ;set to zero for bg
                        DialogInput(FindName3, ChatBox, "OK")
                        CloseDialog(FindName3, ChatBox)
                        Warp(FindName3, BgName, "StartBg", 1) ;Warp 3rd player
                        DoEvents(1000)
                       ; PlayMusic(FindName3, 3, 0)
                         ;Tell 4th player
                        FindName4$ = FindActor(ReadName4) ;find firt name in list
                        Chatbox$ = OpenDialog(FindName4, Target, "Pvp Organizer")
                        DialogOutPut(FindName4, ChatBox, "Click OK to enter the pvp battle ground", 255, 45, 234)
                         SetAttribute(FindName4, "PVPBG Points", 0) ;set to zero for bg
                        DialogInput(FindName4, ChatBox, "OK")
                        CloseDialog(FindName4, ChatBox)
                        Warp(FindName4, BgName, "StartBg", 1) ;Warp 4th player
                        DoEvents(1000)
                       ;PlayMusic(FindName4, 3, 0)
                        ;Tell 5th player
                        FindName5$ = FindActor(ReadName5) ;find firt name in list
                        Chatbox$ = OpenDialog(FindName5, Target, "Pvp Organizer")
                        DialogOutPut(FindName5, ChatBox, "Click OK to enter the pvp battle ground", 255, 45, 234)
                         SetAttribute(FindName5, "PVPBG Points", 0) ;set to zero for bg
                        DialogInput(FindName5, ChatBox, "OK")
                        CloseDialog(FindName5, ChatBox)
                       Warp(FindName5, BgName, "StartBg", 1) ;Warp 5th player
                       DoEvents(1000)
                      ; PlayMusic(FindName5, 3, 0)

                ThreadExecute("Pvp_Startup", "Main", Player, 0) ;execute for player should run one time.

            Else
                 Chatbox$ = OpenDialog(Player, Target, "Pvp Organizer")
                 DialogOutPut(Player, ChatBox, "You have been added to the queue, you will be warped to the pvp zone when there is enough players.")
                 DialogInput(Player, ChatBox, "Close")
                 CloseDialog(Player, Chatbox) ;close chatbox
            EndIf
       ; OutPut(Player, "Count amount is " + AmountReady)

 End Function
 ;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------
;5 player pvp bg winner will be the player that holds the flag the longest.
Function HoldFlag() ;pvp organizer for hold the flag to win.

;using super global 3 for hold flag

Player = Actor()
Target = ContextActor()
BgName$ = "PvpHoldFlag" ;name of pvp zone

       ;bg kill count to 0
        Bgkills% = Split(ActorGlobal(Player, 3), 20, "|")

                If (Bgkills > 0)

                ;-----------------------------------------------------------------------------------------------------------
    ;Set changes to delimiter

             HealthStat% = Split(ActorGlobal(Player, 3), 1, "|")
            ManaStat% = Split(ActorGlobal(Player, 3), 2, "|")
            StrStat% = Split(ActorGlobal(Player, 3), 3, "|")
            TouStat% = Split(ActorGlobal(Player, 3), 4, "|")
            DefStat% = Split(ActorGlobal(Player, 3), 5, "|")
            AgiStat% = Split(ActorGlobal(Player, 3), 6, "|")
            WizStat% = Split(ActorGlobal(Player, 3), 7, "|")
            StatsCurr% = Split(ActorGlobal(Player, 3), 8, "|")
            StBak% = Split(ActorGlobal(Player, 3), 9, "|")
            RepCurr% = Split(ActorGlobal(Player, 3), 10, "|")     ;player rep
            Gamble% = Split(ActorGlobal(Player, 3), 11, "|")      ;used in gambling
            ClassStored% = Split(ActorGlobal(Player, 3), 12, "|") ;stores melee, ranging and magic
            InOutCombat% = Split(ActorGlobal(Player, 3), 13, "|")  ;use in tracker in and out of combat
            ;extra delimters for things that mybe needed later.
            Extra1% = Split(ActorGlobal(Player, 3), 14, "|")
            Extra2% = Split(ActorGlobal(Player, 3), 15, "|")
            Extra3% = Split(ActorGlobal(Player, 3), 16, "|")
            Extra4% = Split(ActorGlobal(Player, 3), 17, "|")
            Extra5% = Split(ActorGlobal(Player, 3), 18, "|")
            Extra6% = Split(ActorGlobal(Player, 3), 19, "|")
            Extra7% = 0
            Extra8% = Split(ActorGlobal(Player, 3), 21, "|")

        SetActorGlobal(Player, 3, OtherThingsToStore) ;set dilimiter to actor global 3

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

    Chatbox$ = OpenDialog(Player, Target, "Pvp Organizer, Hold Flag")
    DialogOutPut(Player, ChatBox, "Entering you in queue, HOLD FLAG")

   PvpBgStarted% = ZoneInstanceExists(BgName, 1) ;check if there is an pvp inctance already, if there is make a new one.
OutPut(Player, "Zone = " + PvpBgStarted)
 CloseDialog(Player, Chatbox) ;close chatbox
        If (PvpBgStarted = 1) ;there is a pvp zone already, see if there is room or if a new one should be made.
            ;there is a pvp inctance already see if there is room and add player if there is
            ;make new inctance here when ready to add extras
             OutPut(Player, "There is an inctance already", 255, 0, 0)

              ;for testing remove file and set super global back
             SetSuperGlobal(3, 0)
                BgName$ = "PvpHoldFlag" ;name of pvp zone
                RemoveZoneInstance(BgName, 1)
            ; Return

         EndIf

     If (PvpBgStarted = 0) ;there is no inctance make one.
       ; PlayerCurrInc% = Split(ActorGlobal(Player, 3), 19, "|")

           ;      If (PlayerCurrInc > 0) ;player is in q already or in an inctance already
          ;          OutPUt(Player, "You are already in queue for a pvp battleground.")
          ;          CloseDialog(Player, Chatbox)
          ;          Return
          ;      Endif

     ;Make inctance text file to hold player names
        Pname$ = Split(SuperGlobal(3), 1, "|")  ;Retrive leader and name of master list
            If (Pname = "") or (Pname = 0) ;if there is no stored name then use players name and set it.
               Pname$ = Name(Player) ;will be leader and name of master list
            ;Make super global delimiter if there is no pvp zones made yet.
                ;Set changes to delimiter

             Pvpname1$ = 0
            Pvpname2$ = 0
            Pvpname3$ = 0
            Pvpname4$ = 0
            Pvpname5$ = 0
            Pvpname6$ = 0
            Pvpname7$ = 0
            Pvpname8$ = 0
            Pvpname9$ = 0
            Pvpname10$ = 0

        SetSuperGlobal(3, PvpZoneLeaders) ;set dilimiter to actor global 3

             EndIf

            OutPut(Player, "Name of file check " + Pname)
        ;Pname$ = Name(player)
        PvpFileName$ = + Pname + "Master Holdflag PvPBg.Txt"
        PvpFileCheck$ = OpenFile(PvpFileName)

             If (PvpFileCheck >= 1) ;add player to list
                  ;make sure player is not in list before addeding
  ;output(player, "adding you to list")
                  CurrPname$ = Name(Player)
                  Repeat
                    CheckName$ = ReadLine(PvpFileCheck)

                      If (CheckName = CurrPname) ;tell player they are already in queue
                            OUtPUt(Player, "You are already in queue, you will be notified when there is enough players.", 255, 200, 8)
                            CloseFile(PvpFileCheck)
                           Return
                      EndIf
                  OUtpUT(Player, "checking list")

                    DoEvents(10)
                   EndofFile% = Eof(PvpFileCheck)
                  Until (EndofFile = 1)

                  WriteLine(PvpFileCheck, CurrPname) ;write players name to next line.
                 CloseFile(PvpFileCheck) ;close opened file above

            Else ;make master file if super global 2 is empty
                output(Player, "Making new file")
                CloseFile(PvpFileCheck) ;close opened file above
                FileWrite$ = WriteFile(+ Pname + "Master Holdflag PvPBg.Txt") ;make file

                CloseFile(FileWrite)

                PvpFileName$ = + Pname + "Master Holdflag PvPBg.Txt"
                PvpFileCheck3$ = OpenFile(PvpFileName)

                WriteLine(PvpFileCheck3, Pname) ;write leader name on line one.

                CloseFile(PvpFileCheck3) ;close opened file above
                ;set first player to leader for pvp instance
                 ;OutPut(Player, "Made new file")
                 Chatbox$ = OpenDialog(Player, Target, "Pvp Organizer")
                 DialogOutPut(Player, ChatBox, "You have been added to the queue, you will be warped to the pvp zone when there is enough players.")
                 DialogInput(Player, ChatBox, "Close")
                 CloseDialog(Player, Chatbox) ;close chatbox
                 Return

            EndIf

            CloseDialog(Player, Chatbox) ;close chatbox
    EndIf ;end make inctance if none

     ;Count players waiting in queue
        Pname$ = Split(SuperGlobal(3), 1, "|")  ;Retrive leader and name of master list
        PvpFileName$ = + Pname + "Master Holdflag PvPBg.Txt"
        PvpFileCheck$ = OpenFile(PvpFileName)
        AmountReady% = 0
        rewritelist% = 0
                Repeat
                    PvpQue$ = ReadLine(PvpFileCheck) ; read name from file

                    OutPut(Player, "Name to read " + PvpQue)
                    FinePlayer$ = FindActor(PvpQue, 1)
                    PlayerOnline% = PlayerInGame(FinePlayer)

                           If (PvpQue = "") ;if not reading a blank line then player is offline.
                                EndFile = 1
                                PlayerOnline = 0
                            EndIf

                        If (PlayerOnline >= 1) ;if player in list online add 1 to count
                           If (EndFile = 0)
                            AmountReady% = AmountReady + 1
                             ;OutPut(Player, "Name to read is online")
                           EndIf
                        Else    ;player in list is offline rewrite file - player in list.

                            If (EndFile = 0)

                              rewritelist% = 1
                              PlayerOffline$ = PvpQue
                              EndFile = 1
                            EndIf
                        EndIf ;end rewrite of players in queue

                  DoEvents(10)
             ;    EndFile% = Eof(PvpFileCheck)

                 Until (EndFile = 1)

         CloseFile(PvpFileCheck) ;close opened file above

         If (rewritelist = 1) ;player in list is offline rewrite file

                 Pname$ = Split(SuperGlobal(3), 1, "|")  ;Retrive leader and name of master list

                PvpFileName$ = + Pname + "Master Holdflag PvPBg.Txt"
                PvpFileCheck$ = OpenFile(PvpFileName)

                 TempPvpFileName$ = + Pname + "Master TempHoldflag PvPBg.Txt"
                MakeTempFile$ = WriteFile(+ Pname + "Master TempHoldflag PvPBg.Txt") ;write new temp list
                CloseFile(MakeTempFile)

                TempPvpFileCheck$ = OpenFile(TempPvpFileName)
               ; WriteLine(TempPvpFileCheck, Name(Player)) ;add curr player to list
                AmountReady3 = AmountReady
                Countforrewrite% = AmountReady - 1
                    Repeat
           ; output(Player, "Player in list is offline")
                        ReadCurrLine$ = ReadLine(PvpFileCheck)

                    If Not (PlayerOffline = Pname) ;if offline player is leader dont add the name
                        If Not (ReadCurrLine = PlayerOffline)
                            WriteLine(TempPvpFileCheck, ReadCurrLine)
                            Countforrewrite% = Countforrewrite - 1
                        EndIf ;change leader name since leader is offline
                    EndIf

                        If (ReadCurrLine = "")
                            Countforrewrite = 0
                        EndIf

                         Doevents(10)
                    Until (Countforrewrite = 0)

                    CloseFile(PvpFileCheck)
                    CloseFile(TempPvpFileCheck)

                    DeleteFile(+ Pname + "Master Holdflag PvPBg.Txt")

                TempPvpFileName$ = + Pname + "Master TempHoldflag PvPBg.Txt"
                Pname5$ = Split(SuperGlobal(3), 1, "|")
                MakeTempFile$ = OpenFile(TempPvpFileName) ;open temp folder before changing name

                    If Not (PlayerOffline = Pname5) ;leader is stilll online
                   ; OutPut(Player, "Keep old leader.")
                         MakeNewFile$ = WriteFile(+ Pname + "Master Holdflag PvPBg.Txt")
                        CloseFile(MakeNewFile)
                        PvpFileName$ = + Pname + "Master PvPBg.Txt"
                        PvpFileCheck$ = OpenFile(PvpFileName)

                    Else ;if offline player is leader change txt name
                  ;  OutPut(Player, "Write new leader.")
                            Pname$ = Name(Player)
                           MakeNewFile$ = WriteFile(+ Pname + "Master Holdflag PvPBg.Txt")
                            CloseFile(MakeNewFile)
                            PvpFileName$ = + Pname + "Master Holdflag PvPBg.Txt"
                            PvpFileCheck$ = OpenFile(PvpFileName)
                            WriteLine(PvpFileCheck, Pname)
                                        ;Make super global delimiter if there is no pvp zones made yet.
                ;Set changes to delimiter

             Pvpname1$ = Split(SuperGlobal(3), 1, "|")
            Pvpname2$ = Split(SuperGlobal(3), 2, "|")
            Pvpname3$ = Split(SuperGlobal(3), 3, "|")
            Pvpname4$ = Split(SuperGlobal(3), 4, "|")
            Pvpname5$ = Split(SuperGlobal(3), 5, "|")
            Pvpname6$ = Split(SuperGlobal(3), 6, "|")
            Pvpname7$ = Split(SuperGlobal(3), 7, "|")
            Pvpname8$ = Split(SuperGlobal(3), 8, "|")
            Pvpname9$ = Split(SuperGlobal(3), 9, "|")
            Pvpname10$ = Split(SuperGlobal(3), 10, "|")

        SetSuperGlobal(3, PvpZoneLeaders) ;set dilimiter to actor global 3

                     EndIf

                    Repeat

                        ReadCurrLine$ = ReadLine(MakeTempFile)

                            WriteLine(PvpFileCheck, ReadCurrLine)
                           Countforrewrite% = Eof(MakeTempFile)

                        Doevents(10)
                    Until (Countforrewrite = 1)
                CloseFile(PvpFileCheck)
                CloseFile(MakeTempFile)

                DeleteFile(+ Pname5 + "Master TempHoldflag PvPBg.Txt")
          EndIf ;end offline rewrite

         ;All players in list are still online, check if there is enough to start the match.
        AmountNeeded% = 5 ;amount of people needed to start a new inctance.
        AmountReady% = AmountReady ;amount of players in list from above online count.
                ;check if enough players to send to inctance.
            If (AmountReady = AmountNeeded) ;if there is enough players then make and send them to the inctance.
                ;Output(Player, "There is enough players make inctance, and tell all players. make emitter apper for player only when queue is ready, have them be able to type joinpvp or something when emitter is there.")
                CreateZoneInstance("PvpHoldFlag", 1) ;make inctance

                    ;Get name of player in list, to tell them that the inctance is ready.
                    ;2 players for testing will be 5 players to go to inctance.

                    Pname$ = Split(SuperGlobal(3), 1, "|")  ;Retrive leader and name of master list

                        PvpFileName$ = + Pname + "Master Holdflag PvPBg.Txt"
                        PvpFileCheck$ = OpenFile(PvpFileName)

                        ReadName1$ = ReadLine(PvpFileCheck)
                        ReadName2$ = ReadLine(PvpFileCheck)
                        ReadName3$ = ReadLine(PvpFileCheck)
                        ReadName4$ = ReadLine(PvpFileCheck)
                        ReadName5$ = ReadLine(PvpFileCheck)

                        CloseFile(PvpFileCheck)
                            FindName1$ = FindActor(ReadName1) ;find firt name in list
                        Chatbox$ = OpenDialog(FindName1, Target, "Pvp Organizer")
                        DialogOutPut(FindName1, ChatBox, "Click OK to enter the pvp battle ground", 255, 45, 234)
                         SetAttribute(FindName1, "PVPBG Points", 0) ;set to zero for bg
                        DialogInput(FindName1, ChatBox, "OK")
                        CloseDialog(FindName1, ChatBox)
                        Warp(FindName1, BgName, "StartBg", 1) ;Warp 1st player
                        DoEvents(1000)
                       ; PlayMusic(FindName1, 3, 0)
                        ;Tell 2nd player
                        FindName2$ = FindActor(ReadName2) ;find firt name in list
                        Chatbox$ = OpenDialog(FindName2, Target, "Pvp Organizer")
                        DialogOutPut(FindName2, ChatBox, "Click OK to enter the pvp battle ground", 255, 45, 234)
                         SetAttribute(FindName2, "PVPBG Points", 0) ;set to zero for bg
                        DialogInput(FindName2, ChatBox, "OK")
                        CloseDialog(FindName2, ChatBox)
                        Warp(FindName2, BgName, "StartBg", 1) ;Warp 2nd player
                        DoEvents(1000)
                        ;PlayMusic(FindName2, 3, 0)
                        ;Tell 3rd player
                        FindName3$ = FindActor(ReadName3) ;find firt name in list
                        Chatbox$ = OpenDialog(FindName3, Target, "Pvp Organizer")
                        DialogOutPut(FindName3, ChatBox, "Click OK to enter the pvp battle ground", 255, 45, 234)
                         SetAttribute(FindName3, "PVPBG Points", 0) ;set to zero for bg
                        DialogInput(FindName3, ChatBox, "OK")
                        CloseDialog(FindName3, ChatBox)
                        Warp(FindName3, BgName, "StartBg", 1) ;Warp 3rd player
                        DoEvents(1000)
                       ; PlayMusic(FindName3, 3, 0)
                         ;Tell 4th player
                        FindName4$ = FindActor(ReadName4) ;find firt name in list
                        Chatbox$ = OpenDialog(FindName4, Target, "Pvp Organizer")
                        DialogOutPut(FindName4, ChatBox, "Click OK to enter the pvp battle ground", 255, 45, 234)
                         SetAttribute(FindName4, "PVPBG Points", 0) ;set to zero for bg
                        DialogInput(FindName4, ChatBox, "OK")
                        CloseDialog(FindName4, ChatBox)
                        Warp(FindName4, BgName, "StartBg", 1) ;Warp 4th player
                        DoEvents(1000)
                       ;PlayMusic(FindName4, 3, 0)
                        ;Tell 5th player
                        FindName5$ = FindActor(ReadName5) ;find firt name in list
                        Chatbox$ = OpenDialog(FindName5, Target, "Pvp Organizer")
                        DialogOutPut(FindName5, ChatBox, "Click OK to enter the pvp battle ground", 255, 45, 234)
                         SetAttribute(FindName5, "PVPBG Points", 0) ;set to zero for bg
                        DialogInput(FindName5, ChatBox, "OK")
                        CloseDialog(FindName5, ChatBox)
                       Warp(FindName5, BgName, "StartBg", 1) ;Warp 5th player
                       DoEvents(1000)
                      ; PlayMusic(FindName5, 3, 0)

                ThreadExecute("Pvp_Startup", "HoldFlag", Player, 0) ;execute for player should run one time.

            Else
                 Chatbox$ = OpenDialog(Player, Target, "Pvp Organizer")
                 DialogOutPut(Player, ChatBox, "You have been added to the queue, you will be warped to the pvp zone when there is enough players.")
                 DialogInput(Player, ChatBox, "Close")
                 CloseDialog(Player, Chatbox) ;close chatbox
            EndIf
       ; OutPut(Player, "Count amount is " + AmountReady)

 Return

 End Function

```