View Single Post
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 - 67 views - 2.9 KB)

Last edited by ThatKidWhoGames; 09-04-2022 at 13:58.
ThatKidWhoGames is offline