Raised This Month: $ Target: $400
 0% 

[REQ] Add Cvar to plugin tf2


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tigocesar
Member
Join Date: Oct 2015
Old 06-01-2016 , 10:33   [REQ] Add Cvar to plugin tf2
Reply With Quote #1

Hello

I need some help. I want to edit the speed of the players from my server
I want to use this plugin
https://forums.alliedmods.net/showthread.php?p=1359499

But .. the plugin doesn't have the cvar that leaves the command permanently on server
It has been requested from the author to add this function but he didn't answer
The command is :
sm_setspeed

I wanted to put the RED team speed at 300 in all the rounds .

Can someone help me?
tigocesar is offline
tigocesar
Member
Join Date: Oct 2015
Old 08-08-2016 , 23:19   Re: [REQ] Add Cvar to plugin tf2
Reply With Quote #2

Bump

I really need this. I'll pay for this. Just help me and contact me in MP
tigocesar is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 08-09-2016 , 03:58   Re: [REQ] Add Cvar to plugin tf2
Reply With Quote #3

Let me 30 sec.


Here you go.

New command : sm_defaultspeed
New CVAR : sm_defaultspeed_value "-1" - Set the default server speed, -1 to disable.
PHP Code:
#pragma semicolon 1

#include <tf2_stocks>
#include <sdkhooks>

#define PLUGIN_VERSION "1.4.0"

public Plugin:myinfo =
{
    
name "TF2 Set Speed",
    
author "Tylerst",
    
description "Set the movement speed of the target(s)",
    
version PLUGIN_VERSION,
}
public 
APLRes:AskPluginLoad2(Handle:myselfbool:lateString:error[], err_max)
{
    if(
GetEngineVersion() != Engine_TF2)
    {
        
Format(errorerr_max"This plugin only works for Team Fortress 2");
        return 
APLRes_Failure;
    }
    return 
APLRes_Success;
}

new 
Handle:hChat INVALID_HANDLE;
new 
Handle:hLog INVALID_HANDLE;
new 
Handle:hDefaultSpeed INVALID_HANDLE;
new 
Float:g_flSpeed[MAXPLAYERS+1];
new 
Float:DefaultSpeed = -1.0;
new 
bool:g_bSpeedSet[MAXPLAYERS+1] = false;

public 
OnPluginStart()
{
    
LoadTranslations("common.phrases");
    
CreateConVar("sm_setspeed_version"PLUGIN_VERSION"Set the movement speed of the target(s)"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
hChat CreateConVar("sm_setspeed_chat""1""Enable/Disable Showing setspeed changes in chat");
    
hLog CreateConVar("sm_setspeed_log""1""Enable/Disable Logging setspeed changes");
    
hDefaultSpeed CreateConVar("sm_defaultspeed_value""-1""Set the default server speed, -1 to disable.");
    
RegAdminCmd("sm_setspeed"Command_SetSpeedADMFLAG_SLAY"Set target(s) speed, Usage: sm_setspeed \"target\" \"speed\"");
    
RegAdminCmd("sm_resetspeed"Command_ResetSpeedADMFLAG_SLAY"Reset target(s) speed, Usage: sm_resetspeed \"target\"");
    
RegAdminCmd("sm_unsetspeed"Command_ResetSpeedADMFLAG_SLAY"Reset target(s) speed, Usage: sm_unsetspeed \"target\"");
    
RegAdminCmd("sm_defaultspeed"Command_DefaultSpeedADMFLAG_SLAY"Set the default speed for all the server");
    for(new 
client 1client <= MaxClientsclient++)
    {
        
OnClientPutInServer(client);
    }
}

public 
OnClientPutInServer(client)
{
    if(
IsValidClient(clientfalse))
    {
        
SDKHook(clientSDKHook_PreThinkSDKHooks_OnPreThink);    
        if(
DefaultSpeed != -1)
        {
            
g_bSpeedSet[client] = true;
            
SetSpeed(clientDefaultSpeed);
        }
        else
        {
            
g_bSpeedSet[client] = false;
        }
    }
}

public 
void OnConfigsExecuted()
{
    
DefaultSpeed GetConVarFloat(hDefaultSpeed);
}

public 
SDKHooks_OnPreThink(client)
{
    if(
IsValidClient(client) && g_bSpeedSet[client]) SetSpeed(clientg_flSpeed[client]);
}

public 
Action:Command_SetSpeed(clientargs)
{
    if(
args != 2)
    {
        
ReplyToCommand(client"[SM] Usage: sm_setspeed \"target\" \"speed\"");
        return 
Plugin_Handled;
    }

    new 
String:strTarget[MAX_TARGET_LENGTH], String:strSpeed[32], Float:flSpeedString:target_name[MAX_TARGET_LENGTH],target_list[MAXPLAYERS], target_countbool:tn_is_ml;
    
GetCmdArg(1strTargetsizeof(strTarget));
    if((
target_count ProcessTargetString(strTargetclienttarget_listMAXPLAYERS0target_namesizeof(target_name), tn_is_ml)) <= 0)
    {
        
ReplyToTargetError(clienttarget_count);
        return 
Plugin_Handled;
    }


    
GetCmdArg(2strSpeedsizeof(strSpeed));
    
flSpeed StringToFloat(strSpeed);
    
    if(
flSpeed 0.0 || flSpeed 520.0)
    {
        
ReplyToCommand(client"[SM] Speed must be from 0 to 520");
        return 
Plugin_Handled;
    }    

    new 
bool:bLog  GetConVarBool(hLog);
    for(new 
0target_counti++)
    {
        
g_flSpeed[target_list[i]] = flSpeed;
        
g_bSpeedSet[target_list[i]] = true;
        if(
bLogLogAction(clienttarget_list[i], "\"%L\" set speed of  \"%L\" to (%f)"clienttarget_list[i], flSpeed);
    }
    if(
GetConVarBool(hChat)) ShowActivity2(client"[SM] ","Set speed of %s to %-0.2f"target_nameflSpeed);
    return 
Plugin_Handled;
}

public 
Action:Command_ResetSpeed(clientargs)
{
    if (
args != 1)
    {
        
ReplyToCommand(client"\x04[SM] \x01Usage: sm_resetspeed \"target\"");
        return 
Plugin_Handled;
    }

    new 
String:strTarget[MAX_TARGET_LENGTH], String:target_name[MAX_TARGET_LENGTH],target_list[MAXPLAYERS], target_countbool:tn_is_ml;
    
GetCmdArg(1strTargetsizeof(strTarget));
    if((
target_count ProcessTargetString(strTargetclienttarget_listMAXPLAYERS0target_namesizeof(target_name), tn_is_ml)) <= 0)
    {
        
ReplyToTargetError(clienttarget_count);
        return 
Plugin_Handled;
    }

    new 
bool:bLog  GetConVarBool(hLog);
    for (new 
0target_count++)
    {
        
g_bSpeedSet[target_list[i]] = false;
        
ResetSpeed(target_list[i]);
        if(
bLogLogAction(clienttarget_list[i], "\"%L\" reset speed of  \"%L\" to Normal"clienttarget_list[i]);    
    }
    if(
GetConVarBool(hChat)) ShowActivity2(client"[SM] ","Set speed of %s to Normal"target_name);
    return 
Plugin_Handled;
}

public 
Action:Command_DefaultSpeed(clientargs)
{
     if(
args != -1)
     {
        
ReplyToCommand(client"\x04[SM] \x01Usage: sm_defaultspeed \"value\" use sm_defaultspeed \"RESET\" to disable the command.");
        return 
Plugin_Handled;
     }
     
     new 
String:value[10];
     
GetCmdArg(1valuesizeof(value));
     
     if(
StrEqual(value"reset"false))
     {
         for(new 
1<= MaxClientsi++)
         {
             if(
IsValidClient(i))
                
ResetSpeed(i);
        }
     }
     else
     {
        
DefaultSpeed StringToFloat(value);
        
         for(new 
1<= MaxClientsi++)
         {
             if(
IsValidClient(i))
                
SetSpeed(iDefaultSpeed);
        }
     }
     
     if(
GetConVarBool(hChat)) ShowActivity2(client"[SM] ","Set speed for the server to %-0.2f"DefaultSpeed); 
     
     return 
Plugin_Handled;
}

stock SetSpeed(clientFloat:flSpeed)
{
    
SetEntPropFloat(clientProp_Send"m_flMaxspeed"flSpeed);
}

stock ResetSpeed(client)
{
    
TF2_StunPlayer(client0.00.0TF_STUNFLAG_SLOWDOWN);
}

stock bool:IsValidClient(clientbool:bCheckAlive=true)
{
    if(
client || client MaxClients) return false;
    if(!
IsClientInGame(client)) return false;
    if(
IsClientSourceTV(client) || IsClientReplay(client)) return false;
    if(
bCheckAlive) return IsPlayerAlive(client);
    return 
true;

__________________
Want to check my plugins ?

Last edited by Arkarr; 08-09-2016 at 04:16.
Arkarr is offline
tigocesar
Member
Join Date: Oct 2015
Old 08-10-2016 , 23:42   Re: [REQ] Add Cvar to plugin tf2
Reply With Quote #4

Quote:
Originally Posted by Arkarr View Post
Let me 30 sec.


Here you go.

New command : sm_defaultspeed
New CVAR : sm_defaultspeed_value "-1" - Set the default server speed, -1 to disable.
PHP Code:
#pragma semicolon 1

#include <tf2_stocks>
#include <sdkhooks>

#define PLUGIN_VERSION "1.4.0"

public Plugin:myinfo =
{
    
name "TF2 Set Speed",
    
author "Tylerst",
    
description "Set the movement speed of the target(s)",
    
version PLUGIN_VERSION,
}
public 
APLRes:AskPluginLoad2(Handle:myselfbool:lateString:error[], err_max)
{
    if(
GetEngineVersion() != Engine_TF2)
    {
        
Format(errorerr_max"This plugin only works for Team Fortress 2");
        return 
APLRes_Failure;
    }
    return 
APLRes_Success;
}

new 
Handle:hChat INVALID_HANDLE;
new 
Handle:hLog INVALID_HANDLE;
new 
Handle:hDefaultSpeed INVALID_HANDLE;
new 
Float:g_flSpeed[MAXPLAYERS+1];
new 
Float:DefaultSpeed = -1.0;
new 
bool:g_bSpeedSet[MAXPLAYERS+1] = false;

public 
OnPluginStart()
{
    
LoadTranslations("common.phrases");
    
CreateConVar("sm_setspeed_version"PLUGIN_VERSION"Set the movement speed of the target(s)"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
hChat CreateConVar("sm_setspeed_chat""1""Enable/Disable Showing setspeed changes in chat");
    
hLog CreateConVar("sm_setspeed_log""1""Enable/Disable Logging setspeed changes");
    
hDefaultSpeed CreateConVar("sm_defaultspeed_value""-1""Set the default server speed, -1 to disable.");
    
RegAdminCmd("sm_setspeed"Command_SetSpeedADMFLAG_SLAY"Set target(s) speed, Usage: sm_setspeed \"target\" \"speed\"");
    
RegAdminCmd("sm_resetspeed"Command_ResetSpeedADMFLAG_SLAY"Reset target(s) speed, Usage: sm_resetspeed \"target\"");
    
RegAdminCmd("sm_unsetspeed"Command_ResetSpeedADMFLAG_SLAY"Reset target(s) speed, Usage: sm_unsetspeed \"target\"");
    
RegAdminCmd("sm_defaultspeed"Command_DefaultSpeedADMFLAG_SLAY"Set the default speed for all the server");
    for(new 
client 1client <= MaxClientsclient++)
    {
        
OnClientPutInServer(client);
    }
}

public 
OnClientPutInServer(client)
{
    if(
IsValidClient(clientfalse))
    {
        
SDKHook(clientSDKHook_PreThinkSDKHooks_OnPreThink);    
        if(
DefaultSpeed != -1)
        {
            
g_bSpeedSet[client] = true;
            
SetSpeed(clientDefaultSpeed);
        }
        else
        {
            
g_bSpeedSet[client] = false;
        }
    }
}

public 
void OnConfigsExecuted()
{
    
DefaultSpeed GetConVarFloat(hDefaultSpeed);
}

public 
SDKHooks_OnPreThink(client)
{
    if(
IsValidClient(client) && g_bSpeedSet[client]) SetSpeed(clientg_flSpeed[client]);
}

public 
Action:Command_SetSpeed(clientargs)
{
    if(
args != 2)
    {
        
ReplyToCommand(client"[SM] Usage: sm_setspeed \"target\" \"speed\"");
        return 
Plugin_Handled;
    }

    new 
String:strTarget[MAX_TARGET_LENGTH], String:strSpeed[32], Float:flSpeedString:target_name[MAX_TARGET_LENGTH],target_list[MAXPLAYERS], target_countbool:tn_is_ml;
    
GetCmdArg(1strTargetsizeof(strTarget));
    if((
target_count ProcessTargetString(strTargetclienttarget_listMAXPLAYERS0target_namesizeof(target_name), tn_is_ml)) <= 0)
    {
        
ReplyToTargetError(clienttarget_count);
        return 
Plugin_Handled;
    }


    
GetCmdArg(2strSpeedsizeof(strSpeed));
    
flSpeed StringToFloat(strSpeed);
    
    if(
flSpeed 0.0 || flSpeed 520.0)
    {
        
ReplyToCommand(client"[SM] Speed must be from 0 to 520");
        return 
Plugin_Handled;
    }    

    new 
bool:bLog  GetConVarBool(hLog);
    for(new 
0target_counti++)
    {
        
g_flSpeed[target_list[i]] = flSpeed;
        
g_bSpeedSet[target_list[i]] = true;
        if(
bLogLogAction(clienttarget_list[i], "\"%L\" set speed of  \"%L\" to (%f)"clienttarget_list[i], flSpeed);
    }
    if(
GetConVarBool(hChat)) ShowActivity2(client"[SM] ","Set speed of %s to %-0.2f"target_nameflSpeed);
    return 
Plugin_Handled;
}

public 
Action:Command_ResetSpeed(clientargs)
{
    if (
args != 1)
    {
        
ReplyToCommand(client"\x04[SM] \x01Usage: sm_resetspeed \"target\"");
        return 
Plugin_Handled;
    }

    new 
String:strTarget[MAX_TARGET_LENGTH], String:target_name[MAX_TARGET_LENGTH],target_list[MAXPLAYERS], target_countbool:tn_is_ml;
    
GetCmdArg(1strTargetsizeof(strTarget));
    if((
target_count ProcessTargetString(strTargetclienttarget_listMAXPLAYERS0target_namesizeof(target_name), tn_is_ml)) <= 0)
    {
        
ReplyToTargetError(clienttarget_count);
        return 
Plugin_Handled;
    }

    new 
bool:bLog  GetConVarBool(hLog);
    for (new 
0target_count++)
    {
        
g_bSpeedSet[target_list[i]] = false;
        
ResetSpeed(target_list[i]);
        if(
bLogLogAction(clienttarget_list[i], "\"%L\" reset speed of  \"%L\" to Normal"clienttarget_list[i]);    
    }
    if(
GetConVarBool(hChat)) ShowActivity2(client"[SM] ","Set speed of %s to Normal"target_name);
    return 
Plugin_Handled;
}

public 
Action:Command_DefaultSpeed(clientargs)
{
     if(
args != -1)
     {
        
ReplyToCommand(client"\x04[SM] \x01Usage: sm_defaultspeed \"value\" use sm_defaultspeed \"RESET\" to disable the command.");
        return 
Plugin_Handled;
     }
     
     new 
String:value[10];
     
GetCmdArg(1valuesizeof(value));
     
     if(
StrEqual(value"reset"false))
     {
         for(new 
1<= MaxClientsi++)
         {
             if(
IsValidClient(i))
                
ResetSpeed(i);
        }
     }
     else
     {
        
DefaultSpeed StringToFloat(value);
        
         for(new 
1<= MaxClientsi++)
         {
             if(
IsValidClient(i))
                
SetSpeed(iDefaultSpeed);
        }
     }
     
     if(
GetConVarBool(hChat)) ShowActivity2(client"[SM] ","Set speed for the server to %-0.2f"DefaultSpeed); 
     
     return 
Plugin_Handled;
}

stock SetSpeed(clientFloat:flSpeed)
{
    
SetEntPropFloat(clientProp_Send"m_flMaxspeed"flSpeed);
}

stock ResetSpeed(client)
{
    
TF2_StunPlayer(client0.00.0TF_STUNFLAG_SLOWDOWN);
}

stock bool:IsValidClient(clientbool:bCheckAlive=true)
{
    if(
client || client MaxClients) return false;
    if(!
IsClientInGame(client)) return false;
    if(
IsClientSourceTV(client) || IsClientReplay(client)) return false;
    if(
bCheckAlive) return IsPlayerAlive(client);
    return 
true;

Thank you so much, Arkarr!!
tigocesar is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 08-11-2016 , 03:07   Re: [REQ] Add Cvar to plugin tf2
Reply With Quote #5

Quote:
Originally Posted by tigocesar View Post
Thank you so much, Arkarr!!
It's fine, not tested through. Any feedback would be appreciate.
__________________
Want to check my plugins ?
Arkarr is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:05.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode