Skip to content

Commit

Permalink
feat: add infinite primary ammo (#33)
Browse files Browse the repository at this point in the history
* feat: add primary infinite ammo

* chore: version
  • Loading branch information
rick-yao authored Dec 12, 2024
1 parent be76f9d commit 715a19b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 10 deletions.
11 changes: 8 additions & 3 deletions l4d2_tank_draw/scripting/l4d2_tank_draw.sp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* @repository https://github.com/rick-yao/L4d2-plugin
*
* Changelog
* v2.8.0 - 2024-12-12
* - add infinite primary ammo
*
* v2.7.0 - 2024-12-12
* - add reset all survivor health
*
Expand Down Expand Up @@ -44,7 +47,7 @@
#include "lib/dev_menu.sp"
#include "lib/lucky_draw.sp"

#define PLUGIN_VERSION "2.7.0"
#define PLUGIN_VERSION "2.8.0"
#define PLUGIN_FLAG FCVAR_SPONLY | FCVAR_NOTIFY
#define COMMAND_FILTER COMMAND_FILTER_CONNECTED | COMMAND_FILTER_NO_BOTS

Expand Down Expand Up @@ -98,6 +101,8 @@ public void OnPluginStart()
ChanceDisarmSurvivorMolotov = CreateConVar("l4d2_tank_draw_infinite_ammo_disarm_survivor_molotov_chance", "30", "无限弹药时,玩家乱扔火时缴械概率(百分比,0为关闭) / Probability of disarming a survivor when throwing molotovs recklessly with infinite ammo (percentage, 0 to disable)", FCVAR_NONE);
ChanceTimerBombMolotov = CreateConVar("l4d2_tank_draw_infinite_ammo_timer_bomb_molotov_chance", "30", "无限弹药时,玩家乱扔火时变成定时炸弹概率(百分比,0为关闭) / Probability of becoming a timer bomb when throwing molotovs recklessly with infinite ammo (percentage, 0 to disable)", FCVAR_NONE);

ChanceInfinitePrimaryAmmo = CreateConVar("l4d2_tank_draw_infinite_primary_ammo_chance", "10", "主武器无限弹药的概率 / Probability of infinite primary ammo", FCVAR_NONE);

ChanceInfiniteMelee = CreateConVar("l4d2_tank_draw_infinite_melee_chance", "5", "无限近战范围的概率 / Probability of infinite melee range", FCVAR_NONE);
InfiniteMeeleRange = CreateConVar("l4d2_tank_draw_infinite_melee_range", "700", "无限近战范围,游戏默认为70,重复抽取会自动恢复默认值 / Infinite melee range, game default is 70, repeated draws will restore default value", false, false);

Expand Down Expand Up @@ -245,8 +250,8 @@ public Action Event_Molotov(Event event, const char[] name, bool dontBroadcast)
{
PrintToServer("[Tank Draw] Event_Molotov triggered.");

g_hInfinitePrimaryAmmo = FindConVar("sv_infinite_ammo");
if (g_hInfinitePrimaryAmmo.IntValue == 1)
g_hInfiniteAmmo = FindConVar("sv_infinite_ammo");
if (g_hInfiniteAmmo.IntValue == 1)
{
int random = GetRandomInt(1, 100);
int chanceDisarmSurvivorMolotov = ChanceDisarmSurvivorMolotov.IntValue;
Expand Down
10 changes: 8 additions & 2 deletions l4d2_tank_draw/scripting/lib/lib.sp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// built-in convar
ConVar
g_hInfiniteAmmo,
g_hInfinitePrimaryAmmo,
g_MeleeRange,
g_WorldGravity;
Expand Down Expand Up @@ -53,7 +54,9 @@ ConVar
FreezeBombCountDown,
FreezeBombRadius,

ChanceResetAllSurvivorHealth;
ChanceResetAllSurvivorHealth,

ChanceInfinitePrimaryAmmo;

Handle g_SingleGravityTimer[MAXPLAYERS + 1] = { INVALID_HANDLE, ... };
Handle g_WorldGravityTimer = INVALID_HANDLE;
Expand Down Expand Up @@ -82,7 +85,10 @@ stock void ResetAllTimer()
stock void ResetAllValue()
{
// reset all changed server value
g_hInfinitePrimaryAmmo = FindConVar("sv_infinite_ammo");
g_hInfiniteAmmo = FindConVar("sv_infinite_ammo");
g_hInfiniteAmmo.RestoreDefault();

g_hInfinitePrimaryAmmo = FindConVar("sv_infinite_primary_ammo");
g_hInfinitePrimaryAmmo.RestoreDefault();

g_MeleeRange = FindConVar("melee_range");
Expand Down
40 changes: 35 additions & 5 deletions l4d2_tank_draw/scripting/lib/lucky_draw.sp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ stock Action LuckyDraw(int victim, int attacker)
int chanceDisableGlow = ChanceDisableGlow.IntValue;
int chanceFreezeBomb = ChanceFreezeBomb.IntValue;
int chanceResetAllSurvivorHealth = ChanceResetAllSurvivorHealth.IntValue;
int chanceInfinitePrimaryAmmo = ChanceInfinitePrimaryAmmo.IntValue;

int chanceLimitedTimeWorldMoonGravity = ChanceLimitedTimeWorldMoonGravity.IntValue;
int chanceMoonGravityOneLimitedTime = ChanceMoonGravityOneLimitedTime.IntValue;
Expand All @@ -24,7 +25,7 @@ stock Action LuckyDraw(int victim, int attacker)
int chanceClearAllSurvivorHealth = ChanceClearAllSurvivorHealth.IntValue;
int chanceReviveAllDead = ChanceReviveAllDead.IntValue;

int totalChance = chanceNoPrice + chanceResetAllSurvivorHealth + chanceNewWitch + chanceFreezeBomb + chanceTimerBomb + chanceReviveAllDead + chanceNewTank + chanceDisarmSingleSurvivor + chanceDisarmAllSurvivor + chanceDecreaseHealth + chanceClearAllSurvivorHealth + chanceIncreaseHealth + chanceInfiniteAmmo + chanceInfiniteMelee + chanceAverageHealth + chanceKillAllSurvivor + chanceKillSingleSurvivor + chanceDisableGlow;
int totalChance = chanceNoPrice + chanceResetAllSurvivorHealth + chanceInfinitePrimaryAmmo + chanceNewWitch + chanceFreezeBomb + chanceTimerBomb + chanceReviveAllDead + chanceNewTank + chanceDisarmSingleSurvivor + chanceDisarmAllSurvivor + chanceDecreaseHealth + chanceClearAllSurvivorHealth + chanceIncreaseHealth + chanceInfiniteAmmo + chanceInfiniteMelee + chanceAverageHealth + chanceKillAllSurvivor + chanceKillSingleSurvivor + chanceDisableGlow;
totalChance += chanceLimitedTimeWorldMoonGravity + chanceMoonGravityOneLimitedTime + chanceWorldMoonGravityToggle + chanceIncreaseGravity;

if (totalChance == 0)
Expand Down Expand Up @@ -52,6 +53,30 @@ stock Action LuckyDraw(int victim, int attacker)
return Plugin_Continue;
}

currentChance += chanceInfinitePrimaryAmmo;
if (random <= currentChance)
{
// Infinite ammo
g_hInfiniteAmmo = FindConVar("sv_infinite_ammo");
g_hInfinitePrimaryAmmo = FindConVar("sv_infinite_primary_ammo");
if (g_hInfiniteAmmo.IntValue == 1)
{
g_hInfiniteAmmo.RestoreDefault();
}
if (g_hInfinitePrimaryAmmo.IntValue == 0)
{
g_hInfinitePrimaryAmmo.IntValue = 1;
CPrintToChatAll("%t", "TankDrawResult_EnableInfinitePrimaryAmmo", attackerName);
PrintHintTextToAll("%t", "TankDrawResult_EnableInfinitePrimaryAmmo_NoColor", attackerName);
}
else {
g_hInfinitePrimaryAmmo.RestoreDefault();
CPrintToChatAll("%t", "TankDrawResult_DisableInfinitePrimaryAmmo", attackerName);
PrintHintTextToAll("%t", "TankDrawResult_DisableInfinitePrimaryAmmo_NoColor", attackerName);
}
return Plugin_Continue;
}

currentChance += chanceResetAllSurvivorHealth;
if (random <= currentChance)
{
Expand Down Expand Up @@ -321,15 +346,20 @@ stock Action LuckyDraw(int victim, int attacker)
if (random <= currentChance)
{
// Infinite ammo
g_hInfinitePrimaryAmmo = FindConVar("sv_infinite_ammo");
if (g_hInfinitePrimaryAmmo.IntValue == 0)
g_hInfiniteAmmo = FindConVar("sv_infinite_ammo");
g_hInfinitePrimaryAmmo = FindConVar("sv_infinite_primary_ammo");
if (g_hInfinitePrimaryAmmo.IntValue == 1)
{
g_hInfinitePrimaryAmmo.IntValue = 1;
g_hInfinitePrimaryAmmo.RestoreDefault();
}
if (g_hInfiniteAmmo.IntValue == 0)
{
g_hInfiniteAmmo.IntValue = 1;
CPrintToChatAll("%t", "TankDrawResult_EnableInfiniteAmmo", attackerName);
PrintHintTextToAll("%t", "TankDrawResult_EnableInfiniteAmmo_NoColor", attackerName);
}
else {
g_hInfinitePrimaryAmmo.RestoreDefault();
g_hInfiniteAmmo.RestoreDefault();
CPrintToChatAll("%t", "TankDrawResult_DisableInfiniteAmmo", attackerName);
PrintHintTextToAll("%t", "TankDrawResult_DisableInfiniteAmmo_NoColor", attackerName);
}
Expand Down
24 changes: 24 additions & 0 deletions l4d2_tank_draw/translations/l4d2_tank_draw.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -611,4 +611,28 @@
"en" "[Tank Draw] Player %s's lucky draw result: Reset all survivors' health."
"chi" "[坦克抽奖] 玩家 %s 的幸运抽奖结果: 重置所有幸存者生命值"
}

"TankDrawResult_EnableInfinitePrimaryAmmo"
{
"en" "{yellow}[Tank Draw] {lightgreen}Player {olive}%s{lightgreen}'s lucky draw result: {olive}Everyone has infinite primary ammo."
"chi" "{yellow}[坦克抽奖] {lightgreen}玩家 {olive}%s{lightgreen} 的幸运抽奖结果:{olive}开启主武器无限子弹"
}

"TankDrawResult_EnableInfinitePrimaryAmmo_NoColor"
{
"en" "[Tank Draw] Player %s's lucky draw result: Everyone has infinite primary ammo."
"chi" "[坦克抽奖] 玩家 %s 的幸运抽奖结果: 开启主武器无限子弹"
}

"TankDrawResult_DisableInfinitePrimaryAmmo"
{
"en" "{yellow}[Tank Draw] {lightgreen}Player {olive}%s{lightgreen}'s lucky draw result: {olive}Disable Infinite primary ammo."
"chi" "{yellow}[坦克抽奖] {lightgreen}玩家 {olive}%s{lightgreen} 的幸运抽奖结果:{olive}关闭主武器无限子弹"
}

"TankDrawResult_DisableInfinitePrimaryAmmo_NoColor"
{
"en" "[Tank Draw] Player %s's lucky draw result: Disable Infinite primary ammo."
"chi" "[坦克抽奖] 玩家 %s 的幸运抽奖结果: 关闭主武器无限子弹"
}
}

0 comments on commit 715a19b

Please sign in to comment.