Raised This Month: $ Target: $400
 0% 

Solved [TF2] Uber and Critz Activater (HELP PLZ)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Pretty Violet
Junior Member
Join Date: Apr 2024
Old 10-29-2024 , 01:12   [TF2] Uber and Critz Activater (HELP PLZ)
Reply With Quote #1

Greetings!

I wanted to create a plugin that activates crit and ubercharge when capturing intel.

When grabbing intel from either team, a 5 second delay follows and then the opposing team is given krit and uber for 20 seconds.

Code:

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <tf2>

public Plugin:myinfo = {
    
name "Capture Team Buff",
    
author "YourName",
    
description "Gives opposite team crits and uber on intel capture with delay",
    
version "1.20"
};

// Configuration settings
#define BUFF_DURATION 20.0   // Duration of crits and uber charge in seconds
#define DELAY_TIME 5.0       // Delay before activating effects in seconds

public void OnPluginStart() {
    
// Hook the flag capture event
    
HookEvent("ctf_flag_captured"OnFlagCaptureEventHookMode_Post);
    
PrintToConsoleAll("Capture Team Buff plugin loaded successfully.");
}

// Flag capture event handler
public Action OnFlagCapture(Event event, const char[] namebool dontBroadcast) {
    
// Get the team that captured the flag
    
int capturingTeam event.GetInt("team_caps"); 
    
PrintToConsoleAll("Flag captured by Team %d"capturingTeam);

    
// Determine the opposite team
    
int oppositeTeam = (capturingTeam == 2) ? 2
    
PrintToConsoleAll("Giving buffs to Team %d."oppositeTeam);
    
    
// Set a timer with a delay
    
CreateTimer(DELAY_TIMEApplyEffectsToOppositeTeamoppositeTeam);
}

// Timer for applying effects
public Action ApplyEffectsToOppositeTeam(Handle timerany oppositeTeam) {
    
// Apply effects to the opposite team
    
for (int client 1client <= MaxClientsclient++) {
        if (
IsClientInGame(client) && GetClientTeam(client) == oppositeTeam) {
            
// Add crit boost (usually 11) and uber charge (usually 5)
            
TF2_AddCondition(client11BUFF_DURATION); // Crits
            
TF2_AddCondition(client5BUFF_DURATION);  // Uber charge
            
PrintToConsole(client"You received crits and uber from your opponents!");
        }
    }
    return 
Plugin_Stop;


Some of what I was able to do, but the problem is that I can not return the ID of the team that captured the intel, the value says 0, so the team that gets buffs always defaults to 2.

Logs:

Flag captured by Team 0
Giving buffs to Team 2.
You received crits and uber from your opponents!



_____________________________________________
Attached Files
File Type: smx uber.smx (3.9 KB, 14 views)
File Type: sp Get Plugin or Get Source (uber.sp - 17 views - 1.8 KB)

Last edited by Pretty Violet; 11-10-2024 at 19:56.
Pretty Violet is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 10-30-2024 , 12:15   Re: [TF2] Uber and Critz Activater (HELP PLZ)
Reply With Quote #2

In the ctf_flag_captured event, there's no key that's named team_caps so it returns 0 every time.

What you're wanting is the key capping_team instead.
Drixevel is offline
Pretty Violet
Junior Member
Join Date: Apr 2024
Old 11-01-2024 , 16:32   Re: [TF2] Uber and Critz Activater (HELP PLZ)
Reply With Quote #3

Quote:
Originally Posted by Drixevel View Post
In the ctf_flag_captured event, there's no key that's named team_caps so it returns 0 every time.

What you're wanting is the key capping_team instead.
Thank you so much!!! It's working now!

I also wanted to add new features to my plugin, something that could replace admin alerts but with some conditions. I made a sketch of course - but it doesn't work. A bit below I will describe what I wanted to do and how I realized (code).

Idea:
For each team plays a different sound capture (for example, if captured the red - then they receive notification of the capture of the flag, but at the same time blue comes notification of the loss of the flag), but a maximum of 2 times for each team (on the third time already ends the matches and plays the sound of victory, but in this case there are already plugins).

Code:


PHP Code:
 #include <sourcemod>
#include <sdktools>
#include <tf2>

public Plugin:myinfo = {
    
name "Capture Team Buff",
    
author "YourName",
    
description "Gives opposite team crits and uber on intel capture with delay and sound notification",
    
version "1.30"
};

// Plugin settings
#define BUFF_DURATION 20.0   // Duration of crits and uber effects in seconds
#define DELAY_TIME 5.0       // Delay before activating effects in seconds
#define MAX_CAPTURES 2       // Maximum number of captures after which notifications are disabled

// Paths to sound files (make sure these files are accessible on the server and FastDL)
#define RED_CAPTURE_SOUND "sound/svoukr/DAYARUSSKI.wav"   // Sound for the red team on capture
#define BLUE_CAPTURE_SOUND "sound/svoukr/moskva.wav" // Sound for the blue team on capture
#define RED_LOSS_SOUND "sound/svoukr/dopomoje.wav"         // Sound for the red team on loss
#define BLUE_LOSS_SOUND "sound/svoukr/BRLIN.wav"       // Sound for the blue team on loss

// Capture counters for each team
int redCaptures 0;
int blueCaptures 0;

public 
void OnPluginStart() {
    
// Hook to flag capture event
    
HookEvent("ctf_flag_captured"OnFlagCaptureEventHookMode_Post);
    
PrintToConsoleAll("Capture Team Buff plugin loaded successfully.");
}

// Flag capture event handler
public Action OnFlagCapture(Event event, const char[] namebool dontBroadcast) {
    
// Get the ID of the team that captured the flag
    
int capturingTeam event.GetInt("capping_team"); 
    
PrintToConsoleAll("Flag captured by Team %d"capturingTeam);

    
// Determine the opposite team
    
int oppositeTeam = (capturingTeam == 2) ? 2

    
// Play sounds based on the team that captured the flag and the number of captures
    
if (capturingTeam == && redCaptures MAX_CAPTURES) {
        
EmitSoundToAll(RED_CAPTURE_SOUNDcapturingTeam);    // Sound for red team on capture
        
EmitSoundToAll(BLUE_LOSS_SOUNDoppositeTeam);       // Sound for blue team on loss
        
redCaptures++;
    }
    else if (
capturingTeam == && blueCaptures MAX_CAPTURES) {
        
EmitSoundToAll(BLUE_CAPTURE_SOUNDcapturingTeam);   // Sound for blue team on capture
        
EmitSoundToAll(RED_LOSS_SOUNDoppositeTeam);        // Sound for red team on loss
        
blueCaptures++;
    }

    
// Set a timer with a delay to apply buffs
    
if ((capturingTeam == && redCaptures <= MAX_CAPTURES) || (capturingTeam == && blueCaptures <= MAX_CAPTURES)) {
        
CreateTimer(DELAY_TIMEApplyEffectsToOppositeTeamoppositeTeam);
    }
    return 
Plugin_Handled;
}

// Timer for applying effects (buffs)
public Action ApplyEffectsToOppositeTeam(Handle timerany oppositeTeam) {
    
// Apply effects to the opposite team
    
for (int client 1client <= MaxClientsclient++) {
        if (
IsClientInGame(client) && GetClientTeam(client) == oppositeTeam) {
            
// Add crits effect (usually 11) and uber charge effect (usually 5)
            
TF2_AddCondition(client11BUFF_DURATION); // Crits
            
TF2_AddCondition(client5BUFF_DURATION);  // Uber charge
            
PrintToConsole(client"You received crits and uber from the opponents!");
        }
    }
    return 
Plugin_Stop;

Pretty Violet is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 11-02-2024 , 13:52   Re: [TF2] Uber and Critz Activater (HELP PLZ)
Reply With Quote #4

This is probably the simplest way of doing it:
Code:
void EmitSoundToTeam(const char[] sound, int team) {
	for (int i = 1; i <= MaxClients; i++) {
		if (IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) == team) {
			EmitSoundToClient(i, sound);
		}
	}
}
Drixevel is offline
Reply


Thread Tools
Display Modes

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 10:33.


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