Advertisement
Guest User

Untitled

a guest
May 25th, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.40 KB | None | 0 0
  1. new defaultValuesCT[_:WeaponID];
  2. new defaultValuesT[_:WeaponID];
  3. new WeaponID:currentID = WEAPON_NONE;
  4. new bool:bIsFirstKey = true;
  5. new iLastVal = -1;
  6. new iLastIndex = 0;
  7. new perPlayer[_:WeaponID][MAXPLAYERS+1];
  8. new bool:g_bPerPlayerReady = false;
  9. PerPlayerInit()
  10. {
  11.     for(new i = 0; i < _:WeaponID; i++)
  12.     {
  13.         for(new x = 0; x <= MAXPLAYERS; x++)
  14.         {
  15.             perPlayer[i][x] = -2;
  16.         }
  17.     }
  18.     for(new i = 1; i < _:WeaponID; i++)
  19.     {
  20.         if(WeaponID:i == WEAPON_SHIELD)
  21.             continue;
  22.            
  23.         if(WeaponID:i != WEAPON_DEFUSER)
  24.         {
  25.             defaultValuesT[i] = Restrict_GetRestrictValue(CS_TEAM_T, WeaponID:i);
  26.         }
  27.         if(WeaponID:i != WEAPON_C4)
  28.         {
  29.             defaultValuesCT[i] = Restrict_GetRestrictValue(CS_TEAM_CT, WeaponID:i);
  30.         }
  31.     }
  32.     new String:file[PLATFORM_MAX_PATH];
  33.     BuildPath(Path_SM, file, sizeof(file), "configs/restrict/perplayerrestrict.txt", file);
  34.     if(!FileExists(file))
  35.     {
  36.         LogError("Failed to locate '%s'", file);
  37.         return;
  38.     }
  39.     new Handle:parser = SMC_CreateParser();
  40.     new line = 0;
  41.     new col = 0;
  42.    
  43.     SMC_SetReaders(parser, Perplayer_NewSection, Perplayer_KeyValue, Perplayer_EndSection);
  44.     SMC_SetParseEnd(parser, Perplayer_ParseEnd);
  45.    
  46.     new SMCError:error = SMC_ParseFile(parser, file, line, col);
  47.     CloseHandle(parser);
  48.     if(error)
  49.     {
  50.         new String:errorString[128];
  51.         SMC_GetErrorString(error, errorString, sizeof(errorString));
  52.         LogError("Perplayer parser error on line %i col %i. Error: %s", line, col, errorString);
  53.         return;
  54.     }
  55.     g_bPerPlayerReady = true;
  56.     #if defined DEBUG
  57.     Perplayer_Debug(0);
  58.     #endif
  59. }
  60. public Action:Perplayer_Debug(args)
  61. {
  62.     new last;
  63.     new lastval;
  64.     for(new i = 0; i < _:WeaponID; i++)
  65.     {
  66.         if(perPlayer[i][0] == -2)
  67.             continue;
  68.         else
  69.         {
  70.             last = 0;
  71.             lastval = perPlayer[i][0];
  72.             for(new x = 1; x <= MAXPLAYERS; x++)
  73.             {
  74.                 if(lastval != perPlayer[i][x])
  75.                 {
  76.                     PrintToServer("Between %i and %i %s will be restricted to %i", last, x-1, weaponNames[WeaponID:i], lastval);
  77.                     lastval = perPlayer[i][x];
  78.                     last = x;
  79.                 }
  80.                 if(x == MAXPLAYERS)
  81.                 {
  82.                     PrintToServer("Between %i and %i %s will be restricted to %i", last, MAXPLAYERS, weaponNames[WeaponID:i], lastval);
  83.                 }
  84.             }
  85.         }
  86.     }
  87.     return Plugin_Handled;
  88. }
  89. public SMCResult:Perplayer_NewSection(Handle:parser, const String:section[], bool:quotes)
  90. {
  91.     if(StrEqual(section, "PerPlayer", false))
  92.     {
  93.         return SMCParse_Continue;
  94.     }
  95.     new WeaponID:id = Restrict_GetWeaponIDExtended(section);
  96.     if(IsValidWeaponID(id))
  97.     {
  98.         currentID = id;
  99.         bIsFirstKey = true;
  100.         iLastIndex = 0;
  101.     }
  102.     else
  103.     {
  104.         LogError("Invalid section name found in perplayer.txt");
  105.         return SMCParse_HaltFail;
  106.     }
  107.     return SMCParse_Continue;
  108. }
  109. public SMCResult:Perplayer_KeyValue(Handle:parser, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes)
  110. {
  111.     if(bIsFirstKey)
  112.     {
  113.         if(StrEqual(key, "default", false))
  114.         {
  115.             bIsFirstKey = false;
  116.             iLastVal = StringToInt(value);
  117.             if(iLastVal < -1)
  118.                 iLastVal = -1;
  119.         }
  120.         else
  121.         {
  122.             return SMCParse_HaltFail;
  123.         }
  124.     }
  125.     else
  126.     {
  127.         new index = StringToInt(key);
  128.         for(new i = iLastIndex; i < index; i++)
  129.         {
  130.             perPlayer[currentID][i] = iLastVal;
  131.         }
  132.         iLastIndex = index;
  133.         iLastVal = StringToInt(value);
  134.         if(iLastVal < -1)
  135.             iLastVal = -1;
  136.     }
  137.     return SMCParse_Continue;
  138. }
  139. public SMCResult:Perplayer_EndSection(Handle:parser)
  140. {
  141.     for(new i = iLastIndex; i <= MAXPLAYERS; i++)
  142.     {
  143.         perPlayer[currentID][i] = iLastVal;
  144.     }
  145.     currentID = WEAPON_NONE;
  146.     return SMCParse_Continue;
  147. }
  148. public Perplayer_ParseEnd(Handle:parser, bool:halted, bool:failed)
  149. {
  150.     if(failed)
  151.     {
  152.         LogError("Failed to parse Perplayer fully");
  153.     }
  154. }
  155. CheckPerPlayer()
  156. {
  157.     if(!g_bPerPlayerReady)
  158.         return;
  159.     if(GetConVarBool(PerPlayerRestrict))
  160.     {
  161.         new count = GetPlayerCount();
  162.         for(new i = 1; i < _:WeaponID; i++)
  163.         {
  164.             if(WeaponID:i == WEAPON_SHIELD)
  165.                 continue;
  166.            
  167.             if(WeaponID:i != WEAPON_DEFUSER)
  168.             {
  169.                 if(perPlayer[i][0] != -2 && Restrict_GetRestrictValue(CS_TEAM_T, WeaponID:i) != perPlayer[i][count] && !Restrict_IsWeaponInOverride(CS_TEAM_T, WeaponID:i))
  170.                 {
  171.                     Restrict_SetRestriction(WeaponID:i, CS_TEAM_T, perPlayer[i][count], false);
  172.                 }
  173.             }
  174.             if(WeaponID:i != WEAPON_C4)
  175.             {
  176.                 if(perPlayer[i][0] != -2 && Restrict_GetRestrictValue(CS_TEAM_CT, WeaponID:i) != perPlayer[i][count] && !Restrict_IsWeaponInOverride(CS_TEAM_CT, WeaponID:i))
  177.                 {
  178.                     Restrict_SetRestriction(WeaponID:i, CS_TEAM_CT, perPlayer[i][count], false);
  179.                 }
  180.             }
  181.         }
  182.     }
  183.     else
  184.     {
  185.         for(new i = 1; i < _:WeaponID; i++)
  186.         {
  187.             if(WeaponID:i == WEAPON_SHIELD)
  188.                 continue;
  189.            
  190.             if(WeaponID:i != WEAPON_DEFUSER)
  191.             {
  192.                 if(Restrict_GetRestrictValue(CS_TEAM_T, WeaponID:i) != defaultValuesT[i] && !Restrict_IsWeaponInOverride(CS_TEAM_T, WeaponID:i))
  193.                 {
  194.                     Restrict_SetRestriction(WeaponID:i, CS_TEAM_T, defaultValuesT[i], false);
  195.                 }
  196.             }
  197.             if(WeaponID:i != WEAPON_C4)
  198.             {
  199.                 if(Restrict_GetRestrictValue(CS_TEAM_CT, WeaponID:i) != defaultValuesCT[i] && !Restrict_IsWeaponInOverride(CS_TEAM_CT, WeaponID:i))
  200.                 {
  201.                     Restrict_SetRestriction(WeaponID:i, CS_TEAM_CT, defaultValuesCT[i], false);
  202.                 }
  203.             }
  204.         }
  205.     }
  206. }
  207. GetPlayerCount()
  208. {
  209.     new count = 0;
  210.     for(new i = 1; i <= MaxClients; i++)
  211.     {
  212.         if(!IsClientInGame(i) || (!GetConVarBool(PerPlayerBots) && IsFakeClient(i)) || (!GetConVarBool(PerPlayerSpecs) && (GetClientTeam(i) == CS_TEAM_NONE || GetClientTeam(i) == CS_TEAM_SPECTATOR)))
  213.             continue;
  214.        
  215.         count++;
  216.     }
  217.     return count;
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement