diff --git a/examples/1vX/index.js b/examples/1vX/index.js new file mode 100644 index 00000000..878dfe33 --- /dev/null +++ b/examples/1vX/index.js @@ -0,0 +1,38 @@ +var {parseTicks, parseEvent} = require('@laihoe/demoparser2'); + +const pathToDemo = "path/to/demo.dem"; +// 1vX +const X = 4; + + +function find_if_1vx(deaths, round_idx, round_ends, tickData, X){ + for (let i = 0; i < deaths.length; i++){ + if (deaths[i].total_rounds_played == round_idx){ + + let tickData_slice = tickData.filter(t => t.tick == deaths[i].tick) + let ctAlive = tickData_slice.filter(t => t.team_name == "CT" && t.is_alive == true) + let tAlive = tickData_slice.filter(t => t.team_name == "TERRORIST" && t.is_alive == true) + // 3 = CT + if (ctAlive.length == 1 && tAlive.length == X && round_ends[round_idx].winner == 3){ + return ctAlive[0].name + } + // 2 = T + if (tAlive.length == 1 && ctAlive.length == X && round_ends[round_idx].winner == 2){ + return tAlive[0].name + } + } + } +} + +let deaths = parseEvent(pathToDemo, "player_death", [], ["total_rounds_played"]) +let wantedTicks = deaths.map(x => x.tick) +let round_ends = parseEvent(pathToDemo, "round_end") +let tickData = parseTicks(pathToDemo, ["is_alive", "team_name", "team_rounds_total"], wantedTicks) +let maxRound = Math.max(...deaths.map(x => x.total_rounds_played)) + +for (let i = 0; i <= maxRound; i++){ + let res = find_if_1vx(deaths, i, round_ends, tickData, X); + if (res != undefined){ + console.log("Round", i , res, "clutched a 1 v", X); + } +} diff --git a/examples/1vX/main.py b/examples/1vX/main.py new file mode 100644 index 00000000..6d59adb1 --- /dev/null +++ b/examples/1vX/main.py @@ -0,0 +1,32 @@ +from demoparser2 import DemoParser + +# 1vX +X = 4 +path_to_demo = "path/to/demo.dem" + +def find_if_1vx(deaths, round_idx, round_ends, df, X): + for _, death in deaths.iterrows(): + if death["total_rounds_played"] == round_idx: + + subdf = df[df["tick"] == death["tick"]] + ct_alive = subdf[(subdf["team_name"] == "CT") & (subdf["is_alive"] == True)] + t_alive = subdf[(subdf["team_name"] == "TERRORIST") & (subdf["is_alive"] == True)] + # 3 = CT + if len(ct_alive) == 1 and len(t_alive) == X and round_ends.iloc[round_idx]["winner"] == 3: + return ct_alive["name"].iloc[0] + # 2 = T + if len(t_alive) == 1 and len(ct_alive) == X and round_ends.iloc[round_idx]["winner"] == 2: + return t_alive["name"].iloc[0] + + +parser = DemoParser(path_to_demo) +deaths = parser.parse_event("player_death", other=["total_rounds_played"]) +round_ends = parser.parse_event("round_end") +df = parser.parse_ticks(["is_alive", "team_name", "team_rounds_total"], ticks=deaths["tick"].to_list()) +max_round = deaths["total_rounds_played"].max() + 1 + +for round_idx in range(0, max_round): + clutcher_steamid = find_if_1vx(deaths, round_idx, round_ends, df, X) + if clutcher_steamid != None: + print("a", clutcher_steamid, file) +