Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <sdktools>
- #define PLUGIN_NAME "Speed Meter"
- #define PLUGIN_VERSION "1.0.1"
- #define PLUGIN_DESCRIPTION "Show current player speed in HUD every 2 sec"
- #define PLUGIN_AUTHOR "Petit Renard, Anubis"
- #define PLUGIN_URL "http://css.cooldev.net/"
- new Handle:g_enable = INVALID_HANDLE;
- new Handle:g_unit = INVALID_HANDLE;
- new Float:lastPosition[MAXPLAYERS + 1][3];
- new g_MaxClients;
- new Handle:g_timer = INVALID_HANDLE;
- new Bool:g_switch = false;
- /********************
- * Plugin Info
- *********************/
- public Plugin:myinfo = {
- name = PLUGIN_NAME,
- author = PLUGIN_AUTHOR,
- description = PLUGIN_DESCRIPTION,
- version = PLUGIN_VERSION,
- url = PLUGIN_URL
- };
- /********************
- * Start of Plugin
- *********************/
- public OnPluginStart (){
- LoadTranslations ("speedmeter.phrases");
- g_enable = CreateConVar ("speedmeter_enable", "1", "Enable SpeedMeter ? (1 = yes, 0 = no)", FCVAR_PLUGIN, true, 0.0, true, 1.0);
- g_unit = CreateConVar ("speedmeter_unit", "0", "Unit of length (0 = kilometres, 1 = miles)", FCVAR_PLUGIN, true, 0.0, true, 1.0);
- CreateConVar ("speedmeter_version", PLUGIN_VERSION, PLUGIN_NAME, FCVAR_PLUGIN | FCVAR_REPLICATED | FCVAR_NOTIFY);
- CreateConVar ("speedmeter_credit", PLUGIN_URL, PLUGIN_NAME, FCVAR_PLUGIN | FCVAR_REPLICATED | FCVAR_NOTIFY);
- RegConsoleCmd("sm_speed", SwitchMeter);
- HookEvent ("round_start", Event_RoundStart);
- HookEvent ("round_end", Event_RoundEnd);
- }
- /********************
- * Start of Map
- *********************/
- public OnMapStart (){
- g_MaxClients = GetMaxClients();
- }
- /********************
- * Start of Round
- *********************/
- public Action:Event_RoundStart (Handle:event, const String:name[], bool:dontBroadcast) {
- if (IsPluginEnable ()){
- if (EnabledForPlar ()) {
- if (g_timer != INVALID_HANDLE){
- KillTimer (g_timer);
- g_timer = INVALID_HANDLE;
- }
- g_timer = CreateTimer (1.0, Timer_Speed);
- }
- }
- return Plugin_Continue;
- }
- /********************
- * End of Round
- *********************/
- public Action:Event_RoundEnd (Handle:event, const String:name[], bool:dontBroadcast) {
- if (g_timer != INVALID_HANDLE) {
- KillTimer (g_timer);
- g_timer = INVALID_HANDLE;
- }
- }
- /********************
- * Speed Timer
- *********************/
- public Action:Timer_Speed (Handle:timer, any:nothing) {
- for (new i=1; i<=g_MaxClients; i++){
- speedMeter (i);
- }
- g_timer = CreateTimer (1.0, Timer_Speed);
- }
- /********************
- * On/Off for Player
- *********************/
- public Action:SwitchMeter () {
- if(args < 0 && args > 1) {
- PrintToChat("\x04[SM]:\x03 1 - Включить спидометр; 0 - отключить спидометр");
- return Plugin_Handled;
- } elseif (args == 1) {
- if(EnabledForPlar == true) {
- g_switch = true;
- PrintToChat("\x04[SM]:\x03Вы включили спидометр");
- }
- } elseif (args == 0) {
- g_switch = false;
- PrintToChat("\x04[SM]:\x03Вы выключили спидометр");
- }
- }
- /********************
- * Speed Calculator
- *********************/
- stock speedMeter (client){
- if (client && IsClientConnected (client) && IsClientInGame (client) && IsPlayerAlive (client)){
- new Float:newPosition[3], Float:distance, Float:speed, String:message[128], unit;
- GetClientAbsOrigin (client, newPosition);
- distance = GetVectorDistance (lastPosition[client], newPosition);
- speed = distance / 20 * 2;
- lastPosition[client] = newPosition;
- unit = GetConVarInt (g_unit);
- switch (unit){
- case 0:{
- message = "Current speed in kilometers";
- }
- case 1:{
- speed = speed / 1.609347;
- message = "Current speed in miles";
- }
- }
- PrintHintText (client, "%t", message, RoundToNearest (speed));
- }
- }
- /********************
- * Check Plugin
- *********************/
- stock Bool:IsPluginEnable (){
- return Bool:GetConVarBool (g_enable);
- }
- stock Bool:EnabledForPlar () {
- return Bool:GetConVarBool (g_switch);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement