milutinke

SCL Test plugin

Jun 3rd, 2021
762
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <sourcemod>
  2. #include <scl_conext>
  3. #include <cstrike>
  4.  
  5. #pragma semicolon 1
  6. #pragma newdecls required
  7.  
  8. public Plugin myinfo =
  9. {
  10.     name = "Test SCL",
  11.     author = "milutinke",
  12.     description = "Test SCL",
  13.     version = "1.0.0",
  14.     url = ""
  15. };
  16.  
  17. forward void Scl_Parsed(char[] szContext, char[] szFunctionName, any aParameters, int iPlayer);
  18. native int Scl_Parse(char[] szContext, char[] szCode, int iPlayer);
  19. native int Scl_Validate_Parameter_Type_N(char[] szContext, char[] szFunction, any aParameters, int iParameter, int iType);
  20.  
  21. #define SCL_PARSED_START(%0) public void Scl_Parsed(char[] szContext, char[] szFunctionName, any anyParameters, int iPlayer) {\
  22. ArrayList aParameters = view_as<ArrayList>(anyParameters); \
  23. \
  24. if (! % 0.IsValid)\
  25.     return; \
  26. if (! % 0.Equal(szContext))\
  27.     return;
  28.  
  29. #define SCL_PARSED_END() }
  30.  
  31. Scl_Context g_scContext;
  32.  
  33. public void OnAllPluginsLoaded() {
  34.     Handle hDynamicsPluginHandle = INVALID_HANDLE;
  35.     if ((hDynamicsPluginHandle = FindPluginByFile("dynamic.smx")) != INVALID_HANDLE) {
  36.         if (GetPluginStatus(hDynamicsPluginHandle) != Plugin_Running) {
  37.             ThrowError("This plugin requires dynamic.smx to be loaded!");
  38.             return;
  39.         }
  40.     } else {
  41.         ThrowError("This plugin requires dynamic.smx to exists on the server! Download it from: https://forums.alliedmods.net/showthread.php?t=270519");
  42.         return;
  43.     }
  44.    
  45.     if (!ObtainContext("Test Context").IsValid) {
  46.         PrintToServer("Invalid Context in TestSCL");
  47.         return;
  48.     }
  49.    
  50.     Execute("Test:Functions(abc,123,more:strings,1,@Getter(1,2,3,@Nested))):ThirdFunction(1,2,3)");
  51. }
  52.  
  53. public void Scl_Parsed(char[] szContext, char[] szFunctionName, any anyParameters, int iPlayer) {
  54.     PrintToServer("============================================================");
  55.     PrintToServer("             SCL Parsed                                     ");
  56.     PrintToServer("============================================================");
  57.     PrintToServer("Context: %s", szContext);
  58.     PrintToServer("Function: %s", szFunctionName);
  59.     PrintToServer("Player: %d", iPlayer);
  60.     PrintToServer("Parameters:");
  61.    
  62.     if (!g_scContext.IsValidContext) {
  63.         PrintToServer("INVALID CONTEXT");
  64.         PrintToServer("============================================================");
  65.         return;
  66.     }
  67.     ArrayList aParameters = view_as<ArrayList>(anyParameters);
  68.    
  69.     if (aParameters == INVALID_HANDLE) {
  70.         PrintToServer("INVALID ARRAY LIST HANDLE");
  71.         PrintToServer("============================================================");
  72.         return;
  73.     }
  74.    
  75.     char[] szParam = new char[g_scContext.ParameterMaxLength];
  76.     for (int i = 0; i < aParameters.Length; i++) {
  77.         aParameters.GetString(i, szParam, g_scContext.ParameterMaxLength);
  78.         PrintToServer("#%d - %s", i, szParam);
  79.     }
  80.     PrintToServer("============================================================");
  81.    
  82.     if (!g_scContext.IsValid) {
  83.         PrintToServer(">>>>>>>>>>>>>> INVALID CONTEXT");
  84.         return;
  85.     }
  86.    
  87.     if (!g_scContext.Equal(szContext)) {
  88.         char szCtx[128];
  89.         g_scContext.GetContextName(szCtx, sizeof(szCtx));
  90.        
  91.         PrintToServer(">>>>>>>>>>>>>> DIFFERENT CONTEXT - %s - %s - %d", szContext, szCtx, g_scContext.Equal(szContext) ? 1 : 0);
  92.         return;
  93.     }
  94.    
  95.     if (StrEqual(szFunctionName, "Functions")) {
  96.         if (!Scl_Validate_Parameter_Type(szContext, szFunctionName, aParameters, 2, Scl_Type_String)) {
  97.             PrintToServer(">>>>>>>>>>>>>> INVALID TYPE");
  98.             return;
  99.         }
  100.        
  101.         char[] szParameterValue = new char[g_scContext.ParameterMaxLength];
  102.         aParameters.GetString(2, szParameterValue, g_scContext.ParameterMaxLength);
  103.        
  104.         PrintToServer(">>>>>>>>>>>>>> Yay, works!");
  105.        
  106.         Execute(szParameterValue);
  107.         return;
  108.     }
  109. }
  110.  
  111. stock void Execute(char[] szInput) {
  112.     if (!Scl_Parse("Test Context", szInput, 0)) {
  113.         PrintToServer("Failed to execute in SclTest");
  114.         return;
  115.     } else PrintToServer("Parsed...");
  116. }
  117.  
  118. /*#pragma tabsize 0
  119. SCL_PARSED_START(g_scContext)
  120.     if (StrEqual(szFunctionName, "Cvabke")) {
  121.         if (!Scl_Validate_Parameter_Type(szContext, szFunctionName, aParameters, 1, Scl_Type_Integer)) {
  122.             PrintToServer(">>>>>>>>>>>>>> INVALID TYPE");
  123.             return;
  124.         }
  125.                
  126.         PrintToServer(">>>>>>>>>>>>>> Yay, works");
  127.         return;
  128.     }
  129. SCL_PARSED_END()*/
  130.  
  131. public void OnPluginEnd() {
  132.     if (g_scContext.IsValidContext)
  133.         g_scContext.Dispose();
  134. }
  135.  
  136. stock Scl_Context ObtainContext(char[] szName) {
  137.     if (g_scContext.IsValidContext)
  138.         g_scContext.Dispose();
  139.    
  140.     g_scContext = NewContext(szName);
  141.    
  142.     if (!g_scContext.IsValidContext)
  143.         return Scl_Invalid_Context;
  144.    
  145.     return g_scContext;
  146. }
  147.  
  148. stock Scl_Context NewContext(char[] szName) {
  149.     Scl_Context scContext = Scl_Context();
  150.     scContext.SetContextName(szName);
  151.     return scContext;
  152. }
  153.  
  154. stock int Scl_Validate_Parameter_Type(char[] szContext, char[] szFunction, any aParameters, int iParameter, Scl_Types iType) {
  155.     return Scl_Validate_Parameter_Type_N(szContext, szFunction, aParameters, iParameter, view_as<int>(iType));
  156. }
RAW Paste Data