キモブロ

Please spy check please, Fucking retard

MvM鯖プレイ回数統計

こんな感じにした

'select * from game_stats;'
+-----+------------------------------+------+--------+--------+
| id  | map_code                     | win  | played | loaded |
+-----+------------------------------+------+--------+--------+
|  43 | mvm_diverge_b4               |    0 |      0 |      0 |
|  44 | mvm_strider_a6               |    0 |      0 |      0 |
|  53 | mvm_gateway_rc1              |    0 |      0 |      0 |
|  54 | mvm_manndarin_final          |    0 |      0 |      0 |
|  55 | mvm_fakeout_a2               |    0 |      0 |      0 |
|  56 | mvm_open_final_industry      |    0 |      0 |      1 |
|  65 | mvm_Scream_Tv                |    0 |      0 |      0 |
|  80 | mvm_hangtown_v1_2            |    0 |      0 |      0 |
|  82 | mvm_beartrap_a2              |    0 |      0 |      0 |
|  97 | mvm_15wave_of_the_dead_2_fix |    0 |      0 |      0 |
|  99 | mvm_redbrier_b3              |    0 |      0 |      0 |
| 121 | mvm_decoy                    |    0 |      0 |      0 |
| 122 | mvm_labo_a1                  |    0 |      0 |      0 |
| 124 | mvm_mountain_b3              |    0 |      0 |      1 |
| 126 | mvm_processing_v3            |    0 |      0 |      0 |
| 156 | mvm_open_final_swamp         |    0 |      0 |      1 |
| 161 | mvm_badlands_v2fix           |    0 |      0 |      0 |
| 167 | mvm_degrootkeep_b1           |    0 |      0 |      0 |
| 175 | mvm_mannworks                |    0 |      0 |      0 |
| 176 | mvm_manncohq_v3              |    0 |      0 |      0 |
| 181 | mvm_paradigm_a6a             |    0 |      0 |      0 |
| 207 | mvm_monastery_a1             |    0 |      0 |      0 |
| 215 | mvm_orange_x3                |    0 |      0 |      0 |
| 222 | mvm_coaltown                 |    0 |      0 |      0 |
+-----+------------------------------+------+--------+--------+

これをもとにクリア率とか算出してどのマップをfixするかとか決める


集計してるSourceMODはこんな感じのコード

#pragma semicolon 1
#include <sourcemod>
#include <dbi>
#define PLUGIN_VERSION "1.0.0"

public Plugin:myinfo =  
{
  name = "MvM Stats",
  author = "kimoto",
  description = "MvM Stats",
  version = PLUGIN_VERSION,
  url = "http://kymt.me/"
};

new Handle:db = INVALID_HANDLE;
new bool:alreadySent = false;

PrintLastError()
{
  decl String:error[256];
  SQL_GetError(db, error, sizeof(error));
  PrintToServer("Failed to query (error: %s)", error);
}

InitDB()
{
  alreadySent = false;
  LogMessage("try to connect mysql server");
  new String:error[256];
  if((db = SQL_DefConnect(error, sizeof(error))) == INVALID_HANDLE) {
    PrintToServer("Could not connect (enable silent mode): %s", error);
    return;
  }
  LogMessage("connected: %s", error);
}

IsAliveDB()
{
  return (db != INVALID_HANDLE);
}

CountLoaded()
{
  if(!IsAliveDB()) return;
  decl String:map[256];
  GetCurrentMap(map, sizeof(map));
  SQL_QuoteString(db, map, map, sizeof(map));
  decl String:query[256];
  Format(query, sizeof(query), "insert into game_stats (map_code, loaded) VALUES (\"%s\", 1) ON DUPLICATE KEY UPDATE loaded = loaded + 1;", map);
  if(!SQL_FastQuery(db, query)){
    PrintLastError();
  }
}

CountPlayed()
{
  if(!IsAliveDB()) return;
  decl String:map[256];
  GetCurrentMap(map, sizeof(map));
  SQL_QuoteString(db, map, map, sizeof(map));
  decl String:query[256];
  Format(query, sizeof(query), "insert into game_stats (map_code, played) VALUES (\"%s\", 1) ON DUPLICATE KEY UPDATE played = played + 1;", map);
  if(!SQL_FastQuery(db, query)){
    PrintLastError();
  }
}

CountWin()
{
  if(!IsAliveDB()) return;
  decl String:map[256];
  GetCurrentMap(map, sizeof(map));
  SQL_QuoteString(db, map, map, sizeof(map));
  decl String:query[256];
  Format(query, sizeof(query), "insert into game_stats (map_code, win) VALUES (\"%s\", 1) ON DUPLICATE KEY UPDATE win = win + 1;", map);
  if(!SQL_FastQuery(db, query)){
    PrintLastError();
  }
}

CloseDB()
{
  if(IsAliveDB())
    CloseHandle(db);
}

public OnPluginStart()
{
  InitDB();
  HookEvent("mvm_mission_complete", Event_MissionComplete, EventHookMode_PostNoCopy);
  HookEvent("teamplay_round_active", Event_RoundActive, EventHookMode_PostNoCopy);
}

public Action:Event_RoundActive(Handle:event, const String:name[], bool:dontBroadcast)
{
  if(alreadySent == false){
    CountPlayed();
    alreadySent = true;
  }
}

public Action:Event_MissionComplete(Handle:event, const String:name[], bool:dontBroadcast)
{
  LogMessage("event mission complete!!");
  CountWin();
}

public OnPluginEnd()
{
  CloseDB();
}

public OnMapStart()
{
  alreadySent = false;
  CountLoaded();
}