Skip to content
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
48 changes: 25 additions & 23 deletions addons/sourcemod/scripting/FunModes.sp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Plugin myinfo =
name = "FunModes",
author = "Dolly",
description = "bunch of fun modes for ze mode",
version = "2.0.0",
version = "2.1.0",
url = "https://nide.gg"
}

Expand Down Expand Up @@ -57,6 +57,10 @@ public void OnPluginStart()
RegAdminCmd(commands[i], Cmd_FunModes, ADMFLAG_CONVARS, "Show all available funmodes");
}

g_iNetPropAmmoIndex = FindSendPropInfo("CBasePlayer", "m_iAmmo");
if (g_iNetPropAmmoIndex == -1)
SetFailState("[FunModes] Could not find offset `CBasePlayer::m_iAmmo`");

GameData gd = new GameData("sdkhooks.games/engine.ep2v");
if (gd == null)
LogError("[FunModes] Could not find \"sdkhooks.games/engine.ep2v.txt\" file.");
Expand Down Expand Up @@ -108,13 +112,6 @@ public void OnMapStart()

public void OnMapEnd()
{
for (int i = 1; i <= MaxClients; i++)
{
g_bSDKHook_OnTakeDamagePost[i] = false;
g_bSDKHook_WeaponEquip[i] = false;
g_bSDKHook_OnTakeDamage[i] = false;
}

DECLARE_FM_FORWARD(OnMapEnd);
}

Expand All @@ -126,8 +123,8 @@ public void OnClientPutInServer(int client)
public void OnClientDisconnect(int client)
{
g_bSDKHook_OnTakeDamagePost[client] = false;
g_bSDKHook_WeaponEquip[client] = false;
g_bSDKHook_OnTakeDamage[client] = false;
g_bSDKHook_WeaponEquip[client] = false;
DECLARE_FM_FORWARD_PARAM(OnClientDisconnect, client);
}

Expand All @@ -148,6 +145,7 @@ void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
{
g_bRoundEnd = true;
g_bMotherZombie = false;
DECLARE_FM_FORWARD(Event_RoundEnd);
}

Expand All @@ -173,20 +171,20 @@ void OnTakeDamagePost(int victim, int attacker, int inflictor, float damage, int
DECLARE_FM_FORWARD_PARAM3(OnTakeDamagePost, victim, attacker, damage);
}

Action OnWeaponEquip(int client, int weapon)
Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
Action result = Plugin_Continue;

DECLARE_FM_FORWARD_PARAM3(OnWeaponEquip, client, weapon, result);
DECLARE_FM_FORWARD_PARAM4(OnTakeDamage, victim, attacker, damage, result);

return result;
}

Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
Action OnWeaponEquip(int client, int weapon)
{
Action result = Plugin_Continue;

DECLARE_FM_FORWARD_PARAM4(OnTakeDamage, victim, attacker, damage, result);
DECLARE_FM_FORWARD_PARAM3(OnWeaponEquip, client, weapon, result);

return result;
}
Expand All @@ -201,6 +199,20 @@ void FunModes_HookEvent(bool &modeBool, const char[] name, EventHook callback)
}
}

void FunModes_RestartRound()
{
// slay all players before terminating the round
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || !IsPlayerAlive(i))
continue;

ForcePlayerSuicide(i);
}

CS_TerminateRound(3.0, CSRoundEnd_Draw);
}

public void OnAllPluginsLoaded()
{
g_bPlugin_DynamicChannels = LibraryExists("DynamicChannels");
Expand Down Expand Up @@ -264,16 +276,6 @@ stock void BeaconPlayer(int client, int mode, float distance = 0.0, int color[4]
}
}

void GiveGrenadesToClient(int client, WeaponAmmoGrenadeType type, int amount)
{
int ammo = FindSendPropInfo("CBasePlayer", "m_iAmmo");
if (ammo != -1)
{
int grenadesCount = GetEntData(client, ammo + (view_as<int>(type) * 4));
SetEntData(client, ammo + (view_as<int>(type) * 4), grenadesCount + amount, _, true);
}
}

Action Cmd_FunModes(int client, int args)
{
if (!client)
Expand Down
12 changes: 7 additions & 5 deletions addons/sourcemod/scripting/Fun_Modes/BlindMode.sp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void ApplyBlind(int client)
int color[4];
color[3] = 255;

int flags = FFADE_OUT;
int flags = FFADE_IN;

int clients[1];
clients[0] = client;
Expand Down Expand Up @@ -273,17 +273,18 @@ Action Timer_BlindMode(Handle timer)
float percentage = THIS_MODE_INFO.cvarInfo[BLINDMODE_CONVAR_PERCENTAGE].cvar.FloatValue;
int neededZombies = RoundToCeil(zombiesCount * (percentage / 100));

int enough = 0;
int enough = 1;
do
{
int zombie = zombies[GetRandomInt(0, zombiesCount - 1)];
if (g_bHasFlash[zombie])
zombie = zombies[GetRandomInt(0, zombiesCount - 1)];

g_bHasFlash[zombie] = true;

int entity = GivePlayerItem(zombie, "weapon_flashbang");
EquipPlayerWeapon(zombie, entity);
SetEntData(zombie, FindSendPropInfo("CBasePlayer", "m_iAmmo") + (view_as<int>(GrenadeType_Flashbang) * 4), 1, _, true);

CPrintToChat(zombie, "%s You have been granted a FlashBang!!!\nBlind some humans.", THIS_MODE_INFO.tag);
enough++;
} while (enough <= neededZombies);
Expand Down Expand Up @@ -315,6 +316,7 @@ Action Timer_ApplyBlind(Handle timer, int ref)
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", origin);

float maxDistance = THIS_MODE_INFO.cvarInfo[BLINDMODE_CONVAR_MAX_DISTANCE].cvar.FloatValue;
maxDistance *= maxDistance;

for (int i = 1; i <= MaxClients; i++)
{
Expand All @@ -324,7 +326,7 @@ Action Timer_ApplyBlind(Handle timer, int ref)
float plOrigin[3];
GetClientAbsOrigin(i, plOrigin);

float distance = GetVectorDistance(origin, plOrigin);
float distance = GetVectorDistance(origin, plOrigin, true);
if (distance > maxDistance)
continue;

Expand Down
146 changes: 125 additions & 21 deletions addons/sourcemod/scripting/Fun_Modes/ChaosWeapons.sp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ ModeInfo g_ChaosWeaponsInfo;

#define CHAOSWEAPONS_CONVAR_TIMER_INTERVAL 0
#define CHAOSWEAPONS_CONVAR_KNOCKBACK 1
#define CHAOSWEAPONS_CONVAR_TOGGLE 2
#define CHAOSWEAPONS_CONVAR_COUNTDOWN 2
#define CHAOSWEAPONS_CONVAR_TOGGLE 3

Handle g_hChaosWeaponsTimer;

char g_sChaosWeaponCurrent[32];

char g_ChaosWeaponsList[][] =
{
"ELITE", "DEAGLE", /* Pistols */
"MAC10", "TMP", "MP5NAVY", "UMP45", "P90", /* SMGs */
"GALIL", "FAMAS", "AK47", "M4A1", "AUG", "SG552", /* Rifles */
"M3", "XM1014" /* Shotguns */
"mac10", "tmp", "mp5navy", "ump45", "p90", /* SMGs */
"galil", "famas", "ak47", "m4a1", "aug", "sg552", /* Rifles */
"m3", "xm1014" /* Shotguns */
};

float g_fOriginalWeaponsKB[sizeof(g_ChaosWeaponsList)];
Expand Down Expand Up @@ -62,6 +64,12 @@ stock void OnPluginStart_ChaosWeapons()
("0.1,0.2,0.5,1.0"), "float"
);

DECLARE_FM_CVAR(
THIS_MODE_INFO.cvarInfo, CHAOSWEAPONS_CONVAR_COUNTDOWN,
"sm_chaosweapons_countdown", "10", "How many seconds for the countdown",
("5,10,15,20"), "int"
);

DECLARE_FM_CVAR(
THIS_MODE_INFO.cvarInfo, CHAOSWEAPONS_CONVAR_TOGGLE,
"sm_chaosweapons_enable", "1", "Enable/Disable ChaosWeapons Mode (This differs from turning it on/off)",
Expand Down Expand Up @@ -203,18 +211,55 @@ Action Timer_ChaosWeapons(Handle timer)
return Plugin_Handled;
}

PickRandomWeapon();
CreateTimer(1.0, Timer_ChaosWeaponsRepeat, _, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT);
return Plugin_Continue;
}

Action Timer_ChaosWeaponsRepeat(Handle timer)
{
static int counter;
if (!THIS_MODE_INFO.isOn || g_bRoundEnd || !g_bMotherZombie)
{
counter = 0;
return Plugin_Stop;
}

int max = THIS_MODE_INFO.cvarInfo[CHAOSWEAPONS_CONVAR_COUNTDOWN].cvar.IntValue;

if (++counter >= max)
{
counter = 0;
PickRandomWeapon();
return Plugin_Stop;
}

char msg[128];
FormatEx
(
msg, sizeof(msg), "[ChaosWeapons] The weapon that pushes zombies will change in %d seconds!",
max - counter
);

for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i))
continue;

SendHudText(i, msg, _, 1);
}

return Plugin_Continue;
}

void PickRandomWeapon()
{
int index = GetRandomInt(0, sizeof(g_ChaosWeaponsList) - 1);

FormatEx(g_sChaosWeaponCurrent, sizeof(g_sChaosWeaponCurrent), "weapon_%s", g_ChaosWeaponsList[index]);
SetAllWeaponsKnockback(THIS_MODE_INFO.cvarInfo[CHAOSWEAPONS_CONVAR_KNOCKBACK].cvar.FloatValue, index);

char msg[255];
FormatEx(msg, sizeof(msg), "Only the [%s] will push the zombies for the next %d seconds!", g_ChaosWeaponsList[index], THIS_MODE_INFO.cvarInfo[CHAOSWEAPONS_CONVAR_TIMER_INTERVAL].cvar.IntValue);
FormatEx(msg, sizeof(msg), "Only the [%s] will push the zombies for the next %d seconds\nPress F to buy it!", StrToUpper(g_ChaosWeaponsList[index]), THIS_MODE_INFO.cvarInfo[CHAOSWEAPONS_CONVAR_TIMER_INTERVAL].cvar.IntValue);

for (int i = 1; i <= MaxClients; i++)
{
Expand All @@ -226,31 +271,90 @@ void PickRandomWeapon()
}
}

stock char[] StrToUpper(const char[] buffer)
{
int len = strlen(buffer);
char myChar[32];

for (int i = 0; i < len; i++)
{
char c = buffer[i];
if (c >= 'a' && c <= 'z')
c &= ~0x20;

myChar[i] = c;
}

return myChar;
}

void SetAllWeaponsKnockback(float kb = 0.0, int index = -1, bool firstTime = false, bool turnOff = false)
{
for (int i = 0; i < sizeof(g_ChaosWeaponsList); i++)
{
int len = strlen(g_ChaosWeaponsList[i]);
char[] lower = new char[len + 1];
if (turnOff || (index >= 0 && i == index))
{
ZR_SetWeaponKnockback(g_ChaosWeaponsList[i], g_fOriginalWeaponsKB[i]);
continue;
}

if (firstTime)
g_fOriginalWeaponsKB[i] = ZR_GetWeaponKnockback(g_ChaosWeaponsList[i]);

ZR_SetWeaponKnockback(g_ChaosWeaponsList[i], kb);
}
}

stock void OnPlayerRunCmdPost_ChaosWeapons(int client, int buttons, int impulse)
{
#pragma unused buttons

if (!THIS_MODE_INFO.isOn)
return;

if (!IsPlayerAlive(client) || !ZR_IsClientHuman(client))
return;

static float playersTime[MAXPLAYERS + 1];

float currentTime = GetGameTime();
if (currentTime <= playersTime[client])
return;

// https://github.com/ValveSoftware/source-sdk-2013/blob/7191ecc418e28974de8be3a863eebb16b974a7ef/src/game/server/player.cpp#L6073
if (impulse == 100)
{
playersTime[client] = currentTime + 2.0;

char curWeapon[sizeof(g_sChaosWeaponCurrent)];
strcopy(curWeapon, sizeof(curWeapon), g_sChaosWeaponCurrent);

for (int j = 0; j < len; j++)
int weapon = 0;

ReplaceString(curWeapon, sizeof(curWeapon), "weapon_", "");
int price = ZR_GetWeaponZMarketPrice(curWeapon);

int cash = GetEntProp(client, Prop_Send, "m_iAccount");
if (cash < price)
{
char c = g_ChaosWeaponsList[i][j];
if (c >= 'A' && c <= 'Z')
c |= 0x20;

lower[j] = c;
CPrintToChat(client, "%s Insufficent fund", THIS_MODE_INFO.tag);
return;
}

if (turnOff || (index >= 0 && i == index))
weapon = GetPlayerWeaponSlot(client, CS_SLOT_PRIMARY);
if (IsValidEntity(weapon))
{
ZR_SetWeaponKnockback(lower, g_fOriginalWeaponsKB[i]);
continue;
SDKHooks_DropWeapon(client, weapon);
RemoveEntity(weapon);
}

if (firstTime)
g_fOriginalWeaponsKB[i] = ZR_GetWeaponKnockback(lower);
weapon = GivePlayerItem(client, g_sChaosWeaponCurrent);
if (!IsValidEntity(weapon))
return;

if (g_hSwitchSDKCall != null)
SDKCall(g_hSwitchSDKCall, client, weapon, 0);

ZR_SetWeaponKnockback(lower, kb);
SetEntProp(client, Prop_Send, "m_iAccount", cash - price);
}
}
Loading