Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// It's not perfect, but we can find the attacker with reasonable accuracy by finding the closest player to inflictorWorldPos.
const attacker = _.minBy(demo.players, p => {
return distance3(p.position, e.msg.inflictorWorldPos);
});
if (victim && attacker && victim.index !== attacker.index
&& attacker.isAlive && distance3(attacker.position, e.msg.inflictorWorldPos) < 50) {
const victimTeam = getTeam(victim);
const attackerTeam = getTeam(attacker);
const amount = e.msg.amount;
const weapon = attacker.weapon.className;
// console.log(`${attacker.name} (${attackerTeam}) attacked ${victim.name} (${victimTeam}) for ${amount} damage with ${weapon}`);
attacks.push({
time: demo.currentTime,
round: demo.gameRules.roundsPlayed,
score: {
T: demo.teams[demofile.TEAM_TERRORISTS].score,
CT: demo.teams[demofile.TEAM_CTS].score,
},
attacker: {
pos: attacker.position,
team: attackerTeam,
name: attacker.name,
},
victim: {
pos: victim.position,
team: victimTeam,
name: victim.name,
},
amount: amount,
weapon: weapon,
});
}
rxop.filter(e => (e.winner === demofile.TEAM_TERRORISTS || e.winner === demofile.TEAM_CTS) && e.reason < 11),
rxop.map(e => {
rxop.map(() => {
let tScore = demo.teams[demofile.TEAM_TERRORISTS].score;
let ctScore = demo.teams[demofile.TEAM_CTS].score;
let lastTScore = lastRoundScore[demo.teams[demofile.TEAM_TERRORISTS].clanName] || 0;
let lastCTScore = lastRoundScore[demo.teams[demofile.TEAM_CTS].clanName] || 0;
let winner = tScore > lastTScore ? 'T' : (ctScore > lastCTScore ? 'CT' : undefined);
lastRoundScore = {};
lastRoundScore[demo.teams[demofile.TEAM_TERRORISTS].clanName] = tScore;
lastRoundScore[demo.teams[demofile.TEAM_CTS].clanName] = ctScore;
return {winner};
}),
);