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

Trigger a function on round change in L4d1/2


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alliedfront
Junior Member
Join Date: Jan 2024
Location: Germany
Old 03-02-2024 , 11:37   Trigger a function on round change in L4d1/2
Reply With Quote #1

Hello, is there a way in Sourcemod for a plugin to notice a round change?

In L4d Versus, a team's team number (Survivor or Infected) changes with each round within a running map. I want to update the team number in a kicked player's record every round so that only the team that issued it can decide to revoke a ban.
alliedfront is offline
CAN2323
Junior Member
Join Date: Oct 2022
Old 03-07-2024 , 17:33   Re: Trigger a function on round change in L4d1/2
Reply With Quote #2

#include <sourcemod>
#include <sdktools>

// Global variable to store the kicked player's Steam ID
static uint64 g_KickedPlayerSteamID;

// Callback function for on_player_disconnect event
public Action on_player_disconnect(int client, int reason)
{
// Save the kicked player's Steam ID
g_KickedPlayerSteamID = PlayerResource->GetSteamID(client);
return Plugin::Continue;
}

// Callback function for on_round_end hook
public Action on_round_end(int winning_team)
{
// Get the team number of the winning team
int team_number = Team::GetTeam(winning_team);

// Update the kicked player's team number in the database
DB::StoreQuery("UPDATE player_bans SET team_number = %d WHERE steam_id = %llu", team_number, g_KickedPlayerSteamID);

// Reset the global variable for the next round
g_KickedPlayerSteamID = 0;

return Plugin::Continue;
}

// Register the hooks and events
public Plugin:init()
{
Plugin::RegisterHook("player_disconnect", on_player_disconnect);
Plugin::RegisterHook("round_end", on_round_end);

return Plugin::Continue;
}
CAN2323 is offline
alliedfront
Junior Member
Join Date: Jan 2024
Location: Germany
Old 03-13-2024 , 12:53   Re: Trigger a function on round change in L4d1/2
Reply With Quote #3

@CAN2323, Thanks for your answer! However, I found a solution myself yesterday and came back today to update my previous post with it: To get a team number associated with each team during the game, I now use the logical team number:
PHP Code:
#include <sdktools_gamerules>

int GetLogicalTeam(int team)
{
    return (
team GameRules_GetProp("m_bAreTeamsFlipped"1)) - 1;


Last edited by alliedfront; 03-13-2024 at 12:58.
alliedfront is offline
little_froy
Senior Member
Join Date: May 2021
Old 03-13-2024 , 21:33   Re: Trigger a function on round change in L4d1/2
Reply With Quote #4

Quote:
Originally Posted by CAN2323 View Post
#include <sourcemod>
#include <sdktools>

// Global variable to store the kicked player's Steam ID
static uint64 g_KickedPlayerSteamID;

// Callback function for on_player_disconnect event
public Action on_player_disconnect(int client, int reason)
{
// Save the kicked player's Steam ID
g_KickedPlayerSteamID = PlayerResource->GetSteamID(client);
return Plugin::Continue;
}

// Callback function for on_round_end hook
public Action on_round_end(int winning_team)
{
// Get the team number of the winning team
int team_number = Team::GetTeam(winning_team);

// Update the kicked player's team number in the database
DB::StoreQuery("UPDATE player_bans SET team_number = %d WHERE steam_id = %llu", team_number, g_KickedPlayerSteamID);

// Reset the global variable for the next round
g_KickedPlayerSteamID = 0;

return Plugin::Continue;
}

// Register the hooks and events
public Plugin:init()
{
Plugin::RegisterHook("player_disconnect", on_player_disconnect);
Plugin::RegisterHook("round_end", on_round_end);

return Plugin::Continue;
}
please don't ask gpt for code.
little_froy 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 13:53.


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