/
ttt_api_test.sp
179 lines (143 loc) · 5.46 KB
/
ttt_api_test.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#pragma semicolon 1
#include <sourcemod>
#include <ttt>
#include <ttt_sql>
#include <ttt_shop>
#include <ttt_grabbermod>
#pragma newdecls required
#define PLUGIN_NAME TTT_PLUGIN_NAME ... " - API Test"
#define PLUGIN_ITEM_SHORT "testitem"
#define PLUGIN_ITEM_LONG "Test Item"
#define PLUGIN_ITEM_PRICE 350
public Plugin myinfo = {
name = PLUGIN_NAME,
author = TTT_PLUGIN_AUTHOR,
description = TTT_PLUGIN_DESCRIPTION,
version = TTT_PLUGIN_VERSION,
url = TTT_PLUGIN_URL
};
public void OnPluginStart()
{
TTT_IsGameCSGO();
CreateConVar("ttt2_api_test_version", TTT_PLUGIN_VERSION, TTT_PLUGIN_DESCRIPTION, FCVAR_NOTIFY | FCVAR_DONTRECORD | FCVAR_REPLICATED);
HookEvent("weapon_fire", Event_WeaponFire);
RegAdminCmd("sm_uitem", Command_UItem, ADMFLAG_ROOT);
RegAdminCmd("sm_trole", Command_TRole, ADMFLAG_ROOT);
}
public Action Command_TRole(int client, int args)
{
int iRole = TTT_GetClientRole(client);
char sRole[ROLE_LENGTH], sShort[ROLE_LENGTH];
TTT_GetRoleNameByID(iRole, sRole, sizeof(sRole));
TTT_GetShortRoleNameByID(iRole, sShort, sizeof(sShort));
PrintToChat(client, "(1) Player: %N - RoleID: %d - RoleName: %s - RoleShort: %s", client, iRole, sRole, sShort);
TTT_GetRoleNameByShortName(sShort, sRole, sizeof(sRole));
PrintToChat(client, "(2) Player: %N - RoleID: %d - RoleName: %s - RoleShort: %s", client, iRole, sRole, sShort);
iRole = TTT_GetRoleIDByName(sRole);
PrintToChat(client, "(3) Player: %N - RoleID: %d - RoleName: %s - RoleShort: %s", client, iRole, sRole, sShort);
iRole = TTT_GetRoleIDByShortName(sShort);
PrintToChat(client, "(4) Player: %N - RoleID: %d - RoleName: %s - RoleShort: %s", client, iRole, sRole, sShort);
TTT_GetShortRoleNameByName(sRole, sShort, sizeof(sShort));
PrintToChat(client, "(5) Player: %N - RoleID: %d - RoleName: %s - RoleShort: %s", client, iRole, sRole, sShort);
}
public Action Command_UItem(int client, int args)
{
if (args != 2)
{
ReplyToCommand(client, "sm_uitem <item name (short)> <price>");
return Plugin_Handled;
}
char arg1[MAX_NAME_LENGTH], arg2[5];
GetCmdArg(1, arg1, sizeof(arg1));
GetCmdArg(2, arg2, sizeof(arg2));
TTT_UpdateCustomItem(arg1, StringToInt(arg2));
return Plugin_Continue;
}
public void OnConfigsExecuted()
{
RegisterItem();
}
void RegisterItem()
{
TTT_RegisterCustomItem(PLUGIN_ITEM_SHORT, PLUGIN_ITEM_LONG, PLUGIN_ITEM_PRICE);
}
public Action TTT_OnItemPurchase(int client, int &price, bool &count, const char[] item)
{
if (TTT_IsClientValid(client) && IsPlayerAlive(client) && strlen(item) > 2)
{
PrintToChat(client, "[TTT_OnItemPurchase] It works! Hooray! Item: %s Price: %d Count: %d", item, price, count);
}
return Plugin_Continue;
}
public Action TTT_OnItemPurchased(int client, const char[] item, bool count)
{
if (TTT_IsClientValid(client) && IsPlayerAlive(client) && strlen(item) > 2)
{
PrintToChat(client, "[TTT_OnItemPurchased] It works! Hooray! Item: %s Count: %d", item, count);
}
return Plugin_Continue;
}
public Action Event_WeaponFire(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (TTT_IsClientValid(client))
{
PrintToChat(client, "Player: %N, Karma %d, Credits: %d", client, TTT_GetClientKarma(client), TTT_GetClientCredits(client));
}
}
public void TTT_OnRoundStart(int innocents, int traitors, int detective)
{
PrintToServer("TTT_OnRoundStart was called!");
PrintToServer("(TTT_OnRoundStart) innocents: %d - traitors: %d - detective: %d", innocents, traitors, detective);
}
public void TTT_OnRoundStartFailed(int players, int requiredPlayers, int detective)
{
PrintToServer("TTT_OnRoundStartFailed was called!");
PrintToServer("(TTT_OnRoundStartFailed) players: %d - requiredPlayers: %d - detective: %d", players, requiredPlayers, detective);
}
public void TTT_OnClientGetRole(int client, int role)
{
PrintToServer("TTT_OnClientGetRole was called!");
PrintToServer("(TTT_OnClientGetRole) client: %d - role: %d", client, role);
}
public void TTT_OnClientDeath(int victim, int attacker)
{
PrintToServer("TTT_OnClientDeath was called!");
PrintToServer("(TTT_OnClientDeath) victim: %d - attacker: %d", victim, attacker);
}
public Action TTT_OnClientDeathPre(int victim, int attacker)
{
PrintToServer("TTT_OnClientDeathPre was called!");
PrintToServer("(TTT_OnClientDeathPre) victim: %d - attacker: %d", victim, attacker);
}
public void TTT_OnBodyFound(int client, int victim, const char[] deadPlayer, bool silent)
{
PrintToServer("TTT_OnBodyFound was called!");
PrintToServer("(TTT_OnBodyFound) client: %d - victim: %d - deadPlayer: %s - silent: %b", client, victim, deadPlayer, silent);
}
public void TTT_OnBodyScanned(int client, int victim, const char[] deadPlayer)
{
PrintToServer("TTT_OnBodyScanned was called!");
PrintToServer("(TTT_OnBodyScanned) client: %d - victim: %d - deadPlayer: %s", client, victim, deadPlayer);
}
public Action TTT_OnPlayerDeath(int victim, int attacker)
{
PrintToServer("TTT_OnPlayerDeath was called!");
PrintToServer("(TTT_OnPlayerDeath) victim: %d - attacker: %d", victim, attacker);
}
public void TTT_OnSQLConnect(Database db)
{
PrintToServer("TTT_OnSQLConnect was called!");
PrintToServer("(TTT_OnSQLConnect) db: %d", db);
Database dDB = TTT_GetSQLConnection();
PrintToServer("(TTT_OnSQLConnect) dDB: %d", dDB);
if (dDB == db)
{
PrintToServer("(TTT_OnSQLConnect) db and dDB are equal!", db);
}
}
public bool TTT_OnGrabbing(int client, int entity)
{
PrintToServer("TTT_OnGrabbing was called!");
PrintToServer("(TTT_OnGrabbing) Client: %N - Entity: %d", client, entity);
}