-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
weaponmixup.sp
121 lines (98 loc) · 3.41 KB
/
weaponmixup.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
/**
* Weapon Mixup perk.
* Copyright (C) 2023 Filip Tomaszewski
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define Ticks Int[0]
DEFINE_CALL_APPLY_REMOVE(WeaponMixup)
public void WeaponMixup_Init(const Perk perk)
{
Events.OnResupply(perk, WeaponMixup_Apply);
Events.OnAttackCritCheck(perk, WeaponMixup_OnAttackCritCheck);
Events.OnEntitySpawned(perk, WeaponMixup_OnDroppedWeaponSpawn, Classname_DroppedWeapon, Retriever_AccountId);
}
public void WeaponMixup_ApplyPerk(const int client, const Perk perk)
{
Cache[client].Ticks = 2;
WeaponMixup_Apply(client);
Cache[client].Repeat(0.5, WeaponMixup_SwitchTick);
}
public void WeaponMixup_RemovePerk(const int client, const RTDRemoveReason eRemoveReason)
{
// If Heavy was revved up, this should fix it lingering
TF2_RemoveCondition(client, TFCond_Slowed);
for (int i = 0; i < 3; ++i)
{
int iWeapon = GetPlayerWeaponSlot(client, i);
if (iWeapon <= MaxClients || !IsValidEntity(iWeapon))
continue;
TF2Attrib_RemoveByDefIndex(iWeapon, Attribs.DeploySpeed);
TF2Attrib_RemoveByDefIndex(iWeapon, Attribs.ReloadSpeed);
TF2Attrib_RemoveByDefIndex(iWeapon, Attribs.SilentRev);
}
}
void WeaponMixup_Apply(const int client)
{
for (int i = 0; i < 3; ++i)
{
int iWeapon = GetPlayerWeaponSlot(client, i);
if (iWeapon <= MaxClients || !IsValidEntity(iWeapon))
continue;
TF2Attrib_SetByDefIndex(iWeapon, Attribs.DeploySpeed, 0.5);
TF2Attrib_SetByDefIndex(iWeapon, Attribs.ReloadSpeed, 0.1);
TF2Attrib_SetByDefIndex(iWeapon, Attribs.SilentRev, 1.0);
}
}
public void WeaponMixup_OnDroppedWeaponSpawn(const int client, const int iEnt)
{
AcceptEntityInput(iEnt, "Kill");
}
Action WeaponMixup_SwitchTick(const int client)
{
if (--Cache[client].Ticks > 0)
return Plugin_Continue;
Cache[client].Ticks = 2;
int iCurrentWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
int iNextSlot = WeaponMixup_GetNextSlot(client, iCurrentWeapon);
if (!SwitchSlot(client, iNextSlot))
{
// If switch failed, assume next slot is recharing and fallback to melee
if (!SwitchSlot(client, 2))
{
// If failed again, assume client state is blocking (ex. revved up) then force switch
ForceSwitchSlot(client, 2);
}
}
return Plugin_Continue;
}
bool WeaponMixup_OnAttackCritCheck(const int client, const int iWeapon)
{
Cache[client].Ticks = 0;
return false;
}
int WeaponMixup_GetNextSlot(const int client, const int iCurrentWeapon)
{
static int iSlotOrder[] = {0, 1, 2, 0, 1, 2};
int iCurrentSlot = 0;
for (; iCurrentSlot < 3; ++iCurrentSlot)
if (GetPlayerWeaponSlot(client, iCurrentSlot) == iCurrentWeapon)
break;
int iNextSlotId = iCurrentSlot + 1;
for (; iNextSlotId < sizeof(iSlotOrder); ++iNextSlotId)
if (GetPlayerWeaponSlot(client, iSlotOrder[iNextSlotId]) > MaxClients)
break;
return iNextSlotId >= sizeof(iSlotOrder) ? iCurrentSlot : iSlotOrder[iNextSlotId];
}
#undef Ticks