AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   Solved [TF2] Don't Heal Me Plugin (https://forums.alliedmods.net/showthread.php?t=340275)

PC Gamer 11-07-2022 15:05

[TF2] Don't Heal Me Plugin
 
Please make and share a plugin that allows any player to type a command: !nomedic
When the command is entered Medic Bots are NOT able to able to target or heal the player with their medigun.
Players are able to reverse this action with the command: !medic

Why I want the plugin: I do a lot of development work on a live server. The sound and actions of the Medic Bot medigun annoy me while I'm testing things. They seem to fixate on me as a Human player and refuse to heal anyone else. In response to this I normally just change the class of all Medic Bots to something else. However, this has the negative effect of denying other Human players with Medic bots.

I'm hoping you'll be able to write and share a plugin that will prevent Medics from even targeting me with their healing medigun. That way there is no overhealing that impacts my testing, and no healing sound to annoy my ears.

Bacardi 11-10-2022 15:01

Re: [TF2] Don't Heal Me Plugin
 
...I have "fiddle about" little. If I'm lucky I post some kind example, soon.

PC Gamer 11-10-2022 16:54

Re: [TF2] Don't Heal Me Plugin
 
Thanks Bacardi!

I made this plugin which works most of the time but it has two issues:
1. I'd prefer to find an solution that doesn't involve attributes.
2. Its buggy. The player will sometimes still get healed by a Medic.

If you have a better solution please share.

PHP Code:

#include <tf2_stocks>
#include <tf2attributes>

#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "1.0"
#define CHEER "/ambient_mp3/bumper_car_cheer3.mp3"

public Plugin myinfo 
{
    
name "No Healing",
    
author "PC Gamer",
    
description "Medics cannot heal Player",
    
version PLUGIN_VERSION,
    
url "https://forums.alliedmods.net/"
}

public 
void OnPluginStart() 
{
    
RegConsoleCmd("sm_noheal"No_Heal"Medics cannot heal you");
    
RegConsoleCmd("sm_nohealing"No_Heal"Medics cannot heal you");
    
RegConsoleCmd("sm_nomedic"No_Heal"Medics cannot heal you");    
    
RegConsoleCmd("sm_heal"Zombie_Mode"Medics can heal you");
    
RegConsoleCmd("sm_healing"Zombie_Mode"Medics can heal you");    
    
RegConsoleCmd("sm_medic"Zombie_Mode"Medics can heal you");    
}

public 
void OnMapStart()
{
    
PrecacheSound(CHEER);
}

public 
Action No_Heal(int clientint args)
{
    if(
IsValidClient(client))
    {
        
TF2Attrib_SetByName(client"mod weapon blocks healing"1.0);    

        
EmitSoundToAll(CHEER);
        
        
PrintToChat(client"You can no longer be healed by Medics");
        
PrintToChat(client"To reverse this effect type: !medic");
    }
    return 
Plugin_Handled;
}

public 
Action Zombie_Mode(int clientint args)
{    
    if(
IsValidClient(client))
    {
        
TF2Attrib_RemoveByName(client"mod weapon blocks healing");
        
        
PrintToChat(client"You can now be healed by Medics");
    }
    
    return 
Plugin_Handled;
}

stock bool IsValidClient(int client)
{
    if (
client <= 0) return false;
    if (
client MaxClients) return false;
    return 
IsClientInGame(client);



Bacardi 11-10-2022 18:07

Re: [TF2] Don't Heal Me Plugin
 
2 Attachment(s)
I have test this far, with (Windows only)
Code:

CTFPlayer *CTFBotMedicHeal::SelectPatient( CTFBot *me, CTFPlayer *current )
bool CTFBotMedicHeal::IsStable( CTFPlayer *patient ) const

Medic not heal human player, if there are no other teammates in close range.

I have to look at least one more thing also
Code:

CFindMostInjuredNeighbor( CTFBot *me, float maxRange, bool isInCombat )
- When medic heal primary patient, medic also try heal other teammates close by who have low health.

I go sleep

PC Gamer 01-22-2023 19:10

Re: [TF2] Don't Heal Me Plugin
 
I'm marking this thread as 'solved' after receiving help from Bacardi, nosoop, and Pelipoika. Thanks!

Final version:
PHP Code:

//#include <tf2attributes>
#include <tf2utils> //tf2utils by nosoop

#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "1.0"
#define CHEER "/ambient_mp3/bumper_car_cheer3.mp3"

bool g_bNoMedic[MAXPLAYERS 1];

public 
Plugin myinfo 
{
    
name "No Healing",
    
author "PC Gamer",
    
description "Prevent Medics from Healing You",
    
version PLUGIN_VERSION,
    
url "www.sourcemod.net"
}

public 
void OnPluginStart() 
{
    
RegConsoleCmd("sm_noheal"Command_No_Heal"Medics cannot heal you");
    
RegConsoleCmd("sm_nohealing"Command_No_Heal"Medics cannot heal you");
    
RegConsoleCmd("sm_heal"Command_Heal"Medics can heal you");
    
RegConsoleCmd("sm_healing"Command_Heal"Medics can heal you");    

    
HookEvent("player_healed"EventPlayerHealed);
}

public 
void OnMapStart()
{
    
PrecacheSound(CHEER);
}

public 
void EventPlayerHealed(Handle event, const char[] namebool dontBroadcast
{
    
int iMedic GetClientOfUserId(GetEventInt(event"healer"));
    
int iPatient GetClientOfUserId(GetEventInt(event"patient"));
    
    if (
g_bNoMedic[iPatient] && iMedic !=iPatient)
    {
        
PrintToChat(iMedic"%N does not want to be healed"iPatient);
        
PrintToChat(iPatient"Doesn't want %N healing them"iMedic);        
        
ForcePlayerSuicide(iMedic);
    }
}

Action Command_No_Heal(int clientint args)
{
    if(
IsValidClient(client))
    {
        
//TF2Attrib_SetByName(client, "mod weapon blocks healing", 1.0);    

        
g_bNoMedic[client] = true;
        
EmitSoundToAll(CHEER);
        
        
PrintToChat(client"You can no longer be healed by Medics");
        
PrintToChat(client"To reverse this effect type: !healing");
        
CreateTimer(1.0CheckForHealerGetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
    }
    return 
Plugin_Handled;
}

Action Command_Heal(int clientint args)
{    
    if(
IsValidClient(client))
    {
        
//TF2Attrib_RemoveByName(client, "mod weapon blocks healing");
        
        
g_bNoMedic[client] = false;
        
PrintToChat(client"You can now be healed by Medics");
        return 
Plugin_Stop;
    }
    
    return 
Plugin_Handled;
}

Action CheckForHealer(Handle timerany userid)
{
    
int iClient GetClientOfUserId(userid);
    
    if (
IsValidClient(iClient) && g_bNoMedic[iClient] == true)
    {
        for (
int iGetEntProp(iClientProp_Send"m_nNumHealers"); ni++)
        {
            
int iHealerIndex TF2Util_GetPlayerHealer(iClienti);
            
bool bIsClient = (iHealerIndex <= MaxClients);
            
            if(
bIsClient && iClient != iHealerIndex)
            {
                
//PrintToServer("\"%N\" <- healed by player \"%N\" [%i]", iClient, iHealerIndex, iHealerIndex);
                
PrintToChat(iHealerIndex"%N does not want to be healed"iClient);
                
ForcePlayerSuicide(iHealerIndex);
            }
        }
    }
    else
    {
        return 
Plugin_Stop;
    }
    
    return 
Plugin_Handled;
}

bool IsValidClient(int client)
{
    if (
client <= 0) return false;
    if (
client MaxClients) return false;
    return 
IsClientInGame(client);




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

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