-
Notifications
You must be signed in to change notification settings - Fork 3
/
gfldm-autoreload.sp
145 lines (122 loc) · 4.34 KB
/
gfldm-autoreload.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
// Copyright (C) 2020 dreae
//
// This file is part of gfl-dm-pack.
//
// gfl-dm-pack 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.
//
// gfl-dm-pack 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 gfl-dm-pack. If not, see <http://www.gnu.org/licenses/>.
#pragma semicolon 1
#include <sourcemod>
#include <cstrike>
#include <gfldm>
public Plugin myinfo = {
name = "GFLDM Autoreload",
author = "Dreae",
description = "Configurable automatic weapon reloads",
version = GFLDM_VERSION,
url = "https://github.com/GFLClan/gfl-dm-pack"
};
enum struct ReloadValues {
int on_kill;
int on_headshot;
int max;
}
StringMap weapon_config;
public OnPluginStart() {
GFLDM_DefineVersion("gfldm_autoreload_version");
weapon_config = new StringMap();
HookEvent("player_death", Event_PlayerDeath);
}
public OnMapStart() {
KeyValues kv = new KeyValues("autoreload", "", "");
char config_path[2048];
BuildPath(Path_SM, config_path, sizeof(config_path), "configs/gfldm_autoreload.txt");
if (!kv.ImportFromFile(config_path)) {
BuildDefaultKV(kv);
kv.ExportToFile(config_path);
}
kv.GotoFirstSubKey();
char weapon_name[64];
do {
kv.GetSectionName(weapon_name, sizeof(weapon_name));
ReloadValues curr_weapon;
curr_weapon.on_kill = kv.GetNum("on_kill", 0);
curr_weapon.on_headshot = kv.GetNum("on_headshot", 0);
curr_weapon.max = kv.GetNum("max", 0);
weapon_config.SetArray(weapon_name, curr_weapon, sizeof(curr_weapon));
} while (kv.GotoNextKey());
delete kv;
}
public void Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast) {
int attacker = GetClientOfUserId(event.GetInt("attacker"));
if (!GFLDM_IsValidClient(attacker)) {
return;
}
char weapon[64];
event.GetString("weapon", weapon, sizeof(weapon));
Format(weapon, sizeof(weapon), "weapon_%s", weapon);
ReloadValues curr_weapon;
if (weapon_config.GetArray(weapon, curr_weapon, sizeof(curr_weapon))) {
int offset = FindDataMapInfo(attacker, "m_hMyWeapons");
int weapon_ent = 0;
for (int c = 0; c < 48; c++) {
weapon_ent = GetEntDataEnt2(attacker, offset);
if (IsValidEdict(weapon_ent)) {
char clsname[64];
if (GetEdictClassname(weapon_ent, clsname, sizeof(clsname))) {
if (StrEqual(clsname, weapon)) {
int m_iClip1 = GetEntProp(weapon_ent, Prop_Data, "m_iClip1");
if (event.GetBool("headshot")) {
m_iClip1 += curr_weapon.on_headshot;
} else {
m_iClip1 += curr_weapon.on_kill;
}
if (m_iClip1 > curr_weapon.max) {
SetEntProp(weapon_ent, Prop_Data, "m_iClip1", curr_weapon.max);
} else {
SetEntProp(weapon_ent, Prop_Data, "m_iClip1", m_iClip1);
}
break;
}
}
}
offset += 4;
}
}
}
void BuildDefaultKV(KeyValues kv) {
kv.JumpToKey("weapon_deagle", true);
kv.SetNum("on_kill", 3);
kv.SetNum("on_headshot", 7);
kv.SetNum("max", 7);
kv.Rewind();
kv.JumpToKey("weapon_scout", true);
kv.SetNum("on_kill", 2);
kv.SetNum("on_headshot", 4);
kv.SetNum("max", 10);
kv.Rewind();
kv.JumpToKey("weapon_ak47", true);
kv.SetNum("on_kill", 5);
kv.SetNum("on_headshot", 8);
kv.SetNum("max", 30);
kv.Rewind();
kv.JumpToKey("weapon_m4a1", true);
kv.SetNum("on_kill", 5);
kv.SetNum("on_headshot", 8);
kv.SetNum("max", 30);
kv.Rewind();
kv.JumpToKey("weapon_m4a1_silencer", true);
kv.SetNum("on_kill", 5);
kv.SetNum("on_headshot", 8);
kv.SetNum("max", 30);
kv.Rewind();
}