forked from splewis/csgo-pug-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpugsetup_chatmoney.sp
117 lines (97 loc) · 3.42 KB
/
pugsetup_chatmoney.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
#include <cstrike>
#include <sourcemod>
#include "include/pugsetup.inc"
#include "pugsetup/generic.sp"
#pragma semicolon 1
#pragma newdecls required
ConVar g_hEnabled;
public Plugin myinfo = {
name = "CS:GO PugSetup: write team money to chat",
author = "Versatile_BFG/jkroepke",
description = "Write the team members' money to the chat (like WarMod)",
version = PLUGIN_VERSION,
url = "https://github.com/splewis/csgo-pug-setup"
};
public void OnPluginStart() {
LoadTranslations("pugsetup.phrases");
g_hEnabled = CreateConVar("sm_pugsetup_chatmoney_enabled", "1", "Whether the plugin is enabled");
AutoExecConfig(true, "pugsetup_chatmoney", "sourcemod/pugsetup");
HookEvent("round_start", Event_Round_Start);
}
public Action Event_Round_Start(Event event, const char[] name, bool dontBroadcast) {
if (!PugSetup_IsMatchLive() || g_hEnabled.IntValue == 0)
return;
ArrayList players = new ArrayList();
// sort by money
for (int i = 1; i <= MaxClients; i++) {
if (IsPlayer(i) && OnActiveTeam(i)) {
players.Push(i);
}
}
SortADTArrayCustom(players, SortMoneyFunction);
char player_money[16];
char has_weapon[4];
int pri_weapon;
int numPlayers = players.Length;
// display team players money
for (int i = 0; i < numPlayers; i++) {
for (int j = 0; j < numPlayers; j++) {
int displayClient = players.Get(i);
int moneyClient = players.Get(j);
if (GetClientTeam(displayClient) == GetClientTeam(moneyClient)) {
pri_weapon = GetPlayerWeaponSlot(moneyClient, 0);
if (pri_weapon == -1) {
has_weapon = ">";
} else {
has_weapon = "\0";
}
IntToMoney(GetClientMoney(moneyClient), player_money, sizeof(player_money));
PugSetup_Message(displayClient, "\x01$%s \x04%s> \x03%N", player_money, has_weapon, moneyClient);
}
}
}
delete players;
}
public int SortMoneyFunction(int index1, int index2, Handle array, Handle hnd) {
int client1 = GetArrayCell(array, index1);
int client2 = GetArrayCell(array, index2);
int money1 = GetClientMoney(client1);
int money2 = GetClientMoney(client2);
if (money1 > money2) {
return -1;
} else if (money1 == money2) {
return 0;
} else {
return 1;
}
}
public int GetClientMoney(int client) {
int offset = FindSendPropInfo("CCSPlayer", "m_iAccount");
return GetEntData(client, offset);
}
/**
* Get the comma'd string version of an integer
*
* @param OldMoney the integer to convert
* @param String:NewMoney the buffer to save the string in
* @param size the size of the buffer
* @noreturn
*/
public void IntToMoney(int OldMoney, char[] NewMoney, int size) {
char Temp[32];
char OldMoneyStr[32];
char tempChar;
int RealLen = 0;
IntToString(OldMoney, OldMoneyStr, sizeof(OldMoneyStr));
for (int i = strlen(OldMoneyStr) - 1; i >= 0; i--) {
if (RealLen % 3 == 0 && RealLen != strlen(OldMoneyStr) && i != strlen(OldMoneyStr)-1) {
tempChar = OldMoneyStr[i];
Format(Temp, sizeof(Temp), "%s,%s", tempChar, Temp);
} else{
tempChar = OldMoneyStr[i];
Format(Temp, sizeof(Temp), "%s%s", tempChar, Temp);
}
RealLen++;
}
Format(NewMoney, size, "%s", Temp);
}