Skip to content

Commit

Permalink
Don't play the jingle on round restart
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikusch committed Dec 10, 2023
1 parent 207c175 commit 4bcb998
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
38 changes: 18 additions & 20 deletions addons/sourcemod/scripting/tfco_donations.sp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <sdkhooks>
#include <ripext>

#define PLUGIN_VERSION "1.0.2"
#define PLUGIN_VERSION "1.0.3"

#define TFCONNECT_TAG "\x01[\a9E3083TFConnect\x01] "

Expand Down Expand Up @@ -132,6 +132,7 @@ void TogglePlugin(bool bEnable)
else
{
RemoveNormalSoundHook(OnSoundPlayed);
UnhookEvent("teamplay_round_start", OnGameEvent_teamplay_round_start);

tf_player_drop_bonus_ducks.RestoreDefault();

Expand Down Expand Up @@ -181,10 +182,15 @@ void OnDonationReceived(DonationData donation)
PrintToChatAll("\aE1C5F1%s: \x01\"%s\"", donation.name, donation.message);
}

void UpdateDonationDisplays(char[] message)
void OnTotalUpdated(int amount, bool bSilent = false)
{
char message[16];
if (!FormatMoney(amount / 100.0, message, sizeof(message)))
return;

// Update donation displays.
char szScriptCode[256];
Format(szScriptCode, sizeof(szScriptCode), "UpdateDonationDisplays(\"%s\")", message);
Format(szScriptCode, sizeof(szScriptCode), "UpdateTextEntities(\"%s\", %s)", message, bSilent ? "true" : "false");

SetVariantString(szScriptCode);
AcceptEntityInput(0, "RunScriptCode");
Expand Down Expand Up @@ -214,20 +220,20 @@ static Action Timer_RequestDonations(Handle timer)
// Query the campaign details first.
// Once that succeeds, we know that we can fetch current donations and goals.
HTTPRequest request = new HTTPRequest(CAMPAIGN_API_URL);
request.Get(OnCampaignGetRequest);
request.Get(GET_ActiveCampaign);

return Plugin_Continue;
}

// /api/campaigns/active
static void OnCampaignGetRequest(HTTPResponse response, any value)
static void GET_ActiveCampaign(HTTPResponse response, any value)
{
if (!g_bEnabled)
return;

if (response.Status != HTTPStatus_OK)
{
LogError("OnCampaignGetRequest: Failed with status %d", response.Status);
LogError("GET_ActiveCampaign: Failed with status %d", response.Status);
return;
}

Expand All @@ -246,27 +252,24 @@ static void OnCampaignGetRequest(HTTPResponse response, any value)
if (raised_cents != g_nRaisedCents)
{
g_nRaisedCents = raised_cents;

char message[16];
if (FormatMoney(raised_cents / 100.0, message, sizeof(message)))
UpdateDonationDisplays(message);
OnTotalUpdated(raised_cents);
}

// Now, query donations.
HTTPRequest request = new HTTPRequest(DONATION_API_URL);
request.AppendQueryParam("after_time", "%d", g_iLastCheckedTimestamp);
request.Get(OnDonationGetRequest);
request.Get(GET_Donations);
}

// /api/campaigns/active/donations
static void OnDonationGetRequest(HTTPResponse response, any value)
static void GET_Donations(HTTPResponse response, any value)
{
if (!g_bEnabled)
return;

if (response.Status != HTTPStatus_OK)
{
LogError("OnDonationGetRequest: Failed with status %d", response.Status);
LogError("GET_Donations: Failed with status %d", response.Status);
return;
}

Expand Down Expand Up @@ -319,11 +322,8 @@ static Action HandleCommand_TestDonation(int client, int args)

g_nRaisedCents += donation.cents_amount;

char message[64];
if (FormatMoney(g_nRaisedCents / 100.0, message, sizeof(message)))
UpdateDonationDisplays(message);

OnDonationReceived(donation);
OnTotalUpdated(g_nRaisedCents);

return Plugin_Handled;
}
Expand All @@ -344,7 +344,5 @@ static void OnGameEvent_teamplay_round_start(Event event, const char[] name, boo

static void OnRoundStarted()
{
char message[16];
if (FormatMoney(g_nRaisedCents / 100.0, message, sizeof(message)))
UpdateDonationDisplays(message);
OnTotalUpdated(g_nRaisedCents, true);
}
20 changes: 14 additions & 6 deletions scripts/vscripts/tfco_donations.nut
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ function OnGameEvent_teamplay_round_start(params)
{
if (!Convars.GetBool("sm_tfco_donation_enabled"))
return

// Resupply Locker
local regenerate
while (regenerate = Entities.FindByClassname(regenerate, "func_regenerate"))
{
local prop = NetProps.GetPropEntity(regenerate, "m_hAssociatedModel")
if (prop == null)
continue

local worldtext = SpawnEntityFromTable("point_worldtext",
{
targetname = TFCO_DONATION_TEXT_NAME,
Expand All @@ -36,13 +36,14 @@ function OnGameEvent_teamplay_round_start(params)
local bone = point.LookupBone("spinner")
if (bone == -1)
continue

local worldtext = SpawnEntityFromTable("point_worldtext",
{
targetname = TFCO_DONATION_TEXT_NAME,
textsize = "20",
origin = point.GetBoneOrigin(bone)
})

EntFireByHandle(worldtext, "SetParent", "!activator", -1, point, null)
AddThinkToEnt(worldtext, "ControlPointTextThink")
}
Expand Down Expand Up @@ -82,13 +83,20 @@ __CollectGameEventCallbacks(this)
return -1
}

::UpdateDonationDisplays <- function(message)
::UpdateTextEntities <- function(message, silent)
{
local worldtext
while (worldtext = Entities.FindByName(worldtext, TFCO_DONATION_TEXT_NAME))
{
worldtext.KeyValueFromString("message", message)
DispatchParticleEffect("bday_confetti", worldtext.GetOrigin(), worldtext.GetAbsAngles() + Vector())
worldtext.EmitSound("Game.HappyBirthdayNoiseMaker")

CalcTextTotalSize(worldtext)
local origin = worldtext.GetOrigin() - worldtext.GetAbsAngles().Left() * TextSizeOutWidth * -0.5

if (!silent)
{
DispatchParticleEffect("bday_confetti", origin, worldtext.GetAbsAngles() + Vector())
worldtext.EmitSound("Game.HappyBirthdayNoiseMaker")
}
}
}

0 comments on commit 4bcb998

Please sign in to comment.