Skip to content

Instantly share code, notes, and snippets.

@ProdigySim
Created January 24, 2013 08:16
Show Gist options
  • Save ProdigySim/4618651 to your computer and use it in GitHub Desktop.
Save ProdigySim/4618651 to your computer and use it in GitHub Desktop.
A little project I'm working on.
#include <sourcemod>
#include <sdktools>
#include <left4downtown>
#include <l4d2_direct>
#include <l4d2util>
stock SetVersusRoundInProgress(bool:inProgress)
{
static Address:pRoundInProgress = Address_Null;
if(pRoundInProgress == Address_Null)
{
new offset = L4D2Direct_GetCDirectorVersusModeOffset("m_bVersusRoundInProgress");
if(offset == -1)
{
SetFailState("Failed to read CDirectorVersusMode::m_bVersusRoundInProgress offset");
}
pRoundInProgress = L4D2Direct_GetCDirectorVersusMode() + Address:offset;
}
StoreToAddress(pRoundInProgress, inProgress ? 1 : 0, NumberType_Int8);
}
public Action:OnEndVersusModeRound(bool:count_survivors)
{
new campaignScores[2];
new chapterScores[2];
new bool:tiebreak = false;
L4D2_GetVersusCampaignScores(campaignScores);
chapterScores[0] = (campaignScores[0] * 2) + 1;
chapterScores[1] = (campaignScores[1] * 2) + 2;
ShowRoundEndScores(campaignScores[0],campaignScores[1],chapterScores[0],chapterScores[1],tiebreak);
L4D2_SetVersusCampaignScores(campaignScores);
L4D2Direct_DirectorEndScenario(5);
SetVersusRoundInProgress(false);
if(InSecondHalfOfRound() && L4D_IsMissionFinalMap())
{
FireMatchEndEvent(CalculateWinner(campaignScores[0], campaignScores[1]));
}
// Block invocation since we're implementing it ourselves
return Plugin_Handled;
}
// Campaign score 1 (pre),
// Campaign score 2 (pre),
// Chapter score 1,
// Chapter score 2,
// Show tiebreak
ShowRoundEndScores(t1,t2,c1,c2,bool:tiebreak)
{
new iTiebreak = tiebreak ? 1 : 0;
new Handle:scoreKv = CreateKeyValues("scores");
KvSetNum(scoreKv, "t1", t1);
KvSetNum(scoreKv, "t2", t2);
KvSetNum(scoreKv, "c1", c1);
KvSetNum(scoreKv, "c2", c2);
KvSetNum(scoreKv, "tiebreak", iTiebreak);
for(new i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i))
{
ShowVGUIPanel(i, "fullscreen_vs_scoreboard", scoreKv);
}
}
}
// 0: tie
// 1: team 0/1
// 2: team 1/2
FireMatchEndEvent(winner)
{
new Handle:event = CreateEvent("versus_match_finished", true);
SetEventInt(event, "winners", winner);
FireEvent(event);
}
stock CalculateWinner(score1, score2)
{
// The disasm of valve's version of this calculation is pretty cute.
// Possibly a compiler optimization.
// I try to be a little more explicit but still efficient.
new diff = score1 - score2;
if(diff > 0)
{
// score1 > score2 == winner 1
return 1;
}
else if (diff < 0)
{
// score2 > score 1 == winner 2
return 2;
}
// score2 == score1 === winner 0
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment