-
Notifications
You must be signed in to change notification settings - Fork 0
/
rrm_charge.sp
120 lines (98 loc) · 3.08 KB
/
rrm_charge.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
// Copyright (C) 2024 Katsute | Licensed under CC BY-NC-SA 4.0
#pragma semicolon 1
#define RRM_VERSION "1.0"
#include <sourcemod>
#include <sdkhooks>
#include <tf2attributes>
#include <tf2>
#include <tf2_stocks>
#include <rrm>
#pragma newdecls required
int gEnabled = 0;
float gChance = 0.0;
ConVar cMin = null, cMax = null, cDuration = null;
float gMin = 0.0, gMax = 0.0, gDuration = 0.0;
public Plugin myinfo =
{
name = "[RRM] Charged Modifier",
author = "Katsute",
description = "Modifier that grants chance of demoman charge.",
version = "1.0"
};
public void OnPluginStart()
{
cMin = CreateConVar("rrm_charge_min", "0.1", "Minimum value for the random number generator.");
cMax = CreateConVar("rrm_charge_max", "1.0", "Maximum value for the random number generator.");
cDuration = CreateConVar("rrm_charge_duration", "3.0", "Duration for charge to last on affected players.");
cMin.AddChangeHook(OnConvarChanged);
cMax.AddChangeHook(OnConvarChanged);
cDuration.AddChangeHook(OnConvarChanged);
gMin = cMin.FloatValue;
gMax = cMax.FloatValue;
gDuration = cDuration.FloatValue;
for (int i = 1; i <= MaxClients; i++)
{
if(!IsClientInGame(i))
continue;
SDKHook(i, SDKHook_OnTakeDamageAlive, OnTakeDamage);
}
if(RRM_IsRegOpen())
RegisterModifiers();
AutoExecConfig(true, "rrm_charge", "rrm");
}
public int RRM_OnRegOpen()
{
RegisterModifiers();
}
void RegisterModifiers()
{
RRM_Register("Charge", gMin, gMax, false, RRM_Callback_Charge);
}
public void OnConvarChanged(Handle convar, char[] oldValue, char[] newValue)
{
if (StrEqual(oldValue, newValue, true))
return;
float fNewValue = StringToFloat(newValue);
if(convar == cMin)
gMin = fNewValue;
else if(convar == cMax)
gMax = fNewValue;
else if(convar == cDuration)
gDuration = fNewValue;
}
public void OnClientPostAdminCheck(int client)
{
SDKHook(client, SDKHook_OnTakeDamageAlive, OnTakeDamage);
}
public int RRM_Callback_Charge(bool enable, float value)
{
gEnabled = enable;
if(gEnabled)
gChance = value;
return gEnabled;
}
public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &weapon,
float damageForce[3], float damagePosition[3], int damagecustom)
{
if(!gEnabled)
return Plugin_Continue;
if(gChance > RandomFloat(RandomFloat(0.0, 1.0)))
{
if(!(1 <= victim <= MaxClients))
return Plugin_Continue;
if(!IsClientInGame(victim))
return Plugin_Continue;
if(!(1 <= attacker <= MaxClients))
return Plugin_Continue;
if(!IsClientInGame(attacker))
return Plugin_Continue;
if(!IsPlayerAlive(victim))
return Plugin_Continue;
if(!TF2_IsPlayerInCondition(victim, TFCond_Charging))
TF2_AddCondition(victim, TFCond_Charging, gDuration, attacker);
}
return Plugin_Continue;
}
float RandomFloat(const float min = 0.0, const float max = 1.0){
return min + GetURandomFloat() * (max - min);
}