PVP Return Flag Script

*Created by Taz.*

```
Using "RC_Core.rcm"
; testingrc1 1.26
; Date/Time: 11:26:24 PM on 11/11/2011
; By Naddaz on NADCO
;Flag_Fight
 ;Return flag trigger used.
;Using PVPBG Points attribute to tally player points.
;Amount to win game will be default 5 for now.
;When flag is returned, the flag will auto spawn.

;NOTE when map zone finished add multible flag spawn points.

;Attribute Pvp Coins will keep track of player coins so they can buy items with it later.

Function Main()
Player = Actor()
PName$ = Name(Player)
ScoreToWin% = 5 ;Change to amount of flag returns needed to win round.
BgName$ = "pvp zone" ;name of pvp zone
       ; TotalPoints% = Attribute(Player, "PVPBG Points") + 5 ;REMOVE AFTER TEST

;------------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------
;Make stat record file if there is none.
    SRF$ = OpenFile(+ PName + "StatRecord.txt")

      If (SRF = 0) ; If stat recored is not present make it, if already there then countinue.
           StatFile$ = WriteFile(+ PName + "StatRecord.txt")
           WriteLine(StatFile, 0) ;Write line 1 to 0 setting player pvp coins to 0
           DoEvents(200)
           CloseFile(SRF)
           CloseFile(StatFile)
     EndIf
             CloseFile(SRF)

;Read first line in stat recored to get pvp coins amount.
            StatRecord$ = + PName + "StatRecord.txt"
            ReadStatRec$ = OpenFile(StatRecord) ;open file as read only

             ReadLineStatRec$ = ReadLine(ReadStatRec) ;read first line in file.

 CurrentPvpCoins% = ReadLineStatRec ; get current amount of pvp coins that player has.
 TotalPvpCoins% = CurrentPvpCoins + 10  ; set to amount of pvp coins that should be given to winning player.

 ;Close file above
CloseFile(ReadStatRec)
;------------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------

FlaginTrigger$ = ActorInTrigger(Player, 0) ; check if held flag is in trigger.
HasFlagItem% = HasItem(Player, "Pvp Flag") ; check if player has the pvp flag
FlagID$ = ActorID("Pvp Flag", "BattleGround") ;flag Id

 ;OutPut(Player, "In trigger = " + FlaginTrigger)
;OutPut(Player, "has flag = " + HasFlagItem)

    If (ActorInTrigger(Player, 0)) ;player in trigger
     If (HasFlagItem = 1) ;player has flag then continue with script.

         TotalPoints% = Attribute(Player, "PVPBG Points") + 1 ;amount of flag returns plus this one.
        BubbleOutput(Player, "Flag turned in, by " + PName)

        BubbleOutput(Player, + PName + " Has " + TotalPoints + " Flag Returns.")
        SetMaxAttribute(Player, "PVPBG Points", TotalPoints)
        SetAttribute(Player, "PVPBG Points", TotalPoints)
        ;Take players score minus total needed and display remander to win.
        NewPointstoWin% = ScoreToWin - TotalPoints

         BubbleOutPut(Player, + PName + " needs " + NewPointstoWin + " points to win the round")

         GiveItem(Player, "Pvp Flag", - 1) ;take pvp flag item from player
        PvpFlag$ = Spawn(FlagID, "pvp zone", 349.381, 86.3859, 35.021) ; spawn flag at flag return when player turns it in.
        SetSuperGlobal(11, 0) ;set flag holder to 0
        DoEvents(500)
        SetSuperGlobal(10, 0)
        ThreadExecute("Equip Change", "Main", Player, 0) ;send to equip change to update player health and mana after taking pvp flag

        DoEvents(1200) ; hold script then delete returned flag and run flag spawn.

         SetAttribute(PvpFlag, "Health", 0) ;set spawned flag health to 0

         ThreadExecute("Pvp_Spawn_Flag", "Main", Player, 0)

       EndIf

     If (TotalPoints >= ScoreToWin) ;player has won the round.

     ;Anything that should be done or given after points to win has been reached should be done here.

         BubbleOutPut(Player, + Pname + " has won this round.", 255, 214, 234)
        ScreenFlash(Player, 255, 255, 255, 255, 10000, 555) ;M_Pvp_battleground won GUE ID 555
        CreateEmitter(Player, "Summon_Mount", 10, 5000) ;make player glow with power
        OutPut(Player, "You had " + CurrentPvpCoins + " Pvp Coins and you now have " + TotalPvpCoins + " Pvp Coins", 200, 0, 20)

  ;------------------------------------------------------------------------------------------------------
        ;Add to Pvp coins
           StatRecord$ = + PName + "StatRecord.txt"
           StatFile$ = WriteFile(StatRecord)
           WriteLine(StatFile, TotalPvpCoins) ;Write line 1 to 0 setting player pvp coins to 0
           CloseFile(StatFile)
;------------------------------------------------------------------------------------------------------

        Doevents(1200)

                     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)

;NOTE open all players resaults at once.

                        CloseFile(PvpFileCheck)
                        ;First player
                        FindName1$ = FindActor(ReadName1) ;find firt name in list
                        FindName1InGame$ = PlayerInGame(FindName1)
                        If (FindName1InGame = 1) ;player online show results
                            Chatbox$ = OpenDialog(FindName1, Player, "Pvp Results", 521)
                            ShowP1% = 1
                        EndIf

                         ;second player
                        FindName2$ = FindActor(ReadName2) ;find firt name in list
                        FindName2InGame$ = PlayerInGame(FindName2)
                        If (FindName2InGame = 1) ;player online show results
                            Chatbox1$ = OpenDialog(FindName2, Player, "Pvp Results", 521)
                            ShowP2% = 1
                        EndIf

                        ;Third Player
                        FindName3$ = FindActor(ReadName3) ;find firt name in list
                        FindName3InGame$ = PlayerInGame(FindName3)
                        If (FindName3InGame = 1) ;player online show results
                            Chatbox2$ = OpenDialog(FindName3, Player, "Pvp Results", 521)
                            ShowP3% = 1
                        EndIf

;                        ;Forth Player
                         FindName4$ = FindActor(ReadName4) ;find firt name in list
                         FindName4InGame$ = PlayerInGame(FindName4)
                        If (FindName4InGame = 1) ;player online show results
                            Chatbox3$ = OpenDialog(FindName4, Player, "Pvp Results", 521)
                            ShowP4% = 1
                        EndIf

;                        ;Fifth Player
                        FindName5$ = FindActor(ReadName5) ;find firt name in list
                        FindName5InGame$ = PlayerInGame(FindName5)
                        If (FindName5InGame = 1) ;player online show results
                            Chatbox4$ = OpenDialog(FindName5, Player, "Pvp Results", 521)
                            ShowP5% = 1
                        EndIf
                    ;Get Result Info
                         PvpKillCountBg% = Split(ActorGlobal(FindName1, 3), 20, "|") ;player bg kill amount
                         Player1FlagReturns% = Attribute(FindName1, "PVPBG Points")
                         PlayerName1$ = Name(FindName1)
                         PvpKillCountBg2% = Split(ActorGlobal(FindName2, 3), 20, "|") ;player bg kill amount
                         Player2FlagReturns% = Attribute(FindName2, "PVPBG Points")
                         PlayerName2$ = Name(FindName2)
                         PvpKillCountBg3% = Split(ActorGlobal(FindName3, 3), 20, "|") ;player bg kill amount
                         Player3FlagReturns% = Attribute(FindName3, "PVPBG Points")
                         PlayerName3$ = Name(FindName3)
                         PvpKillCountBg4% = Split(ActorGlobal(FindName4, 3), 20, "|") ;player bg kill amount
                         Player4FlagReturns% = Attribute(FindName4, "PVPBG Points")
                         PlayerName4$ = Name(FindName4)
                         PvpKillCountBg5% = Split(ActorGlobal(FindName5, 3), 20, "|") ;player bg kill amount
                         Player5FlagReturns% = Attribute(FindName5, "PVPBG Points")
                         PlayerName5$ = Name(FindName5)

        If (ShowP1 = 1) ;show results to player 1 if they are online
                      ;Display results to all players
                        DialogOutPut(FindName1, ChatBox, "----------" + PName + " WINS----------", 110, 0, 234)
                        DialogOutPut(FindName1, ChatBox, "--------------------------------------", 110, 0, 234)
                        DialogOutPut(FindName1, ChatBox, "")
                        DialogOutPut(FindName1, ChatBox, "----Name-------Flags-------Kills-----", 110, 0, 234)
                        DialogOutPut(FindName1, ChatBox, "---"+ PlayerName1 +"-------"+ Player1FlagReturns + "-------------" + PvpKillCountBg + "-----", 110, 0, 234)
                        DialogOutPut(FindName1, ChatBox, "---"+ PlayerName2 +"-------"+ Player2FlagReturns + "-------------" + PvpKillCountBg2 + "-----", 110, 0, 234)
                        DialogOutPut(FindName1, ChatBox, "---"+ PlayerName3 +"-------"+ Player3FlagReturns + "------------" + PvpKillCountBg3 + "-----", 110, 0, 234)
                        DialogOutPut(FindName1, ChatBox, "---"+ PlayerName4 +"-------"+ Player4FlagReturns + "------------" + PvpKillCountBg4 + "-----", 110, 0, 234)
                        DialogOutPut(FindName1, ChatBox, "---"+ PlayerName5 +"-------"+ Player5FlagReturns + "------------" + PvpKillCountBg5 + "-----", 110, 0, 234)
                DoEvents(100)
       EndIf

        If (ShowP2 = 1) ;show results to player 2 if they are online
                      ;Display results to all players
                        DialogOutPut(FindName2, ChatBox1, "----------" + PName + " WINS----------", 110, 0, 234)
                        DialogOutPut(FindName2, ChatBox1, "--------------------------------------", 110, 0, 234)
                        DialogOutPut(FindName2, ChatBox1, "")
                        DialogOutPut(FindName2, ChatBox1, "----Name-------Flags-------Kills-----", 110, 0, 234)
                        DialogOutPut(FindName2, ChatBox1, "---"+ PlayerName1 +"-------"+ Player1FlagReturns + "------------"  + PvpKillCountBg + "-----", 110, 0, 234)
                        DialogOutPut(FindName2, ChatBox1, "---"+ PlayerName2 +"-------"+ Player2FlagReturns + "------------"  + PvpKillCountBg2 + "-----", 110, 0, 234)
                        DialogOutPut(FindName2, ChatBox1, "---"+ PlayerName3 +"-------"+ Player3FlagReturns + "------------"  + PvpKillCountBg3 + "-----", 110, 0, 234)
                        DialogOutPut(FindName2, ChatBox1, "---"+ PlayerName4 +"-------"+ Player4FlagReturns + "------------"  + PvpKillCountBg4 + "-----", 110, 0, 234)
                        DialogOutPut(FindName2, ChatBox1, "---"+ PlayerName5 +"-------"+ Player5FlagReturns + "------------"  + PvpKillCountBg5 + "-----", 110, 0, 234)
                 DoEvents(100)
        EndIf

         If (ShowP3 = 1) ;show results to player 3 if they are online
                      ;Display results to all players
                        DialogOutPut(FindName3, ChatBox2, "----------" + PName + " WINS----------", 110, 0, 234)
                        DialogOutPut(FindName3, ChatBox2, "--------------------------------------", 110, 0, 234)
                        DialogOutPut(FindName3, ChatBox2, "")
                        DialogOutPut(FindName3, ChatBox2, "----Name-------Flags-------Kills-----", 110, 0, 234)
                        DialogOutPut(FindName3, ChatBox2, "---"+ PlayerName1 +"-------"+ Player1FlagReturns + "------------"  + PvpKillCountBg + "-----", 110, 0, 234)
                        DialogOutPut(FindName3, ChatBox2, "---"+ PlayerName2 +"-------"+ Player2FlagReturns + "------------"  + PvpKillCountBg2 + "-----", 110, 0, 234)
                        DialogOutPut(FindName3, ChatBox2, "---"+ PlayerName3 +"-------"+ Player3FlagReturns + "------------"  + PvpKillCountBg3 + "-----", 110, 0, 234)
                        DialogOutPut(FindName3, ChatBox2, "---"+ PlayerName4 +"-------"+ Player4FlagReturns + "------------"  + PvpKillCountBg4 + "-----", 110, 0, 234)
                        DialogOutPut(FindName3, ChatBox2, "---"+ PlayerName5 +"-------"+ Player5FlagReturns + "------------"  + PvpKillCountBg5 + "-----", 110, 0, 234)
                  DoEvents(100)
       EndIf

        If (ShowP4 = 1) ;show results to player 4  if they are online

                      ;Display results to all players
                        DialogOutPut(FindName4, ChatBox3, "----------" + PName + " WINS----------", 110, 0, 234)
                        DialogOutPut(FindName4, ChatBox3, "--------------------------------------", 110, 0, 234)
                        DialogOutPut(FindName4, ChatBox3, "----Name-------Flags-------Kills-----", 110, 0, 234)
                        DialogOutPut(FindName4, ChatBox3, "--------------------------------------", 110, 0, 234)
                        DialogOutPut(FindName4, ChatBox3, "")
                        DialogOutPut(FindName4, ChatBox3, "---"+ PlayerName1 +"-------"+ Player1FlagReturns + "------------"  + PvpKillCountBg + "-----", 110, 0, 234)
                        DialogOutPut(FindName4, ChatBox3, "---"+ PlayerName2 +"-------"+ Player2FlagReturns + "------------"  + PvpKillCountBg2 + "-----", 110, 0, 234)
                        DialogOutPut(FindName4, ChatBox3, "---"+ PlayerName3 +"-------"+ Player3FlagReturns + "------------"  + PvpKillCountBg3 + "-----", 110, 0, 234)
                        DialogOutPut(FindName4, ChatBox3, "---"+ PlayerName4 +"-------"+ Player4FlagReturns + "------------"  + PvpKillCountBg4 + "-----", 110, 0, 234)
                        DialogOutPut(FindName4, ChatBox3, "---"+ PlayerName5 +"-------"+ Player5FlagReturns + "------------"  + PvpKillCountBg5 + "-----", 110, 0, 234)
        DoEvents(100)
        EndIf

         If (ShowP5 = 1) ;show results to player 5 if they are online
                      ;Display results to all players
                        DialogOutPut(FindName5, ChatBox4, "----------" + PName + " WINS----------", 110, 0, 234)
                        DialogOutPut(FindName5, ChatBox4, "--------------------------------------", 110, 0, 234)
                        DialogOutPut(FindName5, ChatBox4, "----Name-------Flags-------Kills-----", 110, 0, 234)
                        DialogOutPut(FindName5, ChatBox4, "--------------------------------------", 110, 0, 234)
                        DialogOutPut(FindName5, ChatBox4, "")
                        DialogOutPut(FindName5, ChatBox4, "---"+ PlayerName1 +"-------"+ Player1FlagReturns + "------------"  + PvpKillCountBg + "-----", 110, 0, 234)
                        DialogOutPut(FindName5, ChatBox4, "---"+ PlayerName2 +"-------"+ Player2FlagReturns + "------------"  + PvpKillCountBg2 + "-----", 110, 0, 234)
                        DialogOutPut(FindName5, ChatBox4, "---"+ PlayerName3 +"-------"+ Player3FlagReturns + "------------"  + PvpKillCountBg3 + "-----", 110, 0, 234)
                        DialogOutPut(FindName5, ChatBox4, "---"+ PlayerName4 +"-------"+ Player4FlagReturns + "------------"  + PvpKillCountBg4 + "-----", 110, 0, 234)
                        DialogOutPut(FindName5, ChatBox4, "---"+ PlayerName5 +"-------"+ Player5FlagReturns + "------------"  + PvpKillCountBg5 + "-----", 110, 0, 234)
             DoEvents(100)
        EndIf

             ;flash screen for the losers!
            If Not (Pname = FindName1) ;if not winner show losser
                ScreenFlash(FindName1, 255, 255, 255, 255, 10000, 653)
            EndIf

             If Not (Pname = FindName2) ;if not winner show losser
                ScreenFlash(FindName2, 255, 255, 255, 255, 10000, 653)
            EndIf

             If Not (Pname = FindName3) ;if not winner show losser
                ScreenFlash(FindName3, 255, 255, 255, 255, 10000, 653)
            EndIf

            If Not (Pname = FindName4) ;if not winner show losser
                ScreenFlash(FindName4, 255, 255, 255, 255, 10000, 653)
            EndIf

             If Not (Pname = FindName5) ;if not winner show losser
                ScreenFlash(FindName5, 255, 255, 255, 255, 10000, 653)
            EndIf
            DoEvents(8000)

             If (ShowP1 = 1) ;show exit to player 1 if they are online
                        DialogInput(FindName1, ChatBox, "OK") ;player 1
                        CloseDialog(FindName1, ChatBox)
                        SetMaxAttribute(FindName1, "PVPBG Points", 0) ;set attribute back to zero so flags can be counted again.
                        SetAttribute(FindName1, "PVPBG Points", 0)
                        Warp(FindName1, "Annakay Town", "Start", 0) ;Warp 1st player
            EndIf

            If (ShowP2 = 1) ;show exit to player 2 if they are online

                         DialogInput(FindName2, ChatBox1, "OK") ;player 2
                         CloseDialog(FindName2, ChatBox1)
                        SetMaxAttribute(FindName2, "PVPBG Points", 0) ;set attribute back to zero so flags can be counted again.
                        SetAttribute(FindName2, "PVPBG Points", 0)
                         Warp(FindName2, "Annakay Town", "Start", 0) ;Warp 2nd player
             EndIf

                 If (ShowP3 = 1) ;show exit to player 3 if they are online

                        DialogInput(FindName3, ChatBox2, "OK") ;player 3
                        CloseDialog(FindName3, ChatBox2)
                        SetMaxAttribute(FindName3, "PVPBG Points", 0) ;set attribute back to zero so flags can be counted again.
                        SetAttribute(FindName3, "PVPBG Points", 0)
                        Warp(FindName3, "Annakay Town", "Start", 0) ;Warp 3rd player
                 EndIf

                  If (ShowP4 = 1) ;show exit to player 4 if they are online
                        ;DialogInput(FindName4, ChatBox3, "OK") ;player 4
                        CloseDialog(FindName4, ChatBox3)
                        SetMaxAttribute(FindName4, "PVPBG Points", 0) ;set attribute back to zero so flags can be counted again.
                        SetAttribute(FindName4, "PVPBG Points", 0)
                        Warp(FindName4, "Annakay Town", "Start", 0) ;Warp 4th player
                 EndIf
                 If (ShowP5 = 1) ;show exit to player 5 if they are online
                        ;DialogInput(FindName5, ChatBox4, "OK") ;player 5
                        CloseDialog(FindName5, ChatBox4)
                        SetMaxAttribute(FindName5, "PVPBG Points", 0) ;set attribute back to zero so flags can be counted again.
                        SetAttribute(FindName5, "PVPBG Points", 0)
                        Warp(FindName5, "Annakay Town", "Start", 0) ;Warp 5th player
                 EndIf

         CreateEmitter(Player, "Summon_Mount", 11, 5000) ;make player glow with power

              Pname$ = Split(SuperGlobal(2), 1, "|")  ;Retrive leader and name of master list
              DeleteFile(+ Pname + "Master PvPBg.Txt") ;remove pvp bg file
                          ;Make super global delimiter if there is no pvp zones made yet.
                ;Set changes to delimiter

             Pvpname1$ = 0
            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 actor global 3

            ;kill flag before removing zone
           FlagName$ = "Pvp Flag"
           SpawnedFlag$ = FindActor(FlagName, 2)
            If (SpawnedFlag = 1)
                SetAttribute(SpawnedFlag, "Health", 0)
            EndIf
            DoEvents(10000)
            RemoveZoneInstance(BgName, 1)
    EndIf

    EndIf ;end trigger check

End Function

```