AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Trigger a function on round change in L4d1/2 (https://forums.alliedmods.net/showthread.php?t=346544)

alliedfront 03-02-2024 11:37

Trigger a function on round change in L4d1/2
 
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.

CAN2323 03-07-2024 17:33

Re: Trigger a function on round change in L4d1/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;
}

alliedfront 03-13-2024 12:53

Re: Trigger a function on round change in L4d1/2
 
@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;



little_froy 03-13-2024 21:33

Re: Trigger a function on round change in L4d1/2
 
Quote:

Originally Posted by CAN2323 (Post 2819132)
#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.


All times are GMT -4. The time now is 17:56.

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