Advertisement
Diskretor

Untitled

Oct 10th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.62 KB | None | 0 0
  1. #define PLUGIN_VERSION "0.1"
  2.  
  3. /*=======================================================================================
  4. Plugin Info:
  5.  
  6. * Name : [L4D] PaSSifiC - Particles and Sound Sequence Interactive Constructor
  7. * Author : Alex Dragokas
  8. * Descr. : Creates in-game set of effects and sounds to use by another plugins
  9. * Link :
  10.  
  11. ========================================================================================
  12. Change Log:
  13.  
  14.  
  15.  
  16. 0.1 (xx-Oct-2018)
  17. - First commit
  18.  
  19. ========================================================================================
  20. Description:
  21.  
  22. // TODO
  23.  
  24. Commands:
  25. 1. "" - ...
  26.  
  27.  
  28. Settings (ConVars):
  29. 1. "" - ...
  30.  
  31. Using:
  32. ...
  33.  
  34. ======================================================================================*/
  35.  
  36. #pragma semicolon 1
  37. #pragma newdecls required
  38.  
  39. #include <sourcemod>
  40. #include <sdktools>
  41.  
  42.  
  43. public Plugin myinfo =
  44. {
  45. name = "PaSSifiC",
  46. author = "Alex Dragokas",
  47. description = "Creates in-game set of effects and sounds to use by another plugins",
  48. version = PLUGIN_VERSION,
  49. url = "https://github.com/dragokas/"
  50. };
  51.  
  52. KeyValues kv;
  53. char g_sCurParticleGrp[60][MAXPLAYERS+1];
  54.  
  55. public void OnPluginStart()
  56. {
  57. //LoadTranslations("passific.phrases");
  58.  
  59. CreateConVar("passific_version", PLUGIN_VERSION, "PaSSifiC Version", FCVAR_SPONLY | FCVAR_NOTIFY | FCVAR_REPLICATED);
  60.  
  61. RegConsoleCmd("sm_passific_load", Command_LoadConfigs, "Reload configs.");
  62. RegConsoleCmd("sm_passific", Command_MenuMain, "Show passific main menu");
  63.  
  64. Command_LoadConfigs(0, 0);
  65. }
  66.  
  67. public Action Command_LoadConfigs(int client, int args)
  68. {
  69. char ParticlesPath[PLATFORM_MAX_PATH];
  70. BuildPath(Path_SM, ParticlesPath, PLATFORM_MAX_PATH, "data/sm_passific_particles.txt");
  71.  
  72. if (!FileExists(ParticlesPath))
  73. SetFailState("[SM] ERROR: Passific - Missing file, '%s'", ParticlesPath);
  74.  
  75. kv = CreateKeyValues("particles");
  76. if (!FileToKeyValues(kv, ParticlesPath))
  77. SetFailState("[SM] ERROR: Passific - Incorrectly formatted file, '%s'", ParticlesPath);
  78.  
  79. if (!kv.GotoFirstSubKey())
  80. SetFailState("[SM] ERROR: Passific - Config file is empty, '%s'", ParticlesPath);
  81. }
  82.  
  83. /* ------------------------
  84. // "Main Menu"
  85. ---------------------------*/
  86.  
  87. Action Command_MenuMain(int client, int args)
  88. {
  89. if (!IsClientAdmin(client))
  90. {
  91. PrintToChat(client, "You are not allowed to use this feature!");
  92. return Plugin_Handled;
  93. }
  94.  
  95. Menu menu = CreateMenu(MenuHandler_MenuMain, MENU_ACTIONS_DEFAULT);
  96. menu.SetTitle("Select particle action");
  97. menu.AddItem("1", "Choose in list");
  98. menu.AddItem("2", "Next");
  99. menu.AddItem("3", "Repeat");
  100. menu.AddItem("4", "Edit");
  101. menu.AddItem("5", "Add to sequence");
  102. menu.Display(client, MENU_TIME_FOREVER);
  103. return Plugin_Handled;
  104. }
  105.  
  106. public int MenuHandler_MenuMain(Menu menu, MenuAction action, int param1, int param2)
  107. {
  108. switch (action)
  109. {
  110. case MenuAction_End:
  111. delete menu;
  112.  
  113. case MenuAction_Select:
  114. {
  115. int client = param1;
  116. int ItemIndex = param2;
  117.  
  118. char nAction[5];
  119. int iAction;
  120. menu.GetItem(ItemIndex, nAction, sizeof(nAction));
  121. iAction = StringToInt(nAction);
  122.  
  123. switch(iAction) {
  124. case 1: {
  125. Command_Particle_Grp_Choose(client);
  126. }
  127. }
  128. }
  129. }
  130. }
  131.  
  132. void Command_Particle_Grp_Choose(int client)
  133. {
  134. Menu menu = CreateMenu(MenuHandler_Particle_Grp_Choose, MENU_ACTIONS_DEFAULT);
  135.  
  136. menu.SetTitle("Particles: Choose the group");
  137.  
  138. kv.Rewind();
  139. kv.GotoFirstSubKey();
  140.  
  141. char sParticleGrp[40];
  142.  
  143. do
  144. {
  145. kv.GetSectionName(sParticleGrp, sizeof(sParticleGrp));
  146. menu.AddItem(sParticleGrp, sParticleGrp);
  147.  
  148. } while (kv.GotoNextKey());
  149.  
  150. menu.ExitBackButton = true;
  151. menu.Display(client, MENU_TIME_FOREVER);
  152. }
  153.  
  154. public int MenuHandler_Particle_Grp_Choose(Menu menu, MenuAction action, int param1, int param2)
  155. {
  156. switch (action)
  157. {
  158. case MenuAction_End:
  159. delete menu;
  160.  
  161. case MenuAction_Cancel:
  162. if (param2 == MenuCancel_ExitBack)
  163. Command_MenuMain(param1, 0);
  164.  
  165. case MenuAction_Select:
  166. {
  167. int client = param1;
  168. int ItemIndex = param2;
  169.  
  170. char sParticleGrp[40];
  171. menu.GetItem(ItemIndex, sParticleGrp, sizeof(sParticleGrp));
  172.  
  173. PrintToChat(client, "\x03[Passific] Chosen group: \x05%s", sParticleGrp);
  174.  
  175. CreateMenu_ParticleChoose(client, sParticleGrp);
  176. }
  177. }
  178. }
  179.  
  180. void CreateMenu_ParticleChoose(int client, char[] sParticleGrp, int StartItem = 0)
  181. {
  182. Menu menu = CreateMenu(MenuHandler_ParticleChoose, MENU_ACTIONS_DEFAULT);
  183.  
  184. menu.SetTitle("Choose effect");
  185. kv.Rewind();
  186.  
  187. if (kv.JumpToKey(sParticleGrp))
  188. {
  189. strcopy(g_sCurParticleGrp[client], sizeof(g_sCurParticleGrp[]), sParticleGrp);
  190.  
  191. int iTotal = kv.GetNum("Total", 0);
  192.  
  193. char sParticleName[60], s_Idx[5];
  194.  
  195. for (int i = 1; i <= iTotal; i++)
  196. {
  197. IntToString(i, s_Idx, sizeof(s_Idx));
  198. kv.JumpToKey(s_Idx);
  199. kv.GetString("name", sParticleName, sizeof(sParticleName), "error");
  200. kv.GoBack();
  201.  
  202. if (!StrEqual(sParticleName, "error"))
  203. menu.AddItem(sParticleName, sParticleName);
  204. }
  205.  
  206. menu.ExitBackButton = true;
  207. menu.DisplayAt(client, StartItem, MENU_TIME_FOREVER);
  208. }
  209. }
  210.  
  211. public int MenuHandler_ParticleChoose(Menu menu, MenuAction action, int param1, int param2)
  212. {
  213. switch (action)
  214. {
  215. case MenuAction_End:
  216. delete menu;
  217.  
  218. case MenuAction_Cancel:
  219. if (param2 == MenuCancel_ExitBack)
  220. Command_Particle_Grp_Choose(param1);
  221.  
  222. case MenuAction_Select:
  223. {
  224. int client = param1;
  225. int ItemIndex = param2;
  226.  
  227. char sParticle[40];
  228. menu.GetItem(ItemIndex, sParticle, sizeof(sParticle));
  229.  
  230. PrintToChat(client, "\x03[Passific] Chosen particle: \x05%s", sParticle);
  231.  
  232. SpawnEffect(client, sParticle);
  233.  
  234. CreateMenu_ParticleChoose(client, g_sCurParticleGrp[client], menu.Selection );
  235. }
  236. }
  237. }
  238.  
  239. void SpawnEffect(int client, char[] sParticleName)
  240. {
  241. float pos[3];
  242. // GetClientAbsOrigin(client, pos);
  243. GetClientEyePosition(client, pos);
  244. int iEntity = CreateEntityByName("info_particle_system", -1);
  245. if (iEntity != -1)
  246. {
  247. PrintToChat(client, "\x03[Passific] Spawning effect on: \x05%N", client);
  248.  
  249. DispatchKeyValue(iEntity, "effect_name", sParticleName);
  250. DispatchKeyValueVector(iEntity, "origin", pos);
  251. DispatchSpawn(iEntity);
  252. SetVariantString("!activator");
  253. AcceptEntityInput(iEntity, "SetParent", client);
  254. ActivateEntity(iEntity);
  255. AcceptEntityInput(iEntity, "Start");
  256. SetVariantString("OnUser1 !self:kill::1.5:1");
  257. AcceptEntityInput(iEntity, "AddOutput");
  258. AcceptEntityInput(iEntity, "FireUser1");
  259. }
  260. }
  261.  
  262. bool IsClientAdmin(int client)
  263. {
  264. if (!IsClientInGame(client)) return false;
  265. return GetUserAdmin(client) != INVALID_ADMIN_ID;
  266. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement