HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <sdkhooks>
  4. #include <multicolors>
  5. #include <clientprefs>
  6. #include <cstrike>
  7. #include <fpvm_interface>
  8.  
  9. #pragma newdecls required // let's go new syntax!
  10.  
  11. int iTridaggerModel,iTridaggerSteelModel,iBlackDagger,iKabar,iOldKnife,iUltimateKnife, ifu, ides;
  12. int KnifeSelection[MAXPLAYERS+1];
  13. Handle g_hMySelection;
  14. Handle g_hMyFirstJoin;
  15. int showMenu[MAXPLAYERS+1] = 1;
  16.  
  17. #define DATA "2.3.1"
  18.  
  19. Handle cvar_time, timers, trie_times, cvar_times;
  20. int g_veces, g_time;
  21.  
  22. public Plugin myinfo =
  23. {
  24. name = "Custom Knife Models",
  25. author = "Mr.Derp & Franc1sco franug",
  26. description = "Custom Knife Models",
  27. version = DATA,
  28. url = "http://steamcommunity.com/id/iLoveAnime69"
  29. }
  30.  
  31. public void OnPluginStart()
  32. {
  33. trie_times = CreateTrie();
  34.  
  35. CreateConVar("sm_customknifemodels_version", DATA, "plugin info", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
  36.  
  37. cvar_time = CreateConVar("sm_customknifemodels_time", "20", "time in the round start that a normal client can use the !ck command. 0 = disabled.");
  38. cvar_times = CreateConVar("sm_customknifemodels_times", "5", "times in the map that a normal client can use the !ck command. 0 = disabled.");
  39. g_veces = GetConVarInt(cvar_times);
  40. g_time = GetConVarInt(cvar_time);
  41. HookConVarChange(cvar_time, OnConVarChanged);
  42. HookConVarChange(cvar_times, OnConVarChanged);
  43.  
  44. HookEvent("player_spawn", Event_Spawn, EventHookMode_Post);
  45. HookEvent("round_start", Event_Start);
  46. RegConsoleCmd("sm_customknife", Cmd_sm_customknife, "Knife Menu");
  47. RegConsoleCmd("sm_ck", Cmd_sm_customknife, "Knife Menu");
  48. g_hMySelection = RegClientCookie("ck_selection", "Knife Selection", CookieAccess_Protected);
  49. g_hMyFirstJoin = RegClientCookie("ck_firstjoin", "Knife Menu Show", CookieAccess_Protected);
  50.  
  51. for (int i = MaxClients; i > 0; --i)
  52. {
  53. if (!AreClientCookiesCached(i))
  54. {
  55. continue;
  56. }
  57.  
  58. OnClientCookiesCached(i);
  59. }
  60. }
  61.  
  62. public void OnConVarChanged(Handle convar, const char[] oldValue, const char[] newValue)
  63. {
  64. if (convar == cvar_time)
  65. {
  66. g_time = StringToInt(newValue);
  67. }
  68. else if (convar == cvar_times)
  69. {
  70. g_veces = StringToInt(newValue);
  71. }
  72. }
  73.  
  74. public void OnMapStart()
  75. {
  76. ClearTrie(trie_times);
  77.  
  78. iTridaggerModel = PrecacheModel("models/weaponf/v_knife_tridagger_v2.mdl");
  79. iTridaggerSteelModel = PrecacheModel("models/weaponf/v_knife_tridagger_steel.mdl");
  80. iBlackDagger = PrecacheModel("models/weaponf/v_knife_reaper.mdl");
  81. iKabar = PrecacheModel("models/weaponf/v_knife_kabar_v2.mdl");
  82. iOldKnife = PrecacheModel("models/weaponf/crashz.mdl");
  83. iUltimateKnife = PrecacheModel("models/weaponf/v_knife_ultimate.mdl");
  84.  
  85. ifu = PrecacheModel("models/weapons/v_gongfu.mdl");
  86. ides = PrecacheModel("models/weapons/caleon1/screwdriver/v_knife_screwdriver.mdl");
  87.  
  88. //Tridagger
  89. AddFileToDownloadsTable("models/weaponf/v_knife_tridagger_v2.dx90.vtx");
  90. AddFileToDownloadsTable("models/weaponf/v_knife_tridagger_v2.mdl");
  91. AddFileToDownloadsTable("models/weaponf/v_knife_tridagger_v2.vvd");
  92. AddFileToDownloadsTable("materials/models/weaponf/v_models/tridagger/tridagger.vmt");
  93. AddFileToDownloadsTable("materials/models/weaponf/v_models/tridagger/tridagger.vtf");
  94. AddFileToDownloadsTable("materials/models/weaponf/v_models/tridagger/tridagger_exp.vtf");
  95. AddFileToDownloadsTable("materials/models/weaponf/v_models/tridagger/tridagger_normal.vtf");
  96. //Tridagger Steel
  97. AddFileToDownloadsTable("models/weaponf/v_knife_tridagger_steel.dx90.vtx");
  98. AddFileToDownloadsTable("models/weaponf/v_knife_tridagger_steel.mdl");
  99. AddFileToDownloadsTable("models/weaponf/v_knife_tridagger_steel.vvd");
  100. AddFileToDownloadsTable("materials/models/weaponf/v_models/tridagger/steel/tridagger.vmt");
  101. AddFileToDownloadsTable("materials/models/weaponf/v_models/tridagger/steel/tridagger_elite.vtf");
  102. AddFileToDownloadsTable("materials/models/weaponf/v_models/tridagger/steel/tridagger_exp.vtf");
  103. AddFileToDownloadsTable("materials/models/weaponf/v_models/tridagger/steel/tridagger_elite_normal.vtf");
  104. //Black Dagger
  105. AddFileToDownloadsTable("models/weaponf/v_knife_reaper.dx90.vtx");
  106. AddFileToDownloadsTable("models/weaponf/v_knife_reaper.mdl");
  107. AddFileToDownloadsTable("models/weaponf/v_knife_reaper.vvd");
  108. AddFileToDownloadsTable("materials/models/weaponf/v_models/dtb_dagger/dtb.vmt");
  109. AddFileToDownloadsTable("materials/models/weaponf/v_models/dtb_dagger/dtb.vtf");
  110. AddFileToDownloadsTable("materials/models/weaponf/v_models/dtb_dagger/dtb_exp.vtf");
  111. AddFileToDownloadsTable("materials/models/weaponf/v_models/dtb_dagger/dtb_normal.vtf");
  112. //Kabar
  113. AddFileToDownloadsTable("models/weaponf/v_knife_kabar_v2.dx90.vtx");
  114. AddFileToDownloadsTable("models/weaponf/v_knife_kabar_v2.mdl");
  115. AddFileToDownloadsTable("models/weaponf/v_knife_kabar_v2.vvd");
  116. AddFileToDownloadsTable("materials/models/weaponf/kabar/KABAR.vmt");
  117. AddFileToDownloadsTable("materials/models/weaponf/kabar/kabar.vtf");
  118. AddFileToDownloadsTable("materials/models/weaponf/kabar/kabar_G.vtf");
  119. AddFileToDownloadsTable("materials/models/weaponf/kabar/kabar_n.vtf");
  120. //1.6 Knife
  121. AddFileToDownloadsTable("materials/models/weaponf/v_models/knife_ct/bowieknife.vmt");
  122. AddFileToDownloadsTable("materials/models/weaponf/v_models/knife_ct/knife.vtf");
  123. AddFileToDownloadsTable("materials/models/weaponf/v_models/knife_ct/knife_env.vtf");
  124. AddFileToDownloadsTable("materials/models/weaponf/v_models/knife_ct/knife_normal.vtf");
  125. AddFileToDownloadsTable("models/weaponf/crashz.dx80.vtx");
  126. AddFileToDownloadsTable("models/weaponf/crashz.dx90.vtx");
  127. AddFileToDownloadsTable("models/weaponf/crashz.mdl");
  128. AddFileToDownloadsTable("models/weaponf/crashz.sw.vtx");
  129. AddFileToDownloadsTable("models/weaponf/crashz.vvd");
  130. //Ultimate Knife
  131. AddFileToDownloadsTable("materials/models/weaponf/ultimate/texture_1.vmt");
  132. AddFileToDownloadsTable("materials/models/weaponf/ultimate/texture_1.vtf");
  133. AddFileToDownloadsTable("materials/models/weaponf/ultimate/texture_2.vmt");
  134. AddFileToDownloadsTable("materials/models/weaponf/ultimate/texture_2.vtf");
  135. AddFileToDownloadsTable("materials/models/weaponf/ultimate/texture_3.vmt");
  136. AddFileToDownloadsTable("materials/models/weaponf/ultimate/texture_3.vtf");
  137. AddFileToDownloadsTable("materials/models/weaponf/ultimate/texture_4.vmt");
  138. AddFileToDownloadsTable("materials/models/weaponf/ultimate/texture_4.vtf");
  139. AddFileToDownloadsTable("materials/models/weaponf/ultimate/texture_5.vmt");
  140. AddFileToDownloadsTable("materials/models/weaponf/ultimate/texture_5.vtf");
  141. AddFileToDownloadsTable("materials/models/weaponf/ultimate/texture_6.vmt");
  142. AddFileToDownloadsTable("materials/models/weaponf/ultimate/texture_6.vtf");
  143. AddFileToDownloadsTable("materials/models/weaponf/ultimate/texture_7.vmt");
  144. AddFileToDownloadsTable("materials/models/weaponf/ultimate/texture_7.vtf");
  145. AddFileToDownloadsTable("models/weaponf/v_knife_ultimate.dx90.vtx");
  146. AddFileToDownloadsTable("models/weaponf/v_knife_ultimate.mdl");
  147. AddFileToDownloadsTable("models/weaponf/v_knife_ultimate.vvd");
  148.  
  149. AddFileToDownloadsTable("models/weapons/v_gongfu.mdl");
  150. AddFileToDownloadsTable("models/weapons/v_gongfu.dx90.vtx");
  151. AddFileToDownloadsTable("models/weapons/v_gongfu.vvd");
  152.  
  153. AddFileToDownloadsTable("materials/models/weapons/gongfu/v_models/knife_t/tm_leet_lowerbody_variantb.vmt");
  154. AddFileToDownloadsTable("materials/models/weapons/gongfu/v_models/knife_t/tm_leet_lowerbody_variantb.vtf");
  155. AddFileToDownloadsTable("materials/models/weapons/gongfu/v_models/knife_t/tm_leet_lowerbody_variantb_exponent.vtf");
  156. AddFileToDownloadsTable("materials/models/weapons/gongfu/v_models/knife_t/tm_leet_lowerbody_variantb_normal.vtf");
  157.  
  158. AddFileToDownloadsTable("models/weapons/caleon1/screwdriver/v_knife_screwdriver.dx90.vtx");
  159. AddFileToDownloadsTable("models/weapons/caleon1/screwdriver/v_knife_screwdriver.mdl");
  160. AddFileToDownloadsTable("models/weapons/caleon1/screwdriver/v_knife_screwdriver.vvd");
  161.  
  162. AddFileToDownloadsTable("materials/models/weapons/caleon1/screwdriver/yellow.vtf");
  163. AddFileToDownloadsTable("materials/models/weapons/caleon1/screwdriver/black.vmt");
  164. AddFileToDownloadsTable("materials/models/weapons/caleon1/screwdriver/black.vtf");
  165. AddFileToDownloadsTable("materials/models/weapons/caleon1/screwdriver/metal.vmt");
  166. AddFileToDownloadsTable("materials/models/weapons/caleon1/screwdriver/metal.vtf");
  167. AddFileToDownloadsTable("materials/models/weapons/caleon1/screwdriver/yellow.vmt");
  168. }
  169.  
  170. public Action Cmd_sm_customknife(int client, int args)
  171. {
  172. if (client == 0)
  173. {
  174. ReplyToCommand(client, "%t", "Parancs csak játékba használhato");
  175. return Plugin_Handled;
  176. }
  177. ShowKnifeMenu(client);
  178. return Plugin_Handled;
  179. }
  180.  
  181. void ShowKnifeMenu(int client)
  182. {
  183. Menu menu_knives = new Menu(mh_KnifeHandler);
  184. SetMenuTitle(menu_knives, "Select Knife");
  185.  
  186. AddMenuItem(menu_knives, "default", "Alap kés");
  187. AddMenuItem(menu_knives, "tridagger", "Tri-Dagger Black");
  188. AddMenuItem(menu_knives, "tridagger_steel", "Tri-Dagger Steel");
  189. AddMenuItem(menu_knives, "kabar", "Ka-Bar");
  190. AddMenuItem(menu_knives, "reaper", "Reaper Dagger");
  191. AddMenuItem(menu_knives, "css", "1.6/CSS Knife");
  192. AddMenuItem(menu_knives, "ultimate", "Bear Grylls Knife");
  193. AddMenuItem(menu_knives, "ifu", "Gong Fu");
  194. AddMenuItem(menu_knives, "ides", "Screwdriver");
  195. SetMenuPagination(menu_knives, 0);
  196. //SetMenuExitButton(menu_knives, true);
  197. DisplayMenu(menu_knives, client, 0);
  198. }
  199.  
  200. public int mh_KnifeHandler(Menu menu, MenuAction action, int param1, int param2)
  201. {
  202. switch (action)
  203. {
  204. case MenuAction_Select:
  205. {
  206. //param1 is client, param2 is item
  207. if(GetUserAdmin(param1) == INVALID_ADMIN_ID)
  208. {
  209. if(g_time > 0 && timers == INVALID_HANDLE)
  210. {
  211.  
  212. CPrintToChat(param1, "[{GREEN}Custom Knives{DEFAULT}] A plugint csak az első %i masodpercbe használhatod", g_time);
  213. return;
  214. }
  215.  
  216. char steamid[64];
  217. int times;
  218. GetClientAuthId(param1, AuthId_Steam2, steamid, sizeof(steamid));
  219.  
  220. if(!GetTrieValue(trie_times, steamid, times))
  221. {
  222. times = 0;
  223. }
  224.  
  225. if(g_veces > 0 && times >= g_veces)
  226. {
  227. CPrintToChat(param1, "[{GREEN}Custom Knives{DEFAULT}] A plugint csak %i használhatod a mapon", g_veces);
  228. return;
  229. }
  230. ++times;
  231.  
  232. SetTrieValue(trie_times, steamid, times);
  233. }
  234.  
  235. char item[64];
  236. GetMenuItem(menu, param2, item, sizeof(item));
  237.  
  238. SetKnife(param1, item);
  239.  
  240. }
  241. case MenuAction_End:
  242. {
  243. //param1 is MenuEnd reason, if canceled param2 is MenuCancel reason
  244. CloseHandle(menu);
  245.  
  246. }
  247.  
  248. }
  249. }
  250.  
  251. void SetKnife(int param1, char[] item)
  252. {
  253. char item2[16];
  254. if (StrEqual(item, "default"))
  255. {
  256. FPVMI_RemoveViewModelToClient(param1, "weapon_knife");
  257. KnifeSelection[param1] = 0;
  258. IntToString(KnifeSelection[param1], item2, sizeof(item2));
  259. SetClientCookie(param1, g_hMySelection, item2);
  260. }
  261. else if (StrEqual(item, "tridagger"))
  262. {
  263. KnifeSelection[param1] = 1;
  264. FPVMI_AddViewModelToClient(param1, "weapon_knife", iTridaggerModel);
  265. IntToString(KnifeSelection[param1], item2, sizeof(item2));
  266. SetClientCookie(param1, g_hMySelection, item2);
  267. }
  268. else if (StrEqual(item, "tridagger_steel"))
  269. {
  270. KnifeSelection[param1] = 2;
  271. FPVMI_AddViewModelToClient(param1, "weapon_knife", iTridaggerSteelModel);
  272. IntToString(KnifeSelection[param1], item2, sizeof(item2));
  273. SetClientCookie(param1, g_hMySelection, item2);
  274. }
  275. else if (StrEqual(item, "kabar"))
  276. {
  277. KnifeSelection[param1] = 3;
  278. FPVMI_AddViewModelToClient(param1, "weapon_knife", iKabar);
  279. IntToString(KnifeSelection[param1], item2, sizeof(item2));
  280. SetClientCookie(param1, g_hMySelection, item2);
  281. }
  282. else if (StrEqual(item, "reaper"))
  283. {
  284. KnifeSelection[param1] = 4;
  285. FPVMI_AddViewModelToClient(param1, "weapon_knife", iBlackDagger);
  286. IntToString(KnifeSelection[param1], item2, sizeof(item2));
  287. SetClientCookie(param1, g_hMySelection, item2);
  288. }
  289. else if (StrEqual(item, "css"))
  290. {
  291. KnifeSelection[param1] = 5;
  292. FPVMI_AddViewModelToClient(param1, "weapon_knife", iOldKnife);
  293. IntToString(KnifeSelection[param1], item2, sizeof(item2));
  294. SetClientCookie(param1, g_hMySelection, item2);
  295. }
  296. else if (StrEqual(item, "ultimate"))
  297. {
  298. KnifeSelection[param1] = 6;
  299. FPVMI_AddViewModelToClient(param1, "weapon_knife", iUltimateKnife);
  300. IntToString(KnifeSelection[param1], item2, sizeof(item2));
  301. SetClientCookie(param1, g_hMySelection, item2);
  302. }
  303. else if (StrEqual(item, "ifu"))
  304. {
  305. KnifeSelection[param1] = 7;
  306. FPVMI_AddViewModelToClient(param1, "weapon_knife", ifu);
  307. IntToString(KnifeSelection[param1], item2, sizeof(item2));
  308. SetClientCookie(param1, g_hMySelection, item2);
  309. }
  310. else if (StrEqual(item, "ides"))
  311. {
  312. KnifeSelection[param1] = 8;
  313. FPVMI_AddViewModelToClient(param1, "weapon_knife", ides);
  314. IntToString(KnifeSelection[param1], item2, sizeof(item2));
  315. SetClientCookie(param1, g_hMySelection, item2);
  316. }
  317. }
  318.  
  319.  
  320.  
  321. public void OnClientCookiesCached(int client)
  322. {
  323. char sCookieValue[11];
  324. GetClientCookie(client, g_hMySelection, sCookieValue, sizeof(sCookieValue));
  325. KnifeSelection[client] = StringToInt(sCookieValue);
  326. char sCookieValue2[11];
  327. GetClientCookie(client, g_hMyFirstJoin, sCookieValue2, sizeof(sCookieValue2));
  328. showMenu[client] = StringToInt(sCookieValue2);
  329. }
  330.  
  331. public void OnClientPostAdminCheck(int client)
  332. {
  333. if(AreClientCookiesCached(client)) SetKnife_saved(client);
  334. }
  335.  
  336. void SetKnife_saved(int param1)
  337. {
  338. switch (KnifeSelection[param1])
  339. {
  340. case 1:
  341. {
  342. FPVMI_AddViewModelToClient(param1, "weapon_knife", iTridaggerModel);
  343. }
  344. case 2:
  345. {
  346. FPVMI_AddViewModelToClient(param1, "weapon_knife", iTridaggerSteelModel);
  347. }
  348. case 3:
  349. {
  350. FPVMI_AddViewModelToClient(param1, "weapon_knife", iKabar);
  351. }
  352. case 4:
  353. {
  354. FPVMI_AddViewModelToClient(param1, "weapon_knife", iBlackDagger);
  355. }
  356. case 5:
  357. {
  358. FPVMI_AddViewModelToClient(param1, "weapon_knife", iOldKnife);
  359. }
  360. case 6:
  361. {
  362. FPVMI_AddViewModelToClient(param1, "weapon_knife", iUltimateKnife);
  363. }
  364. case 7:
  365. {
  366. FPVMI_AddViewModelToClient(param1, "weapon_knife", ifu);
  367. }
  368. case 8:
  369. {
  370. FPVMI_AddViewModelToClient(param1, "weapon_knife", ides);
  371. }
  372. default:
  373. {
  374. // Blah
  375. }
  376. }
  377. }
  378.  
  379. public Action Event_Start(Event gEventHook, const char[] gEventName, bool iDontBroadcast)
  380. {
  381. if(timers != INVALID_HANDLE) KillTimer(timers);
  382. timers = CreateTimer(GetConVarInt(cvar_time) * 1.0, Passed);
  383.  
  384. }
  385.  
  386. public Action Passed(Handle timer)
  387. {
  388. timers = INVALID_HANDLE;
  389. }
  390.  
  391. public Action Event_Spawn(Event gEventHook, const char[] gEventName, bool iDontBroadcast)
  392. {
  393. int iClient = GetClientOfUserId(GetEventInt(gEventHook, "userid"));
  394.  
  395. if (AreClientCookiesCached(iClient))
  396. {
  397. if (showMenu[iClient] == 0)
  398. {
  399. showMenu[iClient] = 1;
  400. ShowKnifeMenu(iClient);
  401. SetClientCookie(iClient, g_hMyFirstJoin, "1");
  402. }
  403. }
  404. }
  405.  
  406. stock bool IsValidClient(int client, bool nobots = true)
  407. {
  408. if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client)))
  409. {
  410. return false;
  411. }
  412. return IsClientInGame(client);
  413. }