· 7 years ago · Sep 09, 2018, 06:02 PM
1#include <sourcemod>
2#include <sdktools>
3#include <sdkhooks>
4
5new g_iViewModel;
6new g_iWorldModel;
7new g_iUsedViewModelIndex[MAXPLAYERS+1];
8new Handle:db;
9
10public OnClientPutInServer(Client)
11{
12 SDKHook(Client, SDKHook_WeaponSwitch, WeaponHook);
13 SDKHook(Client, SDKHook_WeaponEquip, WeaponHook);
14}
15
16public OnMapStart()
17{
18 g_iViewModel = PrecacheModel("models/oldschool/weapons/awp/assimov/v_snip_awp.mdl", true);
19 g_iWorldModel = PrecacheModel("models/oldschool/weapons/awp/assimov/w_snip_awp.mdl", true);
20}
21
22public OnPluginStart()
23{
24 InitDB(db);
25 HookEvent("player_spawn", Event_Player_Spawn);
26}
27
28InitDB(&Handle:DbDbHNDL)
29{
30
31 // Errormessage Buffer
32 new String:Error[255];
33 if (SQL_CheckConfig("gud"))
34 {
35
36 // COnnect to the DB
37 DbDbHNDL = SQL_Connect("gud", true, Error, sizeof(Error));
38
39
40 // If something fails we quit
41 if(DbDbHNDL == INVALID_HANDLE)
42 {
43 SetFailState(Error);
44 }
45
46 // Querystring
47 //new String:Query[255];
48 //Format(Query, sizeof(Query), "CREATE TABLE IF NOT EXISTS players (steamid TEXT UNIQUE, name TEXT);");
49
50 // Database lock
51 SQL_LockDatabase(DbDbHNDL);
52
53 // Execute the query
54 //SQL_FastQuery(DbDbHNDL, Query);
55
56 // Database unlock
57 SQL_UnlockDatabase(DbDbHNDL);
58}
59 else
60 {
61 SetFailState("[TESZTSKIN] Cant find `GUD` on database.cfg");
62 }
63}
64
65public OnClientAuthorized(Client)
66{
67 decl String:auth[32];
68 GetClientAuthString(Client, auth, sizeof(auth));
69}
70
71bool:DB_GetStats(Client)
72{
73 decl String:auth[32];
74 decl String:szQuery[96];
75 //Format(szQuery, sizeof(szQuery), "SELECT items.active,players.id,players.steamid FROM items INNER JOIN players ON items.owner = players.id WHERE players.steamid = '%s'", auth);
76 Format(szQuery, sizeof(szQuery), "SELECT active FROM items WHERE owner = '1'");
77 new Handle:hQuery = SQL_Query(db, szQuery);
78
79 LoadData(hQuery, Client);
80
81 return true;
82}
83
84LoadData(Handle:hQuery, Client)
85{
86 if (db != INVALID_HANDLE)
87 {
88 decl String:gClassSkin[512];
89 decl String:gClassActive[512];
90 //new gClassSkin[512];
91 //new gClassActive[512];
92 new i;
93 while(SQL_FetchRow(hQuery))
94 {
95 i = SQL_FetchInt(hQuery, 2);
96
97 //gClassSkin[Client][y] = SQL_FetchInt(hQuery, 3);
98 //gClassActive[Client][y] = SQL_FetchInt(hQuery, 4);
99 //gClassSkin[Client] = SQL_FetchInt(hQuery, 3);
100 //gClassActive[Client] = SQL_FetchInt(hQuery, 4);
101 gClassSkin[i] = SQL_FetchInt(hQuery, 3);
102 gClassActive[i] = SQL_FetchInt(hQuery, 4);
103 }
104 //for(new i=0; i <= MAX-1; i++)
105 //{
106 //OsszesSkin[i][id] = SQL_FetchInt(hQuery, 22+i)
107 //}
108 }
109}
110
111public OnGameFrame()
112{
113 //decl String:buffer[4096];
114 DB_GetStats;
115}
116
117public Action:Event_Player_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
118{
119 new Client = GetClientOfUserId(GetEventInt(event, "userid"));
120
121 new ActiveWeapon = GetEntPropEnt(Client, Prop_Data, "m_hActiveWeapon");
122 if(ActiveWeapon != -1)
123 {
124 CreateTimer(0.1, ChangeModelIndex, Client);
125 }
126 return Plugin_Continue;
127}
128
129public Action:WeaponHook(Client, weapon)
130{
131 new ActiveWeapon = GetEntPropEnt(Client, Prop_Data, "m_hActiveWeapon");
132 if(ActiveWeapon != -1)
133 {
134 CreateTimer(0.1, ChangeModelIndex, Client);
135 }
136 return Plugin_Continue;
137}
138
139GetSendPropOffset(const String:serverClass[], const String:propName[])
140{
141 new offset = FindSendPropInfo(serverClass, propName);
142
143 if (!offset)
144 {
145 SetFailState("Fatal Error: Unable to find offset: \"%s::%s\"!", serverClass, propName);
146 }
147
148 return offset;
149}
150
151public Weapon_GetViewModelIndex(Client)
152{
153 new index = -1;
154 while ((index = FindEntityByClassname2(index, "predicted_viewmodel")) != -1)
155 {
156 new Owner = GetEntPropEnt(index, Prop_Send, "m_hOwner");
157 new ClientWeapon = GetEntPropEnt(Client, Prop_Send, "m_hActiveWeapon");
158 new Weapon = GetEntPropEnt(index, Prop_Send, "m_hWeapon");
159 if (Owner != Client)
160 continue;
161 if (ClientWeapon != Weapon)
162 continue;
163 return index;
164 }
165 return -1;
166}
167
168stock FindEntityByClassname2(startEnt, const String:classname[])
169{
170 while (startEnt > -1 && !IsValidEntity(startEnt)) startEnt--;
171 return FindEntityByClassname(startEnt, classname);
172}
173
174public Action:ChangeModelIndex(Handle:Timer, any:Client)
175{
176 new ActiveWeapon = GetEntPropEnt(Client, Prop_Data, "m_hActiveWeapon");
177 g_iUsedViewModelIndex[Client] = Weapon_GetViewModelIndex(Client);
178
179 //decl String:gClassActive[512];
180 //new gClassActive = 1;
181 //new gClassSkin = 1;
182 new gClassActive
183 //decl String:gClassSkin[512];
184 decl String:i;
185 gClassActive = 1;
186 decl String:sWeapon[64];
187 GetEdictClassname(ActiveWeapon, sWeapon, sizeof(sWeapon));
188 //if(StrEqual(sWeapon, "weapon_awp") && (gClassActive == 1) && (gClassSkin == 1))
189 //if(StrEqual(sWeapon, "weapon_awp"))
190 if((gClassActive == 1))
191 {
192 SetEntProp(ActiveWeapon, Prop_Send, "m_iWorldModelIndex", g_iWorldModel);
193 SetEntProp(ActiveWeapon, Prop_Send, "m_iViewModelIndex", g_iViewModel);
194 //SetEntProp(ActiveWeapon, Prop_Send, "m_iWorldDroppedModelIndex", g_iWorldModel);
195
196 SetEntData(g_iUsedViewModelIndex[Client], GetSendPropOffset("CBaseViewModel", "m_nModelIndex"), g_iViewModel, _, true);
197 SetEntData(g_iUsedViewModelIndex[Client], GetSendPropOffset("CBaseViewModel", "m_nSequence"), GetEntData(g_iUsedViewModelIndex[Client], GetSendPropOffset("CBaseViewModel", "m_nSequence")), _, true);
198 //SetEntData(g_iUsedViewModelIndex[Client], GetSendPropOffset("CBaseCombatWeapon", "m_iWorldDroppedModelIndex"), g_iWorldModel, _, true);
199 //SetEntData(ActiveWeapon, GetSendPropOffset("CWeaponCSBase", "m_iViewModelIndex"), g_iViewModel, _, true);
200 //SetEntData(ActiveWeapon, GetSendPropOffset("CWeaponCSBase", "m_iWorldModelIndex"), g_iWorldModel, _, true);
201
202 //SetEntData(ActiveWeapon, GetSendPropOffset("CWeaponCSBaseGun", "m_iViewModelIndex"), g_iViewModel, _, true);
203 //SetEntData(ActiveWeapon, GetSendPropOffset("CWeaponCSBaseGun", "m_iWorldModelIndex"), g_iWorldModel, _, true);
204
205 //SetEntData(ActiveWeapon, FindSendPropInfo("CBaseCombatWeapon", "m_iViewModelIndex"), g_iViewModel, _, true);
206 //SetEntData(ActiveWeapon, FindSendPropInfo("CBaseCombatWeapon", "m_iWorldModelIndex"), g_iWorldModel, _, true);
207 //SetEntData(ActiveWeapon, GetSendPropOffset("CBaseCombatWeapon", "m_iWorldDroppedModelIndex"), g_iWorldModel, _, true);
208 //SetEntData(ActiveWeapon, FindSendPropInfo("CBaseCombatWeapon", "m_iWorldDroppedModelIndex"), g_iWorldModel, _, true);
209 }
210}