Advertisement
Guest User

Untitled

a guest
May 30th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.92 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3.  
  4. #define PLUGIN_NAME "Speed Meter"
  5. #define PLUGIN_VERSION "1.0.1"
  6. #define PLUGIN_DESCRIPTION "Show current player speed in HUD every 2 sec"
  7. #define PLUGIN_AUTHOR "Petit Renard, Anubis"
  8. #define PLUGIN_URL "http://css.cooldev.net/"
  9.  
  10. new Handle:g_enable = INVALID_HANDLE;
  11. new Handle:g_unit = INVALID_HANDLE;
  12. new Float:lastPosition[MAXPLAYERS + 1][3];
  13. new g_MaxClients;
  14. new Handle:g_timer = INVALID_HANDLE;
  15. new Bool:g_switch = false;
  16.  
  17. /********************
  18. * Plugin Info
  19. *********************/
  20. public Plugin:myinfo = {
  21.     name = PLUGIN_NAME,
  22.     author = PLUGIN_AUTHOR,
  23.     description = PLUGIN_DESCRIPTION,
  24.     version = PLUGIN_VERSION,
  25.     url = PLUGIN_URL
  26. };
  27.  
  28. /********************
  29. * Start of Plugin
  30. *********************/
  31. public OnPluginStart (){
  32.     LoadTranslations ("speedmeter.phrases");
  33.    
  34.     g_enable = CreateConVar ("speedmeter_enable", "1", "Enable SpeedMeter ? (1 = yes, 0 = no)", FCVAR_PLUGIN, true, 0.0, true, 1.0);
  35.     g_unit = CreateConVar ("speedmeter_unit", "0", "Unit of length (0 = kilometres, 1 = miles)", FCVAR_PLUGIN, true, 0.0, true, 1.0);
  36.    
  37.     CreateConVar ("speedmeter_version", PLUGIN_VERSION, PLUGIN_NAME, FCVAR_PLUGIN | FCVAR_REPLICATED | FCVAR_NOTIFY);
  38.     CreateConVar ("speedmeter_credit", PLUGIN_URL, PLUGIN_NAME, FCVAR_PLUGIN | FCVAR_REPLICATED | FCVAR_NOTIFY);
  39.    
  40.     RegConsoleCmd("sm_speed", SwitchMeter);
  41.    
  42.     HookEvent ("round_start", Event_RoundStart);
  43.     HookEvent ("round_end", Event_RoundEnd);
  44. }
  45.  
  46. /********************
  47. * Start of Map
  48. *********************/
  49. public OnMapStart (){
  50.     g_MaxClients = GetMaxClients();
  51. }
  52.  
  53. /********************
  54. * Start of Round
  55. *********************/
  56. public Action:Event_RoundStart (Handle:event, const String:name[], bool:dontBroadcast) {
  57.     if (IsPluginEnable ()){
  58.         if (EnabledForPlar ()) {
  59.             if (g_timer != INVALID_HANDLE){
  60.                 KillTimer (g_timer);
  61.                 g_timer = INVALID_HANDLE;
  62.             }
  63.             g_timer = CreateTimer (1.0, Timer_Speed);
  64.         }
  65.     }
  66.     return Plugin_Continue;
  67. }
  68.  
  69. /********************
  70. * End of Round
  71. *********************/
  72. public Action:Event_RoundEnd (Handle:event, const String:name[], bool:dontBroadcast) {
  73.     if (g_timer != INVALID_HANDLE) {
  74.         KillTimer (g_timer);
  75.         g_timer = INVALID_HANDLE;
  76.     }
  77. }
  78.  
  79. /********************
  80. * Speed Timer
  81. *********************/
  82. public Action:Timer_Speed (Handle:timer, any:nothing) {
  83.     for (new i=1; i<=g_MaxClients; i++){
  84.         speedMeter (i);
  85.     }
  86.     g_timer = CreateTimer (1.0, Timer_Speed);
  87. }
  88.  
  89. /********************
  90. * On/Off for Player
  91. *********************/
  92. public Action:SwitchMeter () {
  93.     if(args < 0 && args > 1) {
  94.         PrintToChat("\x04[SM]:\x03 1 - Включить спидометр; 0 - отключить спидометр");
  95.         return Plugin_Handled;
  96.     } elseif (args == 1) {
  97.         if(EnabledForPlar == true) {
  98.             g_switch = true;
  99.             PrintToChat("\x04[SM]:\x03Вы включили спидометр");
  100.         }
  101.     } elseif (args == 0) {
  102.         g_switch = false;
  103.         PrintToChat("\x04[SM]:\x03Вы выключили спидометр");
  104.     }
  105. }
  106.  
  107. /********************
  108. * Speed Calculator
  109. *********************/
  110. stock speedMeter (client){
  111.     if (client && IsClientConnected (client) && IsClientInGame (client) && IsPlayerAlive (client)){
  112.         new Float:newPosition[3], Float:distance, Float:speed, String:message[128], unit;
  113.        
  114.         GetClientAbsOrigin (client, newPosition);
  115.         distance = GetVectorDistance (lastPosition[client], newPosition);
  116.         speed = distance / 20 * 2;
  117.         lastPosition[client] = newPosition;
  118.        
  119.         unit = GetConVarInt (g_unit);
  120.         switch (unit){
  121.             case 0:{
  122.                 message = "Current speed in kilometers";
  123.             }
  124.             case 1:{
  125.                 speed = speed / 1.609347;
  126.                 message = "Current speed in miles";
  127.             }
  128.         }      
  129.         PrintHintText (client, "%t", message, RoundToNearest (speed));
  130.     }
  131. }
  132.  
  133. /********************
  134. * Check Plugin
  135. *********************/
  136. stock Bool:IsPluginEnable (){
  137.     return Bool:GetConVarBool (g_enable);
  138. }
  139.  
  140. stock Bool:EnabledForPlar () {
  141.     return Bool:GetConVarBool (g_switch);
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement