Skip to content

Commit

Permalink
feat: drug survivor (#36)
Browse files Browse the repository at this point in the history
* feat: drug file

* fix: reset timer

* fix: check valid before drug all

* fix: put null rather than delete

* chore: update ignore

* feat: drug.sp

* feat: add drug feature

* feat: add translation

* chore: doc

* feat: drug all survivor

* feat: translation

* chore: version

* feat: render color in drug state
  • Loading branch information
rick-yao authored Dec 26, 2024
1 parent 49105df commit b952d10
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 4 deletions.
2 changes: 2 additions & 0 deletions l4d2_tank_draw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ The plugin includes the following possible prizes:
21. Turn the lucky player into a "timer bomb" (Repeated draws will cancel the timer)
22. Turn the lucky player into a "freeze bomb" (Repeated draws will cancel the timer)
23. Remove survivor outlines (Removes survivor glow outlines, but names above players remain visible; not recommended as many plugins modify outlines)
24. Temporarily Drug lucky player
24. Temporarily Drug all survivors

## Configuration

Expand Down
2 changes: 2 additions & 0 deletions l4d2_tank_draw/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
21. 将幸运玩家变成“定时炸弹”(重复抽取会取消计时)
22. 将幸运玩家变成“冰冻炸弹”(重复抽取会取消计时)
23. 取消人物光圈概率(取消人物轮廓光圈,人物头上的名字依然保留,不建议使用,很多插件会修改光圈)
24. 限时使幸运玩家中毒
25. 限时使所有幸存者中毒

## 配置

Expand Down
11 changes: 10 additions & 1 deletion 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.10.0 - 2024-12-26
* - add drug survivor
*
* v2.9.0 - 2024-12-15
* - change doc
*
Expand Down Expand Up @@ -49,8 +52,9 @@
#include "lib/freeze_timer_bomb.sp"
#include "lib/dev_menu.sp"
#include "lib/lucky_draw.sp"
#include "lib/drug.sp"

#define PLUGIN_VERSION "2.9.0"
#define PLUGIN_VERSION "2.10.0"
#define PLUGIN_FLAG FCVAR_SPONLY | FCVAR_NOTIFY
#define COMMAND_FILTER COMMAND_FILTER_CONNECTED | COMMAND_FILTER_NO_BOTS

Expand Down Expand Up @@ -133,6 +137,11 @@ public void OnPluginStart()
FreezeBombCountDown = CreateConVar("l4d2_tank_draw_freeze_bomb_countdown", "8", "冰冻炸弹倒计时秒数 \nCountdown duration in seconds before the freeze bomb explodes", FCVAR_NONE);
FreezeBombRadius = CreateConVar("l4d2_tank_draw_freeze_bomb_radius", "500.0", "冰冻炸弹范围 \nRadius of the freeze bomb effect", FCVAR_NONE);

DrugAllSurvivorChance = CreateConVar("l4d2_tank_draw_drug_all_survivor_chance", "0", "所有玩家中毒概率 \nProbability of drug luck drawer.", FCVAR_NONE);
DrugAllSurvivorDuration = CreateConVar("l4d2_tank_draw_drug_all_survivor_duration", "30", "所有玩家中毒秒数 \nDuration of drug luck drawer.", FCVAR_NONE);
DrugLuckySurvivorChance = CreateConVar("l4d2_tank_draw_drug_lucky_survivor_chance", "0", "幸运玩家中毒概率 \nProbability of drug luck drawer.", FCVAR_NONE);
DrugLuckySurvivorDuration = CreateConVar("l4d2_tank_draw_drug_lucky_survivor_duration", "30", "幸运玩家中毒秒数 \nDuration of drug luck drawer.", FCVAR_NONE);

AutoExecConfig(true, "l4d2_tank_draw");

PrintToServer("[Tank Draw] Plugin loaded");
Expand Down
103 changes: 103 additions & 0 deletions l4d2_tank_draw/scripting/lib/drug.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@

// Exposed function to set a player in a drugged state for a specific duration
stock void SetDrug(int client, int ticks = 30)
{
if (!IsValidAliveClient(client))
{
PrintToServer("[Tank Draw] IsValidAliveClient false.");
return;
}

// If the client is already drugged, unset the drug immediately and return
if (g_hDrugTimers[client] != null)
{
delete g_hDrugTimers[client];
g_iDrugTicks[client] = 0;
ClearDrugState(client);
return;
}

// Start the drug effect immediately
g_iDrugTicks[client] = ticks;
g_hDrugTimers[client] = CreateTimer(1.0, Timer_Drug, client, REPEAT_TIMER);
}

Action Timer_Drug(Handle timer, int client)
{
if (!IsValidAliveClient(client))
{
delete g_hDrugTimers[client];
g_iDrugTicks[client] = 0;
return Plugin_Stop;
}

g_iDrugTicks[client]--;
if (g_iDrugTicks[client] > 0)
{
float angs[3];
GetClientEyeAngles(client, angs);

angs[2] = g_fDrugAngles[GetRandomInt(0, 100) % 20];

TeleportEntity(client, NULL_VECTOR, angs, NULL_VECTOR);

int clients[2];
clients[0] = client;

int duration = 255;
int holdtime = 255;
int flags = 0x0002;
int color[4] = { 0, 0, 0, 128 };
color[0] = GetRandomInt(0, 255);
color[1] = GetRandomInt(0, 255);
color[2] = GetRandomInt(0, 255);
SetEntityRenderColor(client, color[0], color[1], color[2], color[3]);

Handle message = StartMessageEx(GetUserMessageId("Fade"), clients, 1);
BfWriteShort(message, duration);
BfWriteShort(message, holdtime);
BfWriteShort(message, flags);
BfWriteByte(message, color[0]);
BfWriteByte(message, color[1]);
BfWriteByte(message, color[2]);
BfWriteByte(message, color[3]);
EndMessage();
}
if (g_iDrugTicks[client] == 0)
{
ClearDrugState(client);
g_hDrugTimers[client] = null;
return Plugin_Stop;
}

return Plugin_Continue;
}

void ClearDrugState(int client)
{
float angs[3];
GetClientEyeAngles(client, angs);

angs[2] = 0.0;

TeleportEntity(client, NULL_VECTOR, angs, NULL_VECTOR);

int clients[2];
clients[0] = client;

int duration = 1536;
int holdtime = 1536;
int flags = (0x0001 | 0x0010);
int color[4] = { 0, 0, 0, 0 };
SetEntityRenderColor(client, 255, 255, 255, 255);

Handle message = StartMessageEx(GetUserMessageId("Fade"), clients, 1);
BfWriteShort(message, duration);
BfWriteShort(message, holdtime);
BfWriteShort(message, flags);
BfWriteByte(message, color[0]);
BfWriteByte(message, color[1]);
BfWriteByte(message, color[2]);
BfWriteByte(message, color[3]);
EndMessage();
}
16 changes: 14 additions & 2 deletions l4d2_tank_draw/scripting/lib/lib.sp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,21 @@ ConVar

ChanceResetAllSurvivorHealth,

ChanceInfinitePrimaryAmmo;
ChanceInfinitePrimaryAmmo,

DrugAllSurvivorChance,
DrugAllSurvivorDuration,
DrugLuckySurvivorChance,
DrugLuckySurvivorDuration;

Handle g_SingleGravityTimer[MAXPLAYERS + 1] = { INVALID_HANDLE, ... };
Handle g_WorldGravityTimer = INVALID_HANDLE;

int g_GlowDisabled = 0;
Handle g_hDrugTimers[MAXPLAYERS + 1];
int g_iDrugTicks[MAXPLAYERS + 1];
float g_fDrugAngles[20] = { 0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 20.0, 15.0, 10.0, 5.0, 0.0, -5.0, -10.0, -15.0, -20.0, -25.0, -20.0, -15.0, -10.0, -5.0 };

int g_GlowDisabled = 0;

#define REPEAT_TIMER TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE
#define NO_REPEAT_TIMER TIMER_FLAG_NO_MAPCHANGE
Expand Down Expand Up @@ -161,6 +170,9 @@ stock void KillAllSingleGravityTimer()

stock void ResetClient(int client)
{
delete g_hDrugTimers[client];
g_iDrugTicks[client] = 0;

KillSingleGravityTimer(client);

KillTimeBomb(client);
Expand Down
37 changes: 36 additions & 1 deletion l4d2_tank_draw/scripting/lib/lucky_draw.sp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ stock Action LuckyDraw(int victim, int attacker)
int chanceIncreaseGravity = ChanceIncreaseGravity.IntValue;
int chanceClearAllSurvivorHealth = ChanceClearAllSurvivorHealth.IntValue;
int chanceReviveAllDead = ChanceReviveAllDead.IntValue;
int chanceDrugLuckySurvivor = DrugLuckySurvivorChance.IntValue;
int chanceDrugAllSurvivor = DrugAllSurvivorChance.IntValue;

int totalChance = chanceNoPrize + chanceResetAllSurvivorHealth + chanceInfinitePrimaryAmmo + chanceNewWitch + chanceFreezeBomb + chanceTimerBomb + chanceReviveAllDead + chanceNewTank + chanceDisarmSingleSurvivor + chanceDisarmAllSurvivor + chanceDecreaseHealth + chanceClearAllSurvivorHealth + chanceIncreaseHealth + chanceInfiniteAmmo + chanceInfiniteMelee + chanceAverageHealth + chanceKillAllSurvivor + chanceKillSingleSurvivor + chanceDisableGlow;
int totalChance = chanceNoPrize + chanceDrugAllSurvivor + chanceDrugLuckySurvivor + 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 @@ -53,6 +55,39 @@ stock Action LuckyDraw(int victim, int attacker)
return Plugin_Continue;
}

currentChance += chanceDrugAllSurvivor;
if (random <= currentChance)
{
for (int i = 1; i <= MaxClients; i++)
{
if (IsValidAliveClient(i))
{
SetDrug(i, DrugAllSurvivorDuration.IntValue);
}
}

CPrintToChatAll("%t", "TankDrawResult_DrugAll", attackerName, DrugAllSurvivorDuration.IntValue);
PrintHintTextToAll("%t", "TankDrawResult_DrugAll_NoColor", attackerName, DrugAllSurvivorDuration.IntValue);
return Plugin_Continue;
}

currentChance += chanceDrugLuckySurvivor;
if (random <= currentChance)
{
if (g_hDrugTimers[attacker] != null)
{
SetDrug(attacker, DrugLuckySurvivorDuration.IntValue);
CPrintToChatAll("%t", "TankDrawResult_DrugExist", attackerName);
PrintHintTextToAll("%t", "TankDrawResult_DrugExist_NoColor", attackerName);
}
else {
SetDrug(attacker, DrugLuckySurvivorDuration.IntValue);
CPrintToChatAll("%t", "TankDrawResult_DrugLuckySurvivor", attackerName, DrugLuckySurvivorDuration.IntValue);
PrintHintTextToAll("%t", "TankDrawResult_DrugLuckySurvivor_NoColor", attackerName, DrugLuckySurvivorDuration.IntValue);
}
return Plugin_Continue;
}

currentChance += chanceInfinitePrimaryAmmo;
if (random <= currentChance)
{
Expand Down
36 changes: 36 additions & 0 deletions l4d2_tank_draw/translations/l4d2_tank_draw.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -635,4 +635,40 @@
"en" "[Tank Draw] Player %s's lucky draw result: Disable Infinite primary ammo."
"chi" "[坦克抽奖] 玩家 %s 的幸运抽奖结果: 关闭主武器无限子弹"
}

"TankDrawResult_DrugExist"
{
"en" "{yellow}[Tank Draw] {lightgreen}Player {olive}%s{lightgreen}'s lucky draw result: {olive}Clear drug state."
"chi" "{yellow}[坦克抽奖] {lightgreen}玩家 {olive}%s{lightgreen} 的幸运抽奖结果:{olive}取消中毒"
}

"TankDrawResult_DrugExist_NoColor"
{
"en" "[Tank Draw] Player %s's lucky draw result: Clear drug state."
"chi" "[坦克抽奖] 玩家 %s 的幸运抽奖结果: 取消中毒"
}

"TankDrawResult_DrugLuckySurvivor"
{
"en" "{yellow}[Tank Draw] {lightgreen}Player {olive}%s{lightgreen}'s lucky draw result: {olive}Drug for %d seconds."
"chi" "{yellow}[坦克抽奖] {lightgreen}玩家 {olive}%s{lightgreen} 的幸运抽奖结果:{olive}中毒 %d 秒"
}

"TankDrawResult_DrugLuckySurvivor_NoColor"
{
"en" "[Tank Draw] Player %s's lucky draw result: Drug for %d seconds."
"chi" "[坦克抽奖] 玩家 %s 的幸运抽奖结果: 中毒 %d 秒"
}

"TankDrawResult_DrugAll"
{
"en" "{yellow}[Tank Draw] {lightgreen}Player {olive}%s{lightgreen}'s lucky draw result: {olive}Drug all survivor for %d seconds."
"chi" "{yellow}[坦克抽奖] {lightgreen}玩家 {olive}%s{lightgreen} 的幸运抽奖结果:{olive}全体中毒 %d 秒"
}

"TankDrawResult_DrugAll_NoColor"
{
"en" "[Tank Draw] Player %s's lucky draw result: Drug all survivor for %d seconds."
"chi" "[坦克抽奖] 玩家 %s 的幸运抽奖结果: 全体中毒 %d 秒"
}
}

0 comments on commit b952d10

Please sign in to comment.