· 5 years ago · Nov 22, 2020, 05:18 PM
1//Includes
2#include < sourcemod >
3#include < sdktools >
4#include < cstrike >
5#include < emitsoundany >
6
7#define MAX_STEAMAUTH_LENGTH 21
8#define MAX_COMMUNITYID_LENGTH 18
9#pragma tabsize 0
10//Definitions
11#define PLUGIN_VERSION "1.3"
12
13#define TAG "{blue}[Sklep]"
14
15int user_points[MAXPLAYERS + 1];
16int user_loaded[MAXPLAYERS + 1];
17
18ConVar g_vip;
19ConVar g_player;
20
21Database DB;
22
23public Plugin:myinfo = {
24 name = "sklep",
25 author = "Never",
26 description = "sklep z Fajkami",
27 version = PLUGIN_VERSION,
28 url = ""
29}
30
31public OnPluginStart()
32{
33 HookEvent("player_death", Event_PlayerDeath);
34 g_vip = CreateConVar("vip_get_nabojes", "6", "VIP get nabojes");
35 g_player = CreateConVar("player_get_nabojes", "3", "Player get nabojes");
36}
37
38// hooki
39public void Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
40{
41 int victim = GetClientOfUserId(event.GetInt("userid"));
42 int attacker = GetClientOfUserId(event.GetInt("attacker"));
43
44
45 if (!attacker || victim == attacker || !IsClientInGame(attacker) || IsFakeClient(attacker) || !IsClientInGame(victim) || IsFakeClient(victim) || GetClientTeam(attacker) == GetClientTeam(victim)) {
46 return;
47 }
48
49 // jezeli vip, to ...
50 if(true)
51 {
52 addUserPoints(attacker,6); // dodaje 6 punkty dla atakujacego/zabijajacego
53 }
54 else
55 {
56 addUserPoints(attacker,3);
57 }
58
59
60}
61
62// map start hook
63public void OnMapStart()
64{
65 char error[128];
66 DB = SQL_Connect("Naboje", true, error, sizeof(error));
67 if (DB == INVALID_HANDLE) {
68 ThrowError("Could not connect: %s", error);
69 return;
70 }
71
72 char buffer[1024];
73 Format(buffer, sizeof(buffer), "CREATE TABLE IF NOT EXISTS `Naboje`(`steamid` INT NOT NULL PRIMARY KEY, `nick` VARCHAR(64), `naboje` INT NOT NULL);");
74 if (!SQL_Query(DB, buffer)) {
75 SQL_GetError(DB, error, sizeof(error));
76 ThrowError("Nie udalo sie stowrzyc tabeli! Error: %s", error);
77 }
78}
79// client connecting hook
80public void OnClientPutInServer(int client)
81{
82
83 if (IsFakeClient(client) || IsClientSourceTV(client))
84 return;
85
86 user_loaded[client] = false;
87 user_points[client] = 0;
88
89 int sid = GetSteamAccountID(client);
90 char buffer[1024];
91 Format(buffer, sizeof(buffer), "SELECT `Naboje` FROM `Naboje` WHERE `steamid` = '%d';", sid);
92 SQL_TQuery(DB, LoadPlayerCallback, buffer, client);
93}
94
95public LoadPlayerCallback(Handle owner, Handle hQuery, const char[] error, any client)
96{
97 if (hQuery == INVALID_HANDLE) {
98 ThrowError("Load player naboje MySQL error: %s", error);
99 return;
100 }
101
102 if (SQL_GetRowCount(hQuery)) {
103 while (SQL_FetchRow(hQuery)) {
104 user_loaded[client] = true;
105 user_points[client] = SQL_FetchInt(hQuery, 0);
106 }
107 }
108 else {
109 int sid = GetSteamAccountID(client);
110 char buffer[1024];
111 char s_name[64];
112 GetClientName(client, s_name, sizeof(s_name));
113 Format(buffer, sizeof(buffer), "INSERT INTO `Naboje`(steamid, nick, naboje) VALUES(%d, '%N', 0);", sid, s_name);
114 SQL_TQuery(DB, InsertPlayerCallback, buffer);
115 }
116}
117
118
119// Dodaje konkretna ilosc punktow do bazy sql i do zmiennej
120public int addUserPoints(int client, int value)
121{
122 if(IsClientInGame(client) && !IsFakeClient(client) && user_loaded[client])
123 {
124 user_points[client] += value;
125 int sid = GetSteamAccountID(client);
126 char buffer[1024];
127 Format(buffer, sizeof(buffer), "UPDATE `Naboje` SET `naboje` = `naboje` + %d WHERE `steamid` = '%d';", value, sid);
128 SQL_TQuery(DB, UpdatePlayerCallback, buffer);
129 }
130}
131// ustawia konkretna ilosc punktow w sql i zmiennej
132public void setUserPoints(int client, int value)
133{
134 if(IsClientInGame(client) && !IsFakeClient(client) && user_loaded[client])
135 {
136 user_points[client] = value;
137 int sid = GetSteamAccountID(client);
138 char buffer[1024];
139 Format(buffer, sizeof(buffer), "UPDATE `Naboje` SET `naboje` = %d WHERE `steamid` = '%d';", user_points[client], sid);
140 SQL_TQuery(DB, UpdatePlayerCallback, buffer);
141 }
142}
143// zwraca ilosc punktow
144public int getUserPoints(int client)
145{
146 if(IsClientInGame(client) && !IsFakeClient(client) && user_loaded[client])
147 {
148 return user_points[client];
149 }
150 else
151 return 0;
152}
153
154public UpdatePlayerCallback(Handle owner, Handle hQuery, const char[] error, any client)
155{
156 if (hQuery == INVALID_HANDLE) {
157 ThrowError("Update player naboje MySQL error: %s", error);
158 }
159}
160
161public InsertPlayerCallback(Handle owner, Handle hQuery, const char[] error, any client)
162{
163 if (hQuery == INVALID_HANDLE) {
164 ThrowError("Insert player naboje MySQL error: %s", error);
165 }
166}
167
168// Bool check permission
169bool:vip_player(client)
170{
171 return CheckCommandAccess(client, "", ADMFLAG_CUSTOM1, true);
172}
173bool:player_admin(client)
174{
175 return CheckCommandAccess(client, "", ADMFLAG_ROOT, true);
176}