Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import MaxGUI.Drivers
- Type TStat
- Global list:TList
- Global saved = True
- Function ResetList()
- list = CreateList()
- EndFunction
- Function AddList(name$,u,s,k,d,t)
- TStat.saved = False
- Local stat:TStat = New TStat
- stat.name = name
- stat.usgn = u
- stat.score = s
- stat.kills = k
- stat.deaths = d
- stat.time = t
- ListAddLast(list, stat)
- EndFunction
- Function FindUSGN:TStat(u)
- For s:TStat = EachIn TStat.list
- If s.usgn = u Then Return s
- Next
- EndFunction
- Field name$
- Field usgn
- Field score
- Field kills
- Field deaths
- Field time
- EndType
- Function SaveStats()
- If TStat.list Then
- Local stream:TStream = WriteStream("sys/stats/userstats.dat")
- If stream Then
- TStat.saved = True
- WriteLine stream, "userstats alpha"
- For stat:TStat = EachIn TStat.list
- WriteLine stream, stat.name
- WriteInt stream, stat.usgn
- WriteInt stream, stat.score
- WriteInt stream, stat.kills
- WriteInt stream, stat.deaths
- WriteInt stream, stat.time
- Next
- CloseStream(stream)
- Notify("Stats saved succesfully!")
- Else
- Notify("Failed to save stats, cannot write in file", True)
- EndIf
- Else
- Notify("Failed to save stats, load stats first", True)
- EndIf
- EndFunction
- Function ReadStats()
- TStat.ResetList()
- If FileType("sys/stats/stats.dat") = 1 Then
- DeleteFile("sys/stats/stats.dat")
- EndIf
- Local stream:TStream = ReadStream("sys/stats/userstats.dat")
- If stream Then
- If ReadLine(stream) <> "userstats alpha" Then
- Return Null
- EndIf
- While Not Eof(stream)
- Local name$ = ReadLine(stream)
- Local size = StreamSize(stream) - StreamPos(stream)
- If size >= 20 Then
- Local usgn = ReadInt(stream)
- Local score = ReadInt(stream)
- Local kills = ReadInt(stream)
- Local deaths = ReadInt(stream)
- Local time = ReadInt(stream)
- TStat.AddList(name, usgn, score, kills, deaths, time)
- Else
- Exit
- EndIf
- Wend
- TStat.saved = True
- CloseStream(stream)
- Return True
- EndIf
- EndFunction
- Function LoadStatsMenu()
- If ReadStats() Then
- current_stats = Null
- SetGadgetText(stat_name, "")
- SetGadgetText(stat_usgn, "")
- SetGadgetText(stat_score, "")
- SetGadgetText(stat_kills, "")
- SetGadgetText(stat_deaths, "")
- SetGadgetText(stat_time, "")
- ClearGadgetItems(stat_player_menu)
- For stat:TStat = EachIn TStat.list
- AddGadgetItem(stat_player_menu, stat.name, 0, -1, "#"+stat.usgn)
- Next
- EnableGadget(add_entry_button)
- EnableGadget(create_entry_button)
- EnableGadget(button_save_stats)
- EnableGadget(entry_remove_button)
- Else
- Notify("Failed to load stats", True)
- EndIf
- EndFunction
- Function stats_id:TStat(id)
- Local i = 0
- For stat:TStat = EachIn TStat.list
- If i = id Then
- Return stat
- EndIf
- i = i + 1
- Next
- EndFunction
- Function open_stats_id(id)
- current_stats_id = id
- current_stats = stats_id(id)
- If current_stats Then
- SetGadgetText(stat_name, current_stats.name)
- SetGadgetText(stat_usgn, current_stats.usgn)
- SetGadgetText(stat_score, current_stats.score)
- SetGadgetText(stat_kills, current_stats.kills)
- SetGadgetText(stat_deaths, current_stats.deaths)
- SetGadgetText(stat_time, current_stats.time)
- EndIf
- EndFunction
- Function update_stats()
- If current_stats Then
- Local name$ = GadgetText(stat_name)
- Local usgn = Int(GadgetText(stat_usgn))
- Local score = Int(GadgetText(stat_score))
- Local kills = Int(GadgetText(stat_kills))
- Local deaths = Int(GadgetText(stat_deaths))
- Local time = Int(GadgetText(stat_time))
- Local modified = False
- If name <> current_stats.name Then
- modified = True
- ElseIf usgn <> current_stats.usgn Then
- modified = True
- ElseIf score <> current_stats.score Then
- modified = True
- ElseIf kills <> current_stats.kills Then
- modified = True
- ElseIf deaths <> current_stats.deaths Then
- modified = True
- ElseIf time <> current_stats.time Then
- modified = True
- EndIf
- If modified Then
- current_stats.name = GadgetText(stat_name)
- current_stats.usgn = Int(GadgetText(stat_usgn))
- current_stats.score = Int(GadgetText(stat_score))
- current_stats.kills = Int(GadgetText(stat_kills))
- current_stats.deaths = Int(GadgetText(stat_deaths))
- current_stats.time = Int(GadgetText(stat_time))
- ModifyGadgetItem(stat_player_menu, current_stats_id, name)
- TStat.saved = False
- EndIf
- EndIf
- EndFunction
- Function remove_current_entry()
- If current_stats And TStat.list Then
- ListRemove(TStat.list, current_stats)
- RemoveGadgetItem(stat_player_menu, current_stats_id)
- current_stats_id = Null
- current_stats = Null
- SetGadgetText(stat_name, "")
- SetGadgetText(stat_usgn, "")
- SetGadgetText(stat_score, "")
- SetGadgetText(stat_kills, "")
- SetGadgetText(stat_deaths, "")
- SetGadgetText(stat_time, "")
- EndIf
- EndFunction
- Function TextFieldIntFilter(e:TEvent,context:Object)
- Select e.id
- Case EVENT_KEYCHAR
- If e.data = 8 Then Return 1
- Return Instr("0123456789", Chr(e.data))
- EndSelect
- EndFunction
- Function add_stat_list()
- Local name$ = GadgetText(e_stat_name)
- Local usgn = Int(GadgetText(e_stat_usgn))
- Local score = Int(GadgetText(e_stat_score))
- Local kills = Int(GadgetText(e_stat_kills))
- Local deaths = Int(GadgetText(e_stat_deaths))
- Local time = Int(GadgetText(e_stat_time))
- If usgn > 0 Then
- If Len(name) > 0 Then
- If Not TStat.FindUSGN(usgn) Then
- TStat.AddList(name, usgn, score, kills, deaths, time)
- AddGadgetItem(stat_player_menu, name, 0, -1, "#"+usgn)
- Return True
- Else
- Notify("This U.S.G.N ID is already in the stats list!", True)
- EndIf
- Else
- Notify("You must specify a name!", True)
- EndIf
- Else
- Notify("You must specify an usgn id!", True)
- EndIf
- EndFunction
- AppTitle = "Stats Editor by Starkkz"
- Global current_stats_id
- Global current_stats:TStat
- Global main_window:TGadget = CreateWindow("Stats Editor by Starkkz", DesktopWidth()/2 - 150, DesktopHeight()/2 - 200, 300, 400, Null, WINDOW_TITLEBAR)
- Global button_load_stats:TGadget = CreateButton("Load Stats", 10, 15, 100, 25, main_window)
- Global button_save_stats:TGadget = CreateButton("Save Stats", 10, 45, 100, 25, main_window)
- Global entry_remove_button:TGadget = CreateButton("Remove Entry", 120, 45, 100, 25, main_window)
- Global create_entry_button:TGadget = CreateButton("Create Entry", 120, 15, 100, 25, main_window)
- Global stat_player_menu:TGadget = CreateComboBox(120, 75, 165, 25, main_window)
- Global entry_window:TGadget = CreateWindow("Create Entry", DesktopWidth()/2 - 125, DesktopHeight()/2 - 175, 250, 350, main_window, WINDOW_TITLEBAR|WINDOW_HIDDEN)
- Global add_entry_button:TGadget = CreateButton("Add Entry", 10, 285, 100, 25, entry_window)
- SetGadgetAlpha(entry_window, 0.9)
- DisableGadget(add_entry_button)
- DisableGadget(create_entry_button)
- DisableGadget(button_save_stats)
- DisableGadget(entry_remove_button)
- CreateLabel("Player Name", 10, 90, 100, 20, main_window)
- CreateLabel("USGN ID", 10, 135, 100, 20, main_window)
- CreateLabel("Score", 10, 180, 100, 20, main_window)
- CreateLabel("Kills", 10, 225, 100, 20, main_window)
- CreateLabel("Deaths", 10, 270, 100, 20, main_window)
- CreateLabel("Server time", 10, 315, 100, 20, main_window)
- CreateLabel("Player Name", 10, 10, 100, 20, entry_window)
- CreateLabel("USGN ID", 10, 55, 100, 20, entry_window)
- CreateLabel("Score", 10, 100, 100, 20, entry_window)
- CreateLabel("Kills", 10, 145, 100, 20, entry_window)
- CreateLabel("Deaths", 10, 190, 100, 20, entry_window)
- CreateLabel("Server time", 10, 235, 100, 20, entry_window)
- Global stat_name:TGadget = CreateTextField(10, 110, 170, 25, main_window)
- Global stat_usgn:TGadget = CreateTextField(10, 155, 170, 25, main_window)
- Global stat_score:TGadget = CreateTextField(10, 200, 170, 25, main_window)
- Global stat_kills:TGadget = CreateTextField(10, 245, 170, 25, main_window)
- Global stat_deaths:TGadget = CreateTextField(10, 290, 170, 25, main_window)
- Global stat_time:TGadget = CreateTextField(10, 335, 170, 25, main_window)
- Global e_stat_name:TGadget = CreateTextField(10, 30, 170, 25, entry_window)
- Global e_stat_usgn:TGadget = CreateTextField(10, 75, 170, 25, entry_window)
- Global e_stat_score:TGadget = CreateTextField(10, 120, 170, 25, entry_window)
- Global e_stat_kills:TGadget = CreateTextField(10, 165, 170, 25, entry_window)
- Global e_stat_deaths:TGadget = CreateTextField(10, 210, 170, 25, entry_window)
- Global e_stat_time:TGadget = CreateTextField(10, 255, 170, 25, entry_window)
- SetGadgetFilter(stat_usgn, TextFieldIntFilter)
- SetGadgetFilter(stat_score, TextFieldIntFilter)
- SetGadgetFilter(stat_kills, TextFieldIntFilter)
- SetGadgetFilter(stat_deaths, TextFieldIntFilter)
- SetGadgetFilter(stat_time, TextFieldIntFilter)
- SetGadgetFilter(e_stat_usgn, TextFieldIntFilter)
- SetGadgetFilter(e_stat_score, TextFieldIntFilter)
- SetGadgetFilter(e_stat_kills, TextFieldIntFilter)
- SetGadgetFilter(e_stat_deaths, TextFieldIntFilter)
- SetGadgetFilter(e_stat_time, TextFieldIntFilter)
- Repeat
- WaitEvent()
- Select EventID()
- Case EVENT_GADGETACTION
- Select EventSource()
- Case button_load_stats
- LoadStatsMenu()
- Case button_save_stats
- update_stats()
- SaveStats()
- Case stat_player_menu
- update_stats()
- open_stats_id(EventData())
- Case entry_remove_button
- remove_current_entry()
- Case create_entry_button
- ShowGadget(entry_window)
- Case add_entry_button
- If add_stat_list() Then
- HideGadget(entry_window)
- SetGadgetText(e_stat_name, "")
- SetGadgetText(e_stat_usgn, "")
- SetGadgetText(e_stat_score, "")
- SetGadgetText(e_stat_kills, "")
- SetGadgetText(e_stat_deaths, "")
- SetGadgetText(e_stat_time, "")
- EndIf
- EndSelect
- Case EVENT_WINDOWCLOSE
- Select EventSource()
- Case main_window
- If Not TStat.saved Then
- If Proceed("Stats haven't been saved, do you wish to save them?") Then
- SaveStats()
- EndIf
- EndIf
- End
- Case entry_window
- HideGadget(entry_window)
- SetGadgetText(e_stat_name, "")
- SetGadgetText(e_stat_usgn, "")
- SetGadgetText(e_stat_score, "")
- SetGadgetText(e_stat_kills, "")
- SetGadgetText(e_stat_deaths, "")
- SetGadgetText(e_stat_time, "")
- EndSelect
- EndSelect
- Forever
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement