Freeman185

SHEMA Updt

Jul 31st, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.82 KB | None | 0 0
  1. customSchema = class({})
  2.  
  3. function customSchema:init()
  4.  
  5. -- Check the schema_examples folder for different implementations
  6.  
  7. -- Flag Example
  8. statCollection:setFlags({ version = 2.16 })
  9.  
  10. -- Listen for changes in the current state
  11. ListenToGameEvent('game_rules_state_change', function(keys)
  12. local state = GameRules:State_Get()
  13.  
  14. -- Send custom stats when the game ends
  15. if state == DOTA_GAMERULES_STATE_POST_GAME then
  16.  
  17. -- Build game array
  18. local game = BuildGameArray()
  19.  
  20. -- Build players array
  21. local players = BuildPlayersArray()
  22.  
  23. -- Print the schema data to the console
  24. if statCollection.TESTING then
  25. PrintSchema(game, players)
  26. end
  27.  
  28. -- Send custom stats
  29. if statCollection.HAS_SCHEMA then
  30. statCollection:sendCustom({ game = game, players = players })
  31. end
  32. end
  33. end, nil)
  34. end
  35.  
  36. -------------------------------------
  37.  
  38. -- In the statcollection/lib/utilities.lua, you'll find many useful functions to build your schema.
  39. -- You are also encouraged to call your custom mod-specific functions
  40.  
  41. -- Returns a table with our custom game tracking.
  42. function BuildGameArray()
  43. local game = {}
  44.  
  45. -- Add game values here as game.someValue = GetSomeGameValue()
  46. game.gl = GAME_TIME_ELAPSED -- Game length, from the horn sound, in seconds
  47. game.wt = GAME_WINNER_TEAM -- Winning team
  48.  
  49. return game
  50. end
  51.  
  52. -- Returns a table containing data for every player in the game
  53. function BuildPlayersArray()
  54. local players = {}
  55. for playerID = 0, DOTA_MAX_PLAYERS do
  56. if PlayerResource:IsValidPlayerID(playerID) then
  57. if not PlayerResource:IsBroadcaster(playerID) then
  58.  
  59. local hero = PlayerResource:GetSelectedHeroEntity(playerID)
  60.  
  61. -- Team string logic
  62. local player_team = ""
  63. if hero:GetTeam() == DOTA_TEAM_GOODGUYS then
  64. player_team = "Republic"
  65. else
  66. player_team = "Empire"
  67. end
  68.  
  69. table.insert(players, {
  70. -- steamID32 required in here
  71. steamID32 = PlayerResource:GetSteamAccountID(playerID),
  72.  
  73. -- Example functions for generic stats are defined in statcollection/lib/utilities.lua
  74. -- Add player values here as someValue = GetSomePlayerValue(),
  75.  
  76. HeroName = GetHeroName(playerID), -- Hero by its short name
  77. HeroLevel = hero:GetLevel(), -- Hero level at the end of the game
  78. PlayerNetWorth = GetNetworth(hero), -- Sum of hero gold and item worth
  79. PlayerTeam = player_team, -- Team this hero belongs to
  80. PlayerKills = hero:GetKills(), -- Number of kills of this players hero
  81. PlayerAssist = hero:GetAssists(), -- Number of deaths of this players hero
  82. PlayerDeaths = hero:GetDeaths(), -- Number of deaths of this players hero
  83. --- PlayerRaitng = GetPlayerRaiting(playerID), -- Player raiting(custom mmr)
  84. })
  85. end
  86. end
  87. end
  88.  
  89. return players
  90. end
  91.  
  92. -- Prints the custom schema, required to get an schemaID
  93. function PrintSchema(gameArray, playerArray)
  94. print("-------- GAME DATA --------")
  95. DeepPrintTable(gameArray)
  96. print("\n-------- PLAYER DATA --------")
  97. DeepPrintTable(playerArray)
  98. print("-------------------------------------")
  99. end
  100.  
  101. -- Write 'test_schema' on the console to test your current functions instead of having to end the game
  102. if Convars:GetBool('developer') then
  103. Convars:RegisterCommand("test_schema", function() PrintSchema(BuildGameArray(), BuildPlayersArray()) end, "Test the custom schema arrays", 0)
  104. end
  105.  
  106. -------------------------------------
  107.  
  108. -- If your gamemode is round-based, you can use statCollection:submitRound(bLastRound) at any point of your main game logic code to send a round
  109. -- If you intend to send rounds, make sure your settings.kv has the 'HAS_ROUNDS' set to true. Each round will send the game and player arrays defined earlier
  110. -- The round number is incremented internally, lastRound can be marked to notify that the game ended properly
  111. function customSchema:submitRound(isLastRound)
  112.  
  113. local winners = BuildRoundWinnerArray()
  114. local game = BuildGameArray()
  115. local players = BuildPlayersArray()
  116.  
  117. statCollection:sendCustom({ game = game, players = players })
  118.  
  119. isLastRound = isLastRound or false --If the function is passed with no parameter, default to false.
  120. return { winners = winners, lastRound = isLastRound }
  121. end
  122.  
  123. -- A list of players marking who won this round
  124. function BuildRoundWinnerArray()
  125. local winners = {}
  126. local current_winner_team = GameRules.Winner or 0 --You'll need to provide your own way of determining which team won the round
  127. for playerID = 0, DOTA_MAX_PLAYERS do
  128. if PlayerResource:IsValidPlayerID(playerID) then
  129. if not PlayerResource:IsBroadcaster(playerID) then
  130. winners[PlayerResource:GetSteamAccountID(playerID)] = (PlayerResource:GetTeam(playerID) == current_winner_team) and 1 or 0
  131. end
  132. end
  133. end
  134. return winners
  135. end
  136.  
  137. --[[function GetPlayerRaiting(id)
  138. local hero = PlayerResource:GetSelectedHeroEntity(playerID)
  139. local id = hero:GetTeamNumber()
  140.  
  141.  
  142. end
  143.  
  144. function IsPlayerLose(teamID)
  145. local allAncients = Entities:FindAllByClassname("npc_dota_fort")
  146. for k, fort in pairs(allAncients) do
  147. if fort:IsAlive() == false
  148. if fort:GetTeamNumber() == teamID then
  149. return true
  150. else
  151. return false
  152. end
  153. end
  154. end
  155. end]]
Advertisement
Add Comment
Please, Sign In to add comment