Raised This Month: $51 Target: $400
 12% 

[TF2] Give addcond effect to a player who calls "MEDIC"


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
villyvilly
New Member
Join Date: Sep 2022
Old 09-03-2022 , 11:21   [TF2] Give addcond effect to a player who calls "MEDIC"
Reply With Quote #1

I am making a request here as well because I am not quite familiar with the topic categories here.

Just like the title stated, I am looking for a simple plugin, that gives "addcond 55" for 0.1 second, to a player when he/she does a "voicemenu 0 0" command, which is the "calling for medic" command.

From what I know, I can use AddCommandListener(OnVoiceMenu, "voicemenu");

I found a plugin by Tylerst, which can give addcond effects. It seems to be a good reference.

PHP Code:
#include <tf2>

public Plugin:myinfo =
{
    
name "TF2 Add Condition",
    
author "Tylerst",
    
description "Add a condition to the target(s)",
    
version "1.0.0",
    
url "None"
}

public 
OnPluginStart()
{
    
LoadTranslations("common.phrases");
    
RegAdminCmd("sm_addcond"Command_AddConditionADMFLAG_GENERIC"Add a condition to the target(s), Usage: sm_addcond "target" "condition number" "duration"");
    
RegAdminCmd("sm_removecond"Command_RemoveConditionADMFLAG_GENERIC"Add a condition to the target(s), Usage: sm_removecond "target" "condition number"");
}

public 
Action:Command_AddCondition(clientargs)
{

    if(
args != 3)
    {
        
ReplyToCommand(client"[SM] Usage: sm_addcond "target" "condition number" "duration"");
        return 
Plugin_Handled;
    }

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

    new 
iConditionFloat:flDuration;

    
GetCmdArg(2strBuffersizeof(strBuffer));
    
iCondition StringToInt(strBuffer);

    
GetCmdArg(3strBuffersizeof(strBuffer));
    
flDuration StringToFloat(strBuffer);    

    for(new 
0target_counti++)
    {
        
TF2_AddCondition(target_list[i], TFCond:iConditionflDuration);
    }
    return 
Plugin_Handled;
}

public 
Action:Command_RemoveCondition(clientargs)
{

    if(
args != 2)
    {
        
ReplyToCommand(client"[SM] Usage: sm_removecond "target" "condition number"");
        return 
Plugin_Handled;
    }

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

    new 
iCondition;

    
GetCmdArg(2strBuffersizeof(strBuffer));
    
iCondition StringToInt(strBuffer);

    for(new 
0target_counti++)
    {
        
TF2_RemoveCondition(target_list[i], TFCond:iCondition);
    }
    return 
Plugin_Handled;

villyvilly is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 09-04-2022 , 00:19   Re: [TF2] Give addcond effect to a player who calls "MEDIC"
Reply With Quote #2

This should do what you want. I added a timer to prevent command spamming.

PHP Code:
#include <tf2>

#pragma semicolon 1
#pragma newdecls required

public Plugin myinfo 
{
    
name "Call for Medic",
    
author "PC Gamer",
    
description "Add condition when medic is called",
    
version "1.0",
    
url "www.sourcemod.com"    
}

bool g_wait[MAXPLAYERS 1] = {false, ...}; 

public 
void OnPluginStart()
{
    
AddCommandListener(Command_Listening"voicemenu");
}

public 
Action Command_Listening(int clientchar[] commandint args)
{
    
char arguments[4];
    
GetCmdArgString(argumentssizeof(arguments));
    if (
StrEqual(arguments"0 0") && g_wait[client] == false)
    {
        
//PrintToChatAll("Player %N called for a Medic", client);
        
TF2_AddCondition(clientTFCond_RadiusHealOnDamage0.1);
        
g_wait[client] = true;
        
CreateTimer(10.0Waitingclient); //How long you have to wait to use it again    
    
}
    
    return 
Plugin_Continue;
}

public 
Action Waiting(Handle timerany client
{
    
g_wait[client] = false;
    
    return 
Plugin_Handled;     

Attached Files
File Type: sp Get Plugin or Get Source (callmedic.sp - 67 views - 983 Bytes)
PC Gamer is offline
villyvilly
New Member
Join Date: Sep 2022
Old 09-04-2022 , 04:47   Re: [TF2] Give addcond effect to a player who calls "MEDIC"
Reply With Quote #3

Quote:
Originally Posted by PC Gamer View Post
This should do what you want. I added a timer to prevent command spamming.

PHP Code:
#include <tf2>

#pragma semicolon 1
#pragma newdecls required

public Plugin myinfo 
{
    
name "Call for Medic",
    
author "PC Gamer",
    
description "Add condition when medic is called",
    
version "1.0",
    
url "www.sourcemod.com"    
}

bool g_wait[MAXPLAYERS 1] = {false, ...}; 

public 
void OnPluginStart()
{
    
AddCommandListener(Command_Listening"voicemenu");
}

public 
Action Command_Listening(int clientchar[] commandint args)
{
    
char arguments[4];
    
GetCmdArgString(argumentssizeof(arguments));
    if (
StrEqual(arguments"0 0") && g_wait[client] == false)
    {
        
//PrintToChatAll("Player %N called for a Medic", client);
        
TF2_AddCondition(clientTFCond_RadiusHealOnDamage0.1);
        
g_wait[client] = true;
        
CreateTimer(10.0Waitingclient); //How long you have to wait to use it again    
    
}
    
    return 
Plugin_Continue;
}

public 
Action Waiting(Handle timerany client
{
    
g_wait[client] = false;
    
    return 
Plugin_Handled;     

Thanks a lot! It works exactly what I wanted.
villyvilly is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 09-04-2022 , 13:56   Re: [TF2] Give addcond effect to a player who calls "MEDIC"
Reply With Quote #4

Untested. Added a couple of ConVars for controlling plugin functionality, which is evident and self-explainable in the source code. Feel free to use it if you like!
PHP Code:
#include <sourcemod>
#include <tf2_stocks>

#pragma semicolon 1
#pragma newdecls required

public Plugin myinfo = {
    
name        "[TF2] 'MEDIC!' AddCond",
    
author      "PC Gamer, ThatKidWhoGames",
    
description "Gives a player radius healing for a configurable amount of time after calling for medic.",
    
version     "1.0.0",
    
url         "https://sourcemod.net/"
};

// Variables //
ConVar g_cvarEnable;            // Used for storing ConVar for enabling/disabling plugin functionality
ConVar g_cvarDelay;             // Used for storing ConVar for setting delay before a client can use this again
ConVar g_cvarTime;              // Used for storing ConVar for setting time for condition to last for
ConVar g_cvarCondition;         // Used for storing ConVar for condition to set
Handle g_timer[MAXPLAYERS 1]; // Used for storing timer handle for client's usage delay

public void OnPluginStart() {
    
// Create the ConVars
    
g_cvarEnable    CreateConVar("sm_callformedic_enable",    "1",   "Enable/disable the plugin",                                                    _true0.0true1.0);
    
g_cvarDelay     CreateConVar("sm_callformedic_delay",     "10",  "Delay (in seconds) before players can use the feature again (0 = No delay)"_true0.0);
    
g_cvarTime      CreateConVar("sm_callformedic_time",      "0.1""Time (in seconds) for the condition to last for",                              _true0.1);
    
g_cvarCondition CreateConVar("sm_callformedic_condition""55",  "Condition to give players");

    
// Add the command listener
    
AddCommandListener(CommandListener_VoiceMenu"voicemenu");
}

public 
void OnClientDisconnect_Post(int client) {
    
// Kill timer handle
    
delete g_timer[client];
}

public 
Action CommandListener_VoiceMenu(int client, const char[] commandint argc) {
    
// Check if plugin is enabled
    
if (g_cvarEnable.BoolValue) {
        
// Fetch arguments string
        
char argstr[4];
        
GetCmdArgString(argstrsizeof(argstr));

        
// Check if client indeed called for medic, is alive, and doesn't currently have the condition active
        
if (StrEqual(argstr"0 0") && IsPlayerAlive(client) && !TF2_IsPlayerInCondition(clientview_as<TFCond>(g_cvarCondition.IntValue))) {
            
// Check if delay is enabled
            
if (FloatCompare(0.0g_cvarDelay.FloatValue) == -1) {
                
// Check if client is not on cooldown
                
if (g_timer[client] == null) {
                    
// Create cooldown timer for client
                    
g_timer[client] = CreateTimer(g_cvarDelay.FloatValueTimer_Cooldownclient);
                }
                else {
                    
// Skip execution; continue normally
                    
return Plugin_Continue;
                }
            }

            
// Add the condition to the client
            
TF2_AddCondition(clientview_as<TFCond>(g_cvarCondition.IntValue), g_cvarTime.FloatValue);
        }
    }

    
// Continue normally
    
return Plugin_Continue;
}

public 
Action Timer_Cooldown(Handle timerint client) {
    
// Set timer handle to null
    
g_timer[client] = null;

    
// Stop execution (unnecessary, but I prefer explicitly stating it ;-) )
    
return Plugin_Stop;

Attached Files
File Type: sp Get Plugin or Get Source (call_for_medic.sp - 64 views - 2.9 KB)

Last edited by ThatKidWhoGames; 09-04-2022 at 13:58.
ThatKidWhoGames 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 04:25.


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