/
odins_rock.sp
218 lines (173 loc) · 6.01 KB
/
odins_rock.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
* @Author: 我是派蒙啊
* @Last Modified by: 我是派蒙啊
* @Create Date: 2023-03-18 14:59:54
* @Last Modified time: 2024-02-17 11:11:47
* @Github: https://github.com/Paimon-Kawaii
*/
#pragma semicolon 1
#pragma newdecls required
#include <sdktools>
#include <paiutils>
#include <sourcemod>
#include <left4dhooks>
#define VERSION "2024.02.01"
#define DEBUG 0
#define MAX_CLASSNAME_LENGTH 10
ConVar
g_hOdinsRock,
g_hOdinsTrick,
g_hOdinsTime,
g_hOdinsHuman,
g_hOdinsPunch,
g_hOdinsPunchH,
g_hOdinsTeleport;
bool g_bFinalMapStop,
g_bIsRockTime[MAXPLAYERS + 1] = { true, ... };
public Plugin myinfo =
{
name = "Odin's Rock",
author = "我是派蒙啊",
description = "因果律石头ww",
version = VERSION,
url = "http://github.com/Paimon-Kawaii/L4D2-Plugins/MyPlugins"
};
public void OnPluginStart()
{
g_hOdinsRock = CreateConVar("odins_rock", "1", "开关因果律武器ww", _, true, 0.0, true, 1.0);
g_hOdinsTeleport = CreateConVar("odins_tp", "0", "克在丢石后是否会传送到玩家", _, true, 0.0, true, 1.0);
g_hOdinsHuman = CreateConVar("odins_rock_human", "0", "玩家Tank是否可以使用", _, true, 0.0, true, 1.0);
g_hOdinsTime = CreateConVar("odins_time", "5", "AI克自动丢石时间", _, true, 0.0);
g_hOdinsTrick = CreateConVar("odins_trick", "5", "奥丁之饼伤害", _, true, 0.0);
g_hOdinsPunch = CreateConVar("odins_rock_punch", "600", "石头的冲击力");
g_hOdinsPunchH = CreateConVar("odins_rock_punch_h", "260", "石头的垂直击飞力度");
AutoExecConfig(_, "odins_rock");
}
public void OnMapStart()
{
g_bFinalMapStop = IsMissionFinal();
for (int i = 0; i <= MaxClients; i++)
g_bIsRockTime[i] = true;
}
public Action OnPlayerRunCmd(int client, int &buttons, int &impuls)
{
if (!IsTank(client) || !g_hOdinsRock.BoolValue || !IsFakeClient(client) || g_bFinalMapStop) return Plugin_Continue;
if (g_bIsRockTime[client] && g_hOdinsTime.IntValue /*&& !IsEntitySawThreats(client)*/)
{
g_bIsRockTime[client] = false;
buttons |= IN_ATTACK2;
CreateTimer(g_hOdinsTime.FloatValue, Timer_ResetRockTime, client, TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Changed;
}
return Plugin_Continue;
}
/* --------------------------------------
* GOD BLESS YOU...
* -------------------------------------- */
public Action L4D_TankRock_OnRelease(int tank, int rock, float vecPos[3], float vecAng[3], float vecVel[3], float vecRot[3])
{
if (!g_hOdinsRock.BoolValue || !IsTank(tank) || g_bFinalMapStop)
return Plugin_Continue;
#if DEBUG
PrintToChatAll("%N 释放了石头", tank);
#endif
if (!(IsFakeClient(tank) || g_hOdinsHuman.BoolValue))
return Plugin_Continue;
int target = GetClientAimTarget(tank);
float pos[3];
if (!IsSurvivor(target))
{
GetClientEyePosition(tank, pos);
target = GetNearestSurvivor(pos);
}
if (!IsSurvivor(target))
target = GetNearestSurvivor(vecPos);
#if DEBUG
PrintToChatAll("%N 被石头锁定", target);
#endif
if (!IsSurvivor(target))
return Plugin_Continue;
SDKHook(target, SDKHook_OnTakeDamage, OnTakeDamage);
PrintHintText(target, "奥丁之饼降临ww");
for (int i = 1; i <= MaxClients; i++)
if (IsValidClient(i) && i != target)
PrintHintText(i, "奥丁:%N 饿了,请你吃饼ww", target);
GetClientEyePosition(target, pos);
for (int i = 0; i < 3; i++)
vecPos[i] = pos[i];
vecPos[2] += 10;
pos[0] += 20;
pos[2] += 100;
if (g_hOdinsTeleport.BoolValue)
TeleportEntity(tank, pos, NULL_VECTOR, NULL_VECTOR);
return Plugin_Changed;
}
Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &weapon, float damageForce[3], float damagePosition[3])
{
SDKUnhook(victim, SDKHook_OnTakeDamage, OnTakeDamage);
if (!(IsTankRock(inflictor) && IsSurvivor(victim)))
return Plugin_Continue;
damage = g_hOdinsTrick.FloatValue;
float velocity[3], pos1[3], pos2[3];
GetClientAbsOrigin(attacker, pos1);
GetClientAbsOrigin(victim, pos2);
MakeVectorFromPoints(pos1, pos2, velocity);
NormalizeVector(velocity, velocity);
ScaleVector(velocity, g_hOdinsPunch.FloatValue);
velocity[2] = (velocity[2] > 0 ? velocity[2] : 0.0) + g_hOdinsPunchH.FloatValue;
DataPack data = new DataPack();
data.WriteCell(victim);
data.WriteFloatArray(velocity, 3);
CreateTimer(0.01, Timer_RockImpact, data, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Changed;
}
Action Timer_RockImpact(Handle timer, DataPack data)
{
data.Reset();
int victim = data.ReadCell();
if (!(IsSurvivor(victim) && IsPlayerAlive(victim)))
{
delete data;
return Plugin_Stop;
}
float velocity[3], curvel[3];
data.ReadFloatArray(velocity, 3);
GetEntPropVector(victim, Prop_Data, "m_vecAbsVelocity", curvel);
if (curvel[0] != 0 || curvel[1] != 0)
{
delete data;
return Plugin_Stop;
}
TeleportEntity(victim, NULL_VECTOR, NULL_VECTOR, velocity);
return Plugin_Continue;
}
Action Timer_ResetRockTime(Handle timer, int client)
{
g_bIsRockTime[client] = true;
return Plugin_Stop;
}
int GetNearestSurvivor(const float pos[3])
{
int target;
float dis = -1.0, surPos[3];
for (int i = 1; i <= MaxClients; i++)
if (IsSurvivor(i) && IsPlayerAlive(i) && !IsPlayerIncap(i))
{
GetClientAbsOrigin(i, surPos);
float tmp = GetVectorDistance(pos, surPos, true);
if (dis > tmp || dis == -1)
{
dis = tmp;
target = i;
}
}
return target;
}
bool IsTankRock(int entity)
{
if (entity <= MaxClients || !IsValidEdict(entity))
return false;
static char classname[MAX_CLASSNAME_LENGTH];
GetEdictClassname(entity, classname, sizeof(classname));
return (strcmp(classname, "tank_rock") == 0);
}