FANDOM


Created by Taz.

Using "RC_Core.rcm"
;Bounty hunter script
;By Tazco june 13 2012
;Called when player kills target to see if target has a bounty on them.
				;Line 1 name
				;Line 2 Title
				;Line 3 Reward
				;Line 4 Date
				;Line 5 Reason
				;Line 6 Player that posted
				
;Seems to work, but when re making bounty master list, it still seems to add the name of the player that was killed
;need to fix that and add so the bounty master list will delete itself when empty.				
Function Main()
Player = Actor()

	TName$ = Parameter(1)
ScriptLog("Bounty check running by " + TName)
 Bountylistcheck% = OpenFile(+ TName + " Bounty.Txt")

	If (Bountylistcheck >= 1) ;Killed player has a bounty on them get info and reward.
		
		ReadNewLineDud$ = ReadLine(Bountylistcheck) ;Name not needed
		ReadNewLineDud1$ = ReadLine(Bountylistcheck) ;title not needed
		ReadNewReward1$ = ReadLine(Bountylistcheck) ;Reward
		ReadNewReward% = ReadNewReward1
		ReadNewLineDud12$ = ReadLine(Bountylistcheck) ;Date not needed
	   	ReadNewLineDud13$ = ReadLine(Bountylistcheck) ;Reason not needed
		ReadNewPosterName1$ = ReadLine(Bountylistcheck) ;poster name
		ReadNewPosterName$ = ReadNewPosterName1	
		
		CloseFile(Bountylistcheck)
		DeleteFile(+ TName + " Bounty.Txt") ;delete file since its no longer needed. commented for testing
		
			PMoney% = Money(Player)
			TotPMoney% = Pmoney + ReadNewReward
			
		
			
			OutPut(Player, "You have killed " + Tname + " the reward for this bounty is " + ReadNewReward)
			SetMoney(Player, TotPMoney)
			
		
		;flash screen 432
		ScreenFlash(Player, 255, 255, 255, 255, 9000, 432) ;flash bounty complete
		
		;remove player name form master bounty list.
		;Count Names in list
				 MasterList$ = "Bounty Master List.Txt"
				  Bountylist% = ReadFile(MasterList)


				BountyinFile% = 0
				CountNames% = 0
	
				Repeat			 					  
						;to count names in list

							ReadBML$ = ReadLine(Bountylist)
							ReadBMLLine$ = ReadBML
			
										
									
									    	If (ReadBMLLine = "") ;no one in list end repeat
												nooneinlist% = 1
											Else
									    		CountNames% = CountNames + 1	;add for name in list
												
											EndIf
								
					
								EndOfList% = EoF(Bountylist)  ;leave end of list check since it is counting players in list to use later.
									If (EndOfList = 1)
										BountyinFile1% = 2
									EndIf
							DoEvents(10)
				Until(BountyinFile1 >= 2)
				
									
					CloseFile(ReadBML)
					CloseFile(Bountylist)
					CloseFile(MasterList)

							BMLTemp$ = "Bounty Master ListTemp.Txt"
							BountylistTemp% = OpenFile(BMLTemp)
								If (BountylistTemp = 0) ;write file if it is not there. avoid a server invalid steam crash
									WriteBMTemp$ = WriteFile(BMLTemp)
									CloseFile(WriteBMTemp)
			
								EndIf
							CloseFile(BMLTemp)
							CloseFile(BountylistTemp)
							
							
							
							;open master bounty list
							BML$ = "Bounty Master List.Txt"
							Bountylist% = OpenFile(BML)
							
							;open temp bounty list to copy to.
							BMLTemp$ = "Bounty Master ListTemp.Txt"
							BountylistTemp% = OpenFile(BMLTemp)
							
							CountNames% = CountNames  ;number of lines to read
							BakNameCOunt% = CountNames  ;keep backup of amount of names in list add 1 for player to be added
							MasterFileRe% = CountNames
			
							
							Repeat ;copy lines from txt to text.
								If (CountNames >= 1)
								ReadTxtLine$ = ReadLine(Bountylist) ;readmaster list
								NewReadTxtLine$ = ReadTxtLine
										;If name in list = tname then skip line
							
											 If (NewReadTxtLine = TName)
											 ;	ReadTxtLine$ = ""
											 ;	output(player, "name found in list doing nothing")										 		
											Else
										    ;	OutPut(Player, "Writing name " + NewReadTxtLine)
												WriteLine(BountylistTemp, NewReadTxtLine)  ;Write to temp list
											EndIf
							
							
											DoEvents(10)
											CountNames% = CountNames - 1
							   EndIf
							Until (CountNames <= 0)
							
						
				
						;Close All files that are open
							CloseFile(ReadTxtLine)
							CloseFile(Bountylist)
							CloseFile(BountylistTemp)
							DeleteFile("Bounty Master List.Txt") ;remove file to remake and add changes.
							
							
							
														;Remake master bounty file
							BML$ = "Bounty Master List.Txt"
							Bountylist% = OpenFile(BML)
								If (BountyList = 0) ;write file if it is not there. avoid a server invalid steam crash
									WriteBM$ = WriteFile(BML)
									CloseFile(WriteBM)
									
								EndIf

								CloseFile(Bountylist)
	
							BML$ = "Bounty Master List.Txt"
							Bountylist% = OpenFile(BML)
							
					
						    BMLTemp$ = "Bounty Master ListTemp.Txt"
							BountylistTemp% = OpenFile(BMLTemp)
							SeekFile(BountylistTemp, 0)
								
								Repeat ;rewrite main file
								
								    	TempRead1$ = ReadLine(BountylistTemp)
										NewTempRead1$ = TempRead1
						
										
										WriteLine(Bountylist, TempRead1) ;write to bounty list
																
																	
																	
									DoEvents(10)
									
							    	BakNameCOunt% = BakNameCOunt - 1
							    	
								Until (BakNameCOunt <= 0)
								
								
							
								CloseFile(Bountylist)
								CloseFile(BountylistTemp)
								DeleteFile("Bounty Master ListTemp.Txt") ;remove temp file
							
			
	  		
	EndIf
	
	If (Bountylistcheck = 0) ;target has no bounty on them end script
	
	CloseFile(Bountylistcheck)
	EndIf
	
	
	;	OutPut(Player, "Count is " + CountNames)
		
		If (MasterFileRe <= 1)
		;remove bounty master list if it is empty
		DeleteFile("Bounty Master List.Txt")
		
		EndIf
	
	

End Function