I am trying to fix an old script but am new to python.
The script all works except for when it needs to write the player's name into the script.
The Problem: It only broadcast the last name instead of the full name of the player
Info about the situation and script:
-This script generator creates scripts to run on a game server to control who can play and who can spectate.
-The script uses two external files(lineup.txt & signups.txt) to determine who can play in the next round.
-The game has a UID(unique identifier) for each player and this is used in commands to control whether they play or not.
-The lineup file is grabbed from ingame to determine who is in the server. This file also shows what server slot the player is in, their uid, what state they are in(playing or spectating), their chosen number, which dirt bike size, brand and year and finally their name ingame.
-The signups file is grabbed from a website that manages signups and qualifying times(for the racing game).
-The script in a nutshell compares the uids from each file and discards any that aren't on both list(so any players who didn't show up or sign up to the event are not included)
![[Image: MYrhjrM]](https://imgur.com/a/MYrhjrM)
This is the main script:
![[Image: 4Omyp7f]](https://imgur.com/a/4Omyp7f)
This is an example of what it should create:
The script all works except for when it needs to write the player's name into the script.
The Problem: It only broadcast the last name instead of the full name of the player
Info about the situation and script:
-This script generator creates scripts to run on a game server to control who can play and who can spectate.
-The script uses two external files(lineup.txt & signups.txt) to determine who can play in the next round.
-The game has a UID(unique identifier) for each player and this is used in commands to control whether they play or not.
-The lineup file is grabbed from ingame to determine who is in the server. This file also shows what server slot the player is in, their uid, what state they are in(playing or spectating), their chosen number, which dirt bike size, brand and year and finally their name ingame.
-The signups file is grabbed from a website that manages signups and qualifying times(for the racing game).
-The script in a nutshell compares the uids from each file and discards any that aren't on both list(so any players who didn't show up or sign up to the event are not included)
This is the main script:
def heatsplitter(): #MXS Heat Splitter v4 by Sammy Holt #This script will take information from a lineup file and generate heat scripts to be run by mxserver #This version will use a signup file to parse the lineup file and only include the UIDS which are signed up #Make sure all output files are completely empty #Also, paste lineup file data into "lineuptest.txt" #DO NOT RENAME FILES, the script will fail #If you must change data, simply cut and paste into the designated file #Planned Features: #-Add a user defined amount of heats(In Progress) #-Easier file handling(Timeframe Unknown) #This section takes input from the user for initial file generation print "MX Simulator Heat Splitter w/Signup Parsing" print "Created by Sammy Holt" print "\n" print "\n" lineup = raw_input('Drag and Drop your lineup file: ') signups = raw_input('Drag and Drop your signups file: ') h1 = raw_input('Enter a name for your heat 1 script: ') h2 = raw_input('Enter a name for your heat 2 script: ') racename = raw_input('Enter a race name for heat 1: ') racename2 = raw_input('Enter a race name for heat 2: ') uidname = raw_input('Enter a name for uid export: ') titlecolor = raw_input('Which color would you like the title to be?(Red,Green,Aqua,Blue,White,Black,Yellow,or Purple): ') namecolor = raw_input('Which color would you like the rider names to be?(Red,Green,Aqua,Blue,White,Black,Yellow,or Purple): ') tracknum = raw_input('What is the number of the track the race will be held on?: ') numLaps = raw_input('How many laps will these heats be?: ') numTransfer = raw_input('How many people transfer from each heat?: ') numWarmup = raw_input('Track number of warmup lap: ') #Color Switcher for Title: #This block turns the user color string into a useable term if (titlecolor=='Red') or (titlecolor=='red'): tc='31' elif titlecolor=='Green' or (titlecolor=='green'): tc='32' elif titlecolor=='Aqua' or (titlecolor=='aqua'): tc='36' elif titlecolor=='Blue' or (titlecolor=='blue'): tc='34' elif titlecolor=='White' or (titlecolor=='white'): tc='37' elif titlecolor=='Black' or (titlecolor=='black'): tc='30' elif titlecolor=='Yellow' or (titlecolor=='yellow'): tc='33' elif titlecolor=='Purple' or (titlecolor=='purple'): tc='35' else: print "Not a valid color" #Color Switcher for Names: #This block turns the user color string into a useable term if namecolor=='Red' or (namecolor=='red'): nc='31' elif namecolor=='Green' or (namecolor=='green'): nc='32' elif namecolor=='Aqua' or (namecolor=='aqua'): nc='36' elif namecolor=='Blue' or (namecolor=='blue'): nc='34' elif namecolor=='White' or (namecolor=='white'): nc='37' elif namecolor=='Black' or (namecolor=='black'): nc='30' elif namecolor=='Yellow' or (namecolor=='yellow'): nc='33' elif namecolor=='Purple' or (namecolor=='purple'): nc='35' else: print "Not a valid color" #Create a variable for half the amount of riders #halfriders = (amtRiders/2) #Generate the titles and some other settings for the two scripts heat1script = open("C:\\Scripts\\"+h1+".mxs","a") heat2script = open("C:\\Scripts\\"+h2+".mxs","a") heat1warmup = open("C:\\Scripts\\"+h1+"warmup"+".mxs","a") heat2warmup = open("C:\\Scripts\\"+h2+"warmup"+".mxs","a") heat1nr = open("C:\\Scripts\\"+h1+"nr"+".mxs","a") heat2nr = open("C:\\Scripts\\"+h2+"nr"+".mxs","a") heat1nrwarmup = open("C:\\Scripts\\"+h1+"nrwarmup"+".mxs","a") heat2nrwarmup = open("C:\\Scripts\\"+h2+"nrwarmup"+".mxs","a") heat1script.write("#mxserverscript"+"\n") heat1script.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat1script.write("broadcast ["+tc+"m "+racename+" - "+numLaps+" Laps - "+"Top "+numTransfer+" Transfer"+"\n") heat1script.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat1script.write("allignore all"+'\n') heat1script.write("settrack "+tracknum+'\n') heat1script.write("forcespec all"+'\n') heat1script.close() heat2script.write("#mxserverscript"+"\n") heat2script.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat2script.write("broadcast ["+tc+"m "+racename2+" - "+numLaps+" Laps - "+"Top "+numTransfer+" Transfer"+"\n") heat2script.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat2script.write("allignore all"+'\n') heat2script.write("settrack "+tracknum+'\n') heat2script.write("forcespec all"+'\n') heat2script.close() #Warmup Files heat1warmup.write("#mxserverscript"+"\n") heat1warmup.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat1warmup.write("broadcast ["+tc+"m "+racename+" - "+"Lineup"+"\n") heat1warmup.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat1warmup.write("forcespec all"+"\n") heat1warmup.write("settrack "+numWarmup+"\n") heat1warmup.close() heat2warmup.write("#mxserverscript"+"\n") heat2warmup.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat2warmup.write("broadcast ["+tc+"m "+racename2+" - "+"Lineup"+"\n") heat2warmup.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat2warmup.write("forcespec all"+"\n") heat2warmup.write("settrack "+numWarmup+"\n") heat2warmup.close() #Next Race Script heat1nr.write("#mxserverscript"+"\n") heat1nr.write("broadcast [33m Next Race is: "+racename+"\n") heat1nr.close() heat1nrwarmup.write("#mxserverscript"+"\n") heat1nrwarmup.write("broadcast [33m Next Race is: "+racename+" Warmup Lap"+"\n") heat1nrwarmup.close() #Next Race Script2 heat2nr.write("#mxserverscript"+"\n") heat2nr.write("broadcast [33m Next Race is: "+racename2+"\n") heat2nr.close() heat2nrwarmup.write("#mxserverscript"+"\n") heat2nrwarmup.write("broadcast [33m Next Race is: "+racename2+" Warmup Lap"+"\n") heat2nrwarmup.close() #Add automatic calls to Broadcast Next Race heat1script = open("C:\\Scripts\\"+h1+".mxs","a") heat2script = open("C:\\Scripts\\"+h2+".mxs","a") heat1warmup = open("C:\\Scripts\\"+h1+"warmup"+".mxs","a") heat2warmup = open("C:\\Scripts\\"+h2+"warmup"+".mxs","a") #heat1script.write("at +2 broadcast [33m Next Race is: "+racename+"\n") heat1script.close() #heat2script.write("at +2 broadcast [33m Next Race is: "+racename2+"\n") heat2script.close() #heat1warmup.write("at +2 broadcast [33m Next Race is: "+racename+" Warmup Lap"+"\n") heat1warmup.close() #heat2warmup.write("at +2 broadcast [33m Next Race is: "+racename2+" Warmup Lap"+"\n") heat2warmup.close() #Stuff used to split heats evenly with open(signups) as f: lines = f.read().splitlines() num_lines = sum(1 for line in open(lineup)) p=0 with open(lineup,"r") as f: data = f.readlines() for line in data: words=line.split() userid=words[1] if userid in lines: p+=1 nRacers = (p/2) #This section will deal with the actual lineup file x=0 y=0 z=0 with open(lineup,"r") as f: data = f.readlines() for line in data: #Open files for output heat1=open("C:\\Scripts\\"+h1+".mxs","a") heat2=open("C:\\Scripts\\"+h2+".mxs","a") heat1warmup=open("c:\\Scripts\\"+h1+"warmup"+".mxs","a") heat2warmup=open("c:\\Scripts\\"+h2+"warmup"+".mxs","a") uidfile=open("c:\\Scripts\\"+uidname+".txt","a") #Take lineup file into a list words=line.split() #Make a slot variable slot=words[0] #Set a variable equal to names and uids of each slot #Also cleans up the underscores from the lineup file and replaces them with a whitespace userid=words[1] #The following will generate the heats (AKA. any bugs are probably here) if userid in lines: if x<nRacers: heat1.write("broadcast ["+nc+"m " + username + "\n") heat1.write("forceplay " + userid + "\n") heat1.write("broadcastto " + userid + " [35m You are in: "+racename + "\n") heat1.close() heat1warmup.write("broadcast ["+nc+"m " + username + "\n") heat1warmup.write("forceplay " + userid + "\n") heat1warmup.write("broadcastto " + userid + " [35m You are in: "+racename + "\n") heat1warmup.close() uidfile.write(userid+"\n") uidfile.close() z+=1 else: heat2.write("broadcast ["+nc+"m " + username + "\n") heat2.write("forceplay " + userid + "\n") heat2.write("broadcastto " + userid + " [35m You are in: "+racename2 + "\n") heat2.close() heat2warmup.write("broadcast ["+nc+"m " + username + "\n") heat2warmup.write("forceplay " + userid + "\n") heat2warmup.write("broadcastto " + userid + " [35m You are in: "+racename2 + "\n") heat2warmup.close() uidfile.write(userid+'\n') uidfile.close() y+=1 x+=1 #Appends the number of riders in the race at the bottom of each file a=str(z) b=str(y) heat1script = open("C:\\Scripts\\"+h1+".mxs","a") heat1script.write("broadcast "+"\n") heat1script.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat1script.write("broadcast ["+tc+"m "+a+" Riders"+"\n") heat1script.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat1script.write("broadcast "+"\n") heat1script.close() heat2script = open("C:\\Scripts\\"+h2+".mxs","a") heat2script.write("broadcast "+"\n") heat2script.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat2script.write("broadcast ["+tc+"m "+b+" Riders"+"\n") heat2script.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat2script.write("broadcast "+"\n") heat2script.close() heat1warmup = open("C:\\Scripts\\"+h1+"warmup"+".mxs","a") heat1warmup.write("broadcast "+"\n") heat1warmup.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat1warmup.write("broadcast ["+tc+"m "+a+" Riders"+"\n") heat1warmup.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat1warmup.write("broadcast "+"\n") heat1warmup.close() heat2warmup = open("C:\\Scripts\\"+h2+"warmup"+".mxs","a") heat2warmup.write("broadcast "+"\n") heat2warmup.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat2warmup.write("broadcast ["+tc+"m "+b+" Riders"+"\n") heat2warmup.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat2warmup.write("broadcast "+"\n") heat2warmup.close() import subprocess subprocess.Popen('explorer "C:\Scripts"') def heatsplitternos(): #MXS Heat Splitter v4 by Sammy Holt #This script will take information from a lineup file and generate heat scripts to be run by mxserver #This version will use a signup file to parse the lineup file and only include the UIDS which are signed up #Make sure all output files are completely empty #Also, paste lineup file data into "lineuptest.txt" #DO NOT RENAME FILES, the script will fail #If you must change data, simply cut and paste into the designated file #Planned Features: #-Add a user defined amount of heats(In Progress) #-Easier file handling(Timeframe Unknown) #This section takes input from the user for initial file generation print "MX Simulator Heat Splitter No Signup Parsing" print "Created by Sammy Holt" print "\n" print "\n" lineup = raw_input('Drag and Drop your lineup file: ') h1 = raw_input('Enter a name for your heat 1 script: ') h2 = raw_input('Enter a name for your heat 2 script: ') racename = raw_input('Enter a race name for heat 1: ') racename2 = raw_input('Enter a race name for heat 2: ') uidname = raw_input('Enter a name for uid export: ') titlecolor = raw_input('Which color would you like the title to be?(Red,Green,Aqua,Blue,White,Black,Yellow,or Purple): ') namecolor = raw_input('Which color would you like the rider names to be?(Red,Green,Aqua,Blue,White,Black,Yellow,or Purple): ') tracknum = raw_input('What is the number of the track the race will be held on?: ') numLaps = raw_input('How many laps will these heats be?: ') numTransfer = raw_input('How many people transfer from each heat?: ') numWarmup = raw_input('Track number of warmup lap: ') num_lines = sum(1 for line in open(lineup)) #Color Switcher for Title: #This block turns the user color string into a useable term if (titlecolor=='Red') or (titlecolor=='red'): tc='31' elif titlecolor=='Green' or (titlecolor=='green'): tc='32' elif titlecolor=='Aqua' or (titlecolor=='aqua'): tc='36' elif titlecolor=='Blue' or (titlecolor=='blue'): tc='34' elif titlecolor=='White' or (titlecolor=='white'): tc='37' elif titlecolor=='Black' or (titlecolor=='black'): tc='30' elif titlecolor=='Yellow' or (titlecolor=='yellow'): tc='33' elif titlecolor=='Purple' or (titlecolor=='purple'): tc='35' else: print "Not a valid color" #Color Switcher for Names: #This block turns the user color string into a useable term if namecolor=='Red' or (namecolor=='red'): nc='31' elif namecolor=='Green' or (namecolor=='green'): nc='32' elif namecolor=='Aqua' or (namecolor=='aqua'): nc='36' elif namecolor=='Blue' or (namecolor=='blue'): nc='34' elif namecolor=='White' or (namecolor=='white'): nc='37' elif namecolor=='Black' or (namecolor=='black'): nc='30' elif namecolor=='Yellow' or (namecolor=='yellow'): nc='33' elif namecolor=='Purple' or (namecolor=='purple'): nc='35' else: print "Not a valid color" #Create a variable for half the amount of riders #halfriders = (amtRiders/2) #Generate the titles and some other settings for the two scripts heat1script = open("C:\\Scripts\\"+h1+".mxs","a") heat2script = open("C:\\Scripts\\"+h2+".mxs","a") heat1warmup = open("C:\\Scripts\\"+h1+"warmup"+".mxs","a") heat2warmup = open("C:\\Scripts\\"+h2+"warmup"+".mxs","a") heat1nr = open("C:\\Scripts\\"+h1+"nr"+".mxs","a") heat2nr = open("C:\\Scripts\\"+h2+"nr"+".mxs","a") heat1nrwarmup = open("C:\\Scripts\\"+h1+"nrwarmup"+".mxs","a") heat2nrwarmup = open("C:\\Scripts\\"+h2+"nrwarmup"+".mxs","a") heat1script.write("#mxserverscript"+"\n") heat1script.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat1script.write("broadcast ["+tc+"m "+racename+" - "+numLaps+" Laps - "+"Top "+numTransfer+" Transfer"+"\n") heat1script.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat1script.write("allignore all"+'\n') heat1script.write("settrack "+tracknum+'\n') heat1script.write("forcespec all"+'\n') heat1script.close() heat2script.write("#mxserverscript"+"\n") heat2script.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat2script.write("broadcast ["+tc+"m "+racename2+" - "+numLaps+" Laps - "+"Top "+numTransfer+" Transfer"+"\n") heat2script.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat2script.write("allignore all"+'\n') heat2script.write("settrack "+tracknum+'\n') heat2script.write("forcespec all"+'\n') heat2script.close() #Warmup Files heat1warmup.write("#mxserverscript"+"\n") heat1warmup.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat1warmup.write("broadcast ["+tc+"m "+racename+" - "+"Warmup Lap"+"\n") heat1warmup.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat1warmup.write("forcespec all"+"\n") heat1warmup.write("settrack "+numWarmup+"\n") heat1warmup.close() heat2warmup.write("#mxserverscript"+"\n") heat2warmup.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat2warmup.write("broadcast ["+tc+"m "+racename2+" - "+"Warmup Lap"+"\n") heat2warmup.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat2warmup.write("forcespec all"+"\n") heat2warmup.write("settrack "+numWarmup+"\n") heat2warmup.close() #Next Race Script heat1nr.write("#mxserverscript"+"\n") heat1nr.write("broadcast [33m Next Race is: "+racename+"\n") heat1nr.close() heat1nrwarmup.write("#mxserverscript"+"\n") heat1nrwarmup.write("broadcast [33m Next Race is: "+racename+" Warmup Lap"+"\n") heat1nrwarmup.close() #Next Race Script2 heat2nr.write("#mxserverscript"+"\n") heat2nr.write("broadcast [33m Next Race is: "+racename2+"\n") heat2nr.close() heat2nrwarmup.write("#mxserverscript"+"\n") heat2nrwarmup.write("broadcast [33m Next Race is: "+racename2+" Warmup Lap"+"\n") heat2nrwarmup.close() #Stuff used to split heats evenly p=0 with open(lineup,"r") as f: data = f.readlines() for line in data: words=line.split() userid=words[1] p+=1 nRacers = (p/2) #This section will deal with the actual lineup file x=0 y=0 z=0 with open(lineup,"r") as f: data = f.readlines() for line in data: #Open files for output heat1=open("C:\\Scripts\\"+h1+".mxs","a") heat2=open("C:\\Scripts\\"+h2+".mxs","a") heat1warmup=open("c:\\Scripts\\"+h1+"warmup"+".mxs","a") heat2warmup=open("c:\\Scripts\\"+h2+"warmup"+".mxs","a") uidfile=open("c:\\Scripts\\"+uidname+".txt","a") #Take lineup file into a list words=line.split() #Make a slot variable slot=words[0] #Set a variable equal to names and uids of each slot #Also cleans up the underscores from the lineup file and replaces them with a whitespace userid=words[1] username=words[2].replace("_"," ") #The following will generate the heats (AKA. any bugs are probably here) if x<nRacers: heat1.write("broadcast ["+nc+"m " + username + "\n") heat1.write("forceplay " + userid + "\n") heat1.write("broadcastto " + userid + " [35m You are in: "+racename + "\n") heat1.close() heat1warmup.write("broadcast ["+nc+"m " + username + "\n") heat1warmup.write("forceplay " + userid + "\n") heat1warmup.write("broadcastto " + userid + " [35m You are in: "+racename + "\n") heat1warmup.close() uidfile.write(userid+"\n") uidfile.close() z+=1 else: heat2.write("broadcast ["+nc+"m " + username + "\n") heat2.write("forceplay " + userid + "\n") heat2.write("broadcastto " + userid + " [35m You are in: "+racename2 + "\n") heat2.close() heat2warmup.write("broadcast ["+nc+"m " + username + "\n") heat2warmup.write("forceplay " + userid + "\n") heat2warmup.write("broadcastto " + userid + " [35m You are in: "+racename2 + "\n") heat2warmup.close() uidfile.write(userid+"\n") uidfile.close() y+=1 x+=1 #Appends the number of riders in the race at the bottom of each file a=str(z) b=str(y) heat1script = open("C:\\Scripts\\"+h1+".mxs","a") heat1script.write("broadcast "+"\n") heat1script.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat1script.write("broadcast ["+tc+"m "+a+" Riders"+"\n") heat1script.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat1script.write("broadcast "+"\n") heat1script.close() heat2script = open("C:\\Scripts\\"+h2+".mxs","a") heat2script.write("broadcast "+"\n") heat2script.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat2script.write("broadcast ["+tc+"m "+b+" Riders"+"\n") heat2script.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat2script.write("broadcast "+"\n") heat2script.close() heat1warmup = open("C:\\Scripts\\"+h1+"warmup"+".mxs","a") heat1warmup.write("broadcast "+"\n") heat1warmup.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat1warmup.write("broadcast ["+tc+"m "+a+" Riders"+"\n") heat1warmup.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat1warmup.write("broadcast "+"\n") heat1warmup.close() heat2warmup = open("C:\\Scripts\\"+h2+"warmup"+".mxs","a") heat2warmup.write("broadcast "+"\n") heat2warmup.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat2warmup.write("broadcast ["+tc+"m "+b+" Riders"+"\n") heat2warmup.write("broadcast ["+tc+"m ---------------------------------------------------------------"+"\n") heat2warmup.write("broadcast "+"\n") heat2warmup.close() import subprocess subprocess.Popen('explorer "C:\Scripts"')This is what it creates:
This is an example of what it should create:
Output:#mxserverscript
broadcast [31m ---------------------------------------------------------------
broadcast [31m Heat 2 - 8 Laps - Top 4 Transfer
broadcast [31m ---------------------------------------------------------------
allignore all
settrack 1
forcespec all
broadcast [32m Lochlan Berg | FGR
forceplay 28971
broadcastto 28971 [35m You are in: Heat 2
broadcast
broadcast [31m ---------------------------------------------------------------
broadcast [31m 1 Riders
broadcast [31m ---------------------------------------------------------------
broadcast
And this is what it creates now:Output:#mxserverscript
broadcast [31m ---------------------------------------------------------------
broadcast [31m Heat 2 - 8 Laps - Top 4 Transfer
broadcast [31m ---------------------------------------------------------------
allignore all
settrack 1
forcespec all
broadcast [32m Berg
forceplay 28971
broadcastto 28971 [35m You are in: Heat 2
broadcast
broadcast [31m ---------------------------------------------------------------
broadcast [31m 1 Riders
broadcast [31m ---------------------------------------------------------------
broadcast