-
Notifications
You must be signed in to change notification settings - Fork 0
/
retakes_pistolallocator.sp
127 lines (108 loc) · 3.7 KB
/
retakes_pistolallocator.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
#include <sourcemod>
#include <cstrike>
#include <clientprefs>
#include "include/retakes.inc"
#include "retakes/generic.sp"
#pragma semicolon 1
#pragma newdecls required
#define MENU_TIME_LENGTH 15
char g_PistolChoices[][][] = {
// Default pistols:
{ "weapon_glock", "Glock" },
{ "weapon_usp_silencer", "USP" },
{ "weapon_hkp2000", "P2000" },
// Upgraded pistols:
{ "weapon_p250", "P250" },
{ "weapon_tec9", "Tec-9" },
{ "weapon_fiveseven", "Five-Seven" },
{ "weapon_deagle", "Deagle" },
};
int g_PistolChoice[MAXPLAYERS+1];
Handle g_PistolChoiceCookie = INVALID_HANDLE;
public Plugin myinfo = {
name = "CS:GO Retakes: Pistols and nades",
author = "splewis, BatMen, Ejz",
description = "Defines a simple weapon allocation policy that gives Pistols and nades",
version = PLUGIN_VERSION,
url = "https://github.com/splewis/csgo-retakes"
};
public void OnPluginStart() {
g_PistolChoiceCookie = RegClientCookie("retakes_pistolchoice", "", CookieAccess_Private);
}
public void OnClientConnected(int client) {
g_PistolChoice[client] = 1;
}
public void Retakes_OnGunsCommand(int client) {
GiveGunsMenu(client);
}
public void Retakes_OnWeaponsAllocated(ArrayList tPlayers, ArrayList ctPlayers, Bombsite bombsite) {
PistolAllocator(tPlayers, ctPlayers, bombsite);
}
public void OnClientCookiesCached(int client) {
if (IsFakeClient(client))
return;
g_PistolChoice[client] = GetCookieInt(client, g_PistolChoiceCookie);
}
public void SetNades(char nades[NADE_STRING_LENGTH]) {
int rand = GetRandomInt(0, 3);
switch(rand) {
case 0: nades = "";
case 1: nades = "s";
case 2: nades = "f";
case 3: nades = "h";
}
}
public void PistolAllocator(ArrayList tPlayers, ArrayList ctPlayers, Bombsite bombsite) {
int tCount = GetArraySize(tPlayers);
int ctCount = GetArraySize(ctPlayers);
char primary[WEAPON_STRING_LENGTH];
char secondary[WEAPON_STRING_LENGTH];
char nades[NADE_STRING_LENGTH];
int health = 100;
int kevlar = 100;
bool helmet = false;
bool kit = true;
for (int i = 0; i < tCount; i++) {
int client = GetArrayCell(tPlayers, i);
int choice = g_PistolChoice[client];
strcopy(secondary, sizeof(secondary), g_PistolChoices[choice][0]);
health = 100;
kevlar = IsDefaultPistol(choice) ? 100 : 0;
helmet = false;
kit = false;
SetNades(nades);
Retakes_SetPlayerInfo(client, primary, secondary, nades, health, kevlar, helmet, kit);
}
for (int i = 0; i < ctCount; i++) {
int client = GetArrayCell(ctPlayers, i);
int choice = g_PistolChoice[client];
strcopy(secondary, sizeof(secondary), g_PistolChoices[choice][0]);
kit = true;
health = 100;
kevlar = IsDefaultPistol(choice) ? 100 : 0;
helmet = false;
SetNades(nades);
Retakes_SetPlayerInfo(client, primary, secondary, nades, health, kevlar, helmet, kit);
}
}
public void GiveGunsMenu(int client) {
Menu menu = new Menu(GunsMenuHandler);
SetMenuTitle(menu, "Select a pistol:");
for (int i = 0; i < sizeof(g_PistolChoices); i++) {
AddMenuInt(menu, i, g_PistolChoices[i][1]);
}
DisplayMenu(menu, client, MENU_TIME_LENGTH);
}
public int GunsMenuHandler(Menu menu, MenuAction action, int param1, int param2) {
if (action == MenuAction_Select) {
int client = param1;
int choice = GetMenuInt(menu, param2);
g_PistolChoice[client] = choice;
SetCookieInt(client, g_PistolChoiceCookie, choice);
} else if (action == MenuAction_End) {
CloseHandle(menu);
}
}
public bool IsDefaultPistol(int weaponIndex) {
return weaponIndex <= 2;
}