· 6 years ago · Mar 26, 2019, 01:40 PM
1#include <sourcemod>
2#include <sdktools>
3#include <multicolors>
4#include <cstrike>
5#pragma semicolon 1
6
7#define MAX_STEAMAUTH_LENGTH 21
8#define MAX_COMMUNITYID_LENGTH 18
9
10// Handle for the db
11new Handle:db;
12
13
14
15public OnPluginStart()
16{
17 // Testcommand
18 RegConsoleCmd("sm_kjlgdfjgfdkldgjkldgfljkgdfkjgklj", Command_Test);
19
20 // Create database if it doesn't exist and create rhe table
21 InitDB(db);
22}
23
24
25
26InitDB(&Handle:DbHNDL)
27{
28
29 // Errormessage Buffer
30 new String:Error[255];
31
32 // COnnect to the DB
33 DbHNDL = SQL_Connect("tVip", true, Error, sizeof(Error));
34
35
36 // If something fails we quit
37 if(DbHNDL == INVALID_HANDLE)
38 {
39 SetFailState(Error);
40 }
41
42 // Querystring
43 new String:Query[255];
44 Format(Query, sizeof(Query), "CREATE TABLE IF NOT EXISTS raffle (steamid TEXT UNIQUE, name TEXT);");
45
46 // Database lock
47 SQL_LockDatabase(DbHNDL);
48
49 // Execute the query
50 SQL_FastQuery(DbHNDL, Query);
51
52 // Database unlock
53 SQL_UnlockDatabase(DbHNDL);
54
55}
56
57
58public Action:Command_Test(client, args)
59{
60
61 decl String:szSteamId2[MAX_STEAMAUTH_LENGTH];
62 GetClientAuthId(client, AuthId_Steam2, szSteamId2, sizeof(szSteamId2));
63 new String:Query[255];
64 Format(Query, sizeof(Query), "INSERT OR IGNORE INTO raffle ('%s', '%N')", szSteamId2, client);
65
66 SQL_TQuery(db, SQL_ErrorCheckCallBack, Query);
67
68
69
70 return Plugin_Handled;
71}
72
73
74
75
76
77public SQL_ErrorCheckCallBack(Handle:owner, Handle:hndl, const String:error[], any:data)
78{
79 // This is just an errorcallback for function who normally don't return any data
80 if(hndl == INVALID_HANDLE)
81 {
82 SetFailState("Query failed! %s", error);
83 }
84}