Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Nemesis & Dynamic Channels support. Fix: Hud position, CI update #2

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
20 changes: 15 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
name: CI

on: [push, pull_request]
on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
branches:
- main
- master

jobs:
build:
name: "Build"
runs-on: ${{ matrix.os }}
runs-on: package
strategy:
fail-fast: false
matrix:
Expand All @@ -31,7 +41,7 @@ jobs:
- name: Upload build archive for test runners
uses: actions/upload-artifact@v3
with:
name: ${{ runner.os }}
name: package
path: /tmp/package

tag:
Expand Down Expand Up @@ -76,8 +86,8 @@ jobs:
- name: Package
run: |
ls -Rall
if [ -d "./Linux/" ]; then
cd ./Linux/
if [ -d "./package/" ]; then
cd ./package/
tar -czf ../${{ github.event.repository.name }}-${{ env.RELEASE_VERSION }}.tar.gz -T <(\ls -1)
cd -
fi
Expand Down
132 changes: 99 additions & 33 deletions addons/sourcemod/scripting/TopInfectors.sp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <multicolors>
#include <clientprefs>

#undef REQUIRE_PLUGIN
#tryinclude <DynamicChannels>
#define REQUIRE_PLUGIN

#include "loghelper.inc"
#include "utilshelper.inc"

Expand All @@ -13,16 +17,16 @@

enum WeaponAmmoGrenadeType
{
GrenadeType_Invalid = -1, /** Invalid grenade slot. */
GrenadeType_HEGrenade = 11, /** CSS - HEGrenade slot */
GrenadeType_Flashbang = 12, /** CSS - Flashbang slot. */
GrenadeType_Smokegrenade = 13, /** CSS - Smokegrenade slot. */
GrenadeType_HEGrenadeCSGO = 14, /** CSGO - HEGrenade slot. */
GrenadeType_FlashbangCSGO = 15, /** CSGO - Flashbang slot. */
GrenadeType_SmokegrenadeCSGO = 16, /** CSGO - Smokegrenade slot. */
GrenadeType_Incendiary = 17, /** CSGO - Incendiary and Molotov slot. */
GrenadeType_Decoy = 18, /** CSGO - Decoy slot. */
GrenadeType_Tactical = 22, /** CSGO - Tactical slot. */
GrenadeType_Invalid = -1, /** Invalid grenade slot. */
GrenadeType_HEGrenade = 11, /** CSS - HEGrenade slot */
GrenadeType_Flashbang = 12, /** CSS - Flashbang slot. */
GrenadeType_Smokegrenade = 13, /** CSS - Smokegrenade slot. */
GrenadeType_HEGrenadeCSGO = 14, /** CSGO - HEGrenade slot. */
GrenadeType_FlashbangCSGO = 15, /** CSGO - Flashbang slot. */
GrenadeType_SmokegrenadeCSGO = 16, /** CSGO - Smokegrenade slot. */
GrenadeType_Incendiary = 17, /** CSGO - Incendiary and Molotov slot. */
GrenadeType_Decoy = 18, /** CSGO - Decoy slot. */
GrenadeType_Tactical = 22, /** CSGO - Tactical slot. */
}

#define BELL_SOUND_COMMON "topinfectors/bell.wav"
Expand All @@ -39,7 +43,7 @@ int g_iTopInfector[MAXPLAYERS + 1] = { -1, ... };
int g_iPrintColor[3];
float g_fPrintPos[2];

ConVar g_cvHat, g_cvAmount, g_cvNades, g_cvPrint, g_cvPrintPos, g_cvPrintColor;
ConVar g_cvHat, g_cvAmount, g_cvHENades, g_cvSmokeNades, g_cvPrint, g_cvPrintPos, g_cvPrintColor, g_cvHUDChannel;

Handle g_hHudSync = INVALID_HANDLE;

Expand All @@ -48,13 +52,15 @@ Handle g_hSpawnTimer[MAXPLAYERS + 1];
Handle g_hCookie_HideSkull;

bool g_bIsCSGO = false;
bool g_bNemesis = false;
bool g_bDynamicChannels = false;

public Plugin myinfo =
{
name = "Top Infectors",
author = "Nano, maxime1907, .Rushaway",
description = "Show top infectors after each round",
version = "1.2",
version = "1.2.1",
}

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
Expand All @@ -70,11 +76,13 @@ public void OnPluginStart()
LoadTranslations("topinfectors.phrases");

g_cvAmount = CreateConVar("sm_topinfectors_players", "3", "Amount of players on the top infectors table", _, true, 0.0, true, 5.0);
g_cvNades = CreateConVar("sm_topinfectors_nades", "1", "How much nades are given to top infectors", _, true, 0.0, true, 10.0);
g_cvHENades = CreateConVar("sm_topinfectors_nades", "1", "How much nades are given to top infectors", _, true, 0.0, true, 10.0);
g_cvSmokeNades = CreateConVar("sm_topinfectors_smokes", "1", "How much smokes are given to top killers", _, true, 0.0, true, 10.0);
g_cvHat = CreateConVar("sm_topinfectors_hat", "1", "Enable hat on top infectors", _, true, 0.0, true, 1.0);
g_cvPrint = CreateConVar("sm_topinfectors_print", "0", "2 - Display in hud, 1 - In chat, 0 - Both", _, true, 0.0, true, 2.0);
g_cvPrintPos = CreateConVar("sm_topinfectors_print_position", "0.02 0.42", "The X and Y position for the hud.");
g_cvPrintColor = CreateConVar("sm_topinfectors_print_color", "255 0 0", "RGB color value for the hud.");
g_cvHUDChannel = CreateConVar("sm_topinfectors_hud_channel", "2", "The channel for the hud if using DynamicChannels", _, true, 0.0, true, 6.0);

g_cvPrint.AddChangeHook(OnConVarChange);
g_cvPrintPos.AddChangeHook(OnConVarChange);
Expand Down Expand Up @@ -102,6 +110,28 @@ public void OnPluginEnd()
Cleanup(true);
}

public void OnAllPluginsLoaded()
{
g_bNemesis = LibraryExists("Nemesis");
g_bDynamicChannels = LibraryExists("DynamicChannels");
}

public void OnLibraryAdded(const char[] name)
{
if (strcmp(name, "Nemesis", false) == 0)
g_bNemesis = true;
if (strcmp(name, "DynamicChannels", false) == 0)
g_bDynamicChannels = true;
}

public void OnLibraryRemoved(const char[] name)
{
if (strcmp(name, "Nemesis", false) == 0)
g_bNemesis = false;
if (strcmp(name, "DynamicChannels", false) == 0)
g_bDynamicChannels = false;
}

public void OnConVarChange(ConVar convar, char[] oldValue, char[] newValue)
{
GetConVars();
Expand All @@ -121,10 +151,10 @@ public void OnMapStart()

public void OnMapEnd()
{
for (int i = 1; i <= MaxClients; i++)
{
delete g_hSpawnTimer[i];
}
for (int i = 1; i <= MaxClients; i++)
{
delete g_hSpawnTimer[i];
}
}

public void OnClientPutInServer(int client)
Expand Down Expand Up @@ -200,6 +230,13 @@ public void Event_OnClientDeath(Event hEvent, const char[] sEvent, bool bDontBro

break;
}

if (g_bNemesis)
{
int attacker = GetClientOfUserId(hEvent.GetInt("attacker"));
if (attacker > 0 && attacker <= MaxClients && IsClientInGame(attacker) && IsPlayerAlive(attacker) && ZR_IsClientZombie(attacker))
g_iInfectCount[attacker]++;
}
}

public void Event_OnRoundStart(Event event, char[] name, bool dontBroadcast)
Expand Down Expand Up @@ -246,21 +283,39 @@ public void Event_OnRoundEnd(Event event, char[] name, bool dontBroadcast)
return;

char sBuffer[512];
Format(sBuffer, sizeof(sBuffer), "TOP INFECTORS:");
Format(sBuffer, sizeof(sBuffer), "TOP %s:", g_bNemesis ? "NEMESIS" : "INFECTORS");

for (int i = 0; i < g_cvAmount.IntValue; i++)
{
if (iSortedList[i][0])
{
g_iTopInfector[iSortedList[i][0]] = i;
Format(sBuffer, sizeof(sBuffer), "%s\n%d. %N - %d INFECTED", sBuffer, i + 1, iSortedList[i][0], iSortedList[i][1]);
LogPlayerEvent(iSortedList[i][0], "triggered", i == 0 ? "top_infector" : (i == 1 ? "second_infector" : (i == 2 ? "third_infector" : "super_infector")));
Format(sBuffer, sizeof(sBuffer), "%s\n%d. %N - %d %s", sBuffer, i + 1, iSortedList[i][0], iSortedList[i][1], g_bNemesis ? "KILLED" : "INFECTED");

if (g_bNemesis)
LogPlayerEvent(iSortedList[i][0], "triggered", i == 0 ? "top_nemesis" : (i == 1 ? "second_nemesis" : (i == 2 ? "third_nemesis" : "super_nemesis")));
else
LogPlayerEvent(iSortedList[i][0], "triggered", i == 0 ? "top_infector" : (i == 1 ? "second_infector" : (i == 2 ? "third_infector" : "super_infector")));
}
}

if (g_cvPrint.IntValue <= 0 || g_cvPrint.IntValue == 1)
CPrintToChatAll("{darkred}%s", sBuffer);

bool bDynamicAvailable = false;
int iHUDChannel = -1;

int iChannel = g_cvHUDChannel.IntValue;
if (iChannel < 0 || iChannel > 6)
iChannel = 2;

bDynamicAvailable = g_bDynamicChannels && CanTestFeatures() && GetFeatureStatus(FeatureType_Native, "GetDynamicChannel") == FeatureStatus_Available;

#if defined _DynamicChannels_included_
if (bDynamicAvailable)
iHUDChannel = GetDynamicChannel(iChannel);
#endif

if (g_cvPrint.IntValue <= 0 || g_cvPrint.IntValue == 2)
{
SetHudTextParams(g_fPrintPos[0], g_fPrintPos[1], 5.0, g_iPrintColor[0], g_iPrintColor[1], g_iPrintColor[2], 255, 0, 0.0, 0.1, 0.1);
Expand All @@ -270,8 +325,13 @@ public void Event_OnRoundEnd(Event event, char[] name, bool dontBroadcast)
if (!IsValidClient(client))
continue;

ClearSyncHud(client, g_hHudSync);
ShowSyncHudText(client, g_hHudSync, "%s", sBuffer);
if (bDynamicAvailable)
ShowHudText(client, iHUDChannel, "%s", sBuffer);
else
{
ClearSyncHud(client, g_hHudSync);
ShowSyncHudText(client, g_hHudSync, "%s", sBuffer);
}
}
}
}
Expand All @@ -287,7 +347,7 @@ public void SetPerks(int client, char[] notifHudMsg, char[] notifChatMsg)
PbSetInt(hMessageInfection, "effect", 0);
PbSetColor(hMessageInfection, "clr1", {255, 255, 255, 255});
PbSetColor(hMessageInfection, "clr2", {255, 255, 255, 255});
PbSetVector2D(hMessageInfection, "pos", view_as<float>({-1.0, 0.3}));
PbSetVector2D(hMessageInfection, "pos", view_as<float>({-1.0, 0.2}));
PbSetFloat(hMessageInfection, "fade_in_time", 0.1);
PbSetFloat(hMessageInfection, "fade_out_time", 0.1);
PbSetFloat(hMessageInfection, "hold_time", 5.0);
Expand All @@ -299,7 +359,7 @@ public void SetPerks(int client, char[] notifHudMsg, char[] notifChatMsg)
{
BfWriteByte(hMessageInfection, 50);
BfWriteFloat(hMessageInfection, -1.0);
BfWriteFloat(hMessageInfection, 0.3);
BfWriteFloat(hMessageInfection, 0.2);
BfWriteByte(hMessageInfection, 0);
BfWriteByte(hMessageInfection, 255);
BfWriteByte(hMessageInfection, 255);
Expand All @@ -318,9 +378,14 @@ public void SetPerks(int client, char[] notifHudMsg, char[] notifChatMsg)
}
}

CPrintToChat(client, "{darkblue}%t {grey}%s", "Chat Prefix", notifChatMsg);
if (g_bNemesis)
CPrintToChat(client, "{darkred}[TopNemesis] {grey}%s", notifChatMsg);
else
CPrintToChat(client, "{darkblue}%t {grey}%s", "Chat Prefix", notifChatMsg);

GiveGrenadesToClient(client, g_cvNades.IntValue, g_bIsCSGO ? GrenadeType_HEGrenadeCSGO : GrenadeType_HEGrenade);
GiveGrenadesToClient(client, g_cvHENades.IntValue, g_bIsCSGO ? GrenadeType_HEGrenadeCSGO : GrenadeType_HEGrenade);
if (g_bNemesis)
GiveGrenadesToClient(client, g_cvSmokeNades.IntValue, g_bIsCSGO ? GrenadeType_SmokegrenadeCSGO : GrenadeType_Smokegrenade);

if (g_iTopInfector[client] != 0 || g_bHideSkull[client])
return;
Expand All @@ -345,11 +410,11 @@ public Action Timer_OnClientSpawnPost(Handle timer, any client)
if (!IsValidClient(client) || !IsPlayerAlive(client) || g_iTopInfector[client] <= -1 || !ZR_IsClientHuman(client))
return Plugin_Continue;

SetPerks(
client,
"You have been rewarded grenades\nsince you were the Top Infector last round!",
"You have been rewarded grenades since you were the Top Infector last round!"
);
char sHudMsg[256], sNotifMsg[256];
FormatEx(sHudMsg, sizeof(sHudMsg), "You have been rewarded grenades\nsince you were the Top %s last round!", g_bNemesis ? "Nemesis" : "Infector");
FormatEx(sNotifMsg, sizeof(sNotifMsg), "You have been rewarded grenades since you were the Top %s last round!", g_bNemesis ? "Nemesis" : "Infector");
SetPerks(client, sHudMsg, sNotifMsg);

return Plugin_Continue;
}

Expand Down Expand Up @@ -466,6 +531,7 @@ stock void ToggleSkull(int client)
CreateHat_CSS(client);
}
}

CPrintToChat(client, "{darkblue}%t {grey}%t", "Chat Prefix", g_bHideSkull[client] ? "Skull Disabled" : "Skull Enabled");
}

Expand Down Expand Up @@ -601,7 +667,7 @@ public int SortInfectorsList(int[] elem1, int[] elem2, const int[][] array, Hand

bool IsValidZombie(int attacker)
{
return (0 < attacker <= MaxClients && IsValidEntity(attacker) && IsClientInGame(attacker) && IsPlayerAlive(attacker));
return (0 < attacker <= MaxClients && IsValidEntity(attacker) && IsClientInGame(attacker) && IsPlayerAlive(attacker));
}

//---------------------------------------
Expand All @@ -616,4 +682,4 @@ public int Native_IsTopInfector(Handle plugin, int numParams)
return g_iTopInfector[client];
}
return -1;
}
}
13 changes: 10 additions & 3 deletions sourceknight.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
project:
sourceknight: 0.1
sourceknight: 0.2
name: TopInfectors
dependencies:
- name: sourcemod
type: tar
version: 1.11.0-git6917
location: https://sm.alliedmods.net/smdrop/1.11/sourcemod-1.11.0-git6917-linux.tar.gz
version: 1.11.0-git6934
location: https://sm.alliedmods.net/smdrop/1.11/sourcemod-1.11.0-git6934-linux.tar.gz
unpack:
- source: /addons
dest: /addons
Expand Down Expand Up @@ -38,6 +38,13 @@ project:
- source: /addons/sourcemod/scripting/include
dest: /addons/sourcemod/scripting/include

- name: dynamicchannels
type: git
repo: https://github.com/srcdslab/sm-plugin-DynamicChannels
unpack:
- source: /scripting/include
dest: /addons/sourcemod/scripting/include

root: /
output: /addons/sourcemod/plugins
targets:
Expand Down
Loading