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

Plugin Code & Compile Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ChillyWilly
Junior Member
Join Date: Feb 2022
Old 02-08-2024 , 18:04   Plugin Code & Compile Help
Reply With Quote #1

Hi All,

Looking for help with my plugin below, main goal is to add/remove bots based on wins and losses for the human team. I keep getting compile errors stating "plugin.sp(21) : fatal error 190: too many error messages on one line" so I am unsure of what is causing the issue. Looking for help from the community to explain and assist if they see anything?

I`m super new to scripting and pulled a bunch of this stuff from other scripts and am slowly researching what everything does so any additional explanations to the answer would be super helpful to me and my learning journey!

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

#pragma semicolon 1
#pragma newdecls required

// Configuration variables
ConVar g_iWinsToAddBot;
ConVar g_iWinsToRemoveBot;

// Plugin struct definition
public Plugin my_plugin =
{
    name = "Bot Manager",
    author = "Your Name",
    description = "Manages bots in Counter-Strike: Source based on player round outcomes.",
    version = "1.0"
};

// Event handler for player death
public Action Event_PlayerDeath(Handle:event, const char:eventName[], bool:dontBroadcast)
{
    int attacker = GetEventInt(event, "attacker");
    int victim = GetEventInt(event, "victim");
    
    if (IsClientInGame(attacker) && IsClientInGame(victim))
    {
        bool isBotAttacker = IsFakeClient(attacker);
        bool isBotVictim = IsFakeClient(victim);
        
        if (!isBotAttacker)
        {
            // Attacker is a human player
            int winningTeam = GetClientTeam(attacker);
            int losingTeam = GetClientTeam(victim);
            
            if (winningTeam != losingTeam)
            {
                // The attacker's team won the round
                if (GetTeamRoundWins(losingTeam) >= g_iWinsToAddBot.GetInt())
                {
                    ConVar_SetInt("bot_quota", GetMaxClients() - GetNumPlayers() + 1); // Increase bot quota by 1
                }
            }
            else
            {
                // The attacker's team lost the round
                if (!isBotVictim && GetTeamRoundWins(winningTeam) >= g_iWinsToRemoveBot.GetInt())
                {
                    ConVar_SetInt("bot_quota", GetMaxClients() - GetNumPlayers() - 1); // Decrease bot quota by 1
                }
            }
        }
    }
    
    return Plugin_Continue;
}

// Plugin initialization function
public void OnPluginStart()
{
    g_iWinsToAddBot = FindConVar("sm_botmanager_wins_to_add_bot");
    g_iWinsToRemoveBot = FindConVar("sm_botmanager_wins_to_remove_bot");
    
    // Hook the player_death event
    HookEvent("player_death", Event_PlayerDeath, EventHookMode_Post);
}

// Plugin shutdown function
public void OnPluginEnd()
{
    // Unhook the player_death event
    UnhookEvent("player_death", Event_PlayerDeath);
}
Open to other suggestions as well! Thanks a bunch!
ChillyWilly is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 02-08-2024 , 23:43   Re: Plugin Code & Compile Help
Reply With Quote #2

Code:
#pragma newdecls required
https://wiki.alliedmods.net/SourcePa...ing_new_syntax

You have colons : added in event callback
Code:
// Event handler for player death
public Action Event_PlayerDeath(Handle:event, const char:eventName[], bool:dontBroadcast)
{
https://sm.alliedmods.net/new-api/events/EventHook


Please, do not generate code with AI, example ChatGPT
It just not work.
__________________
Do not Private Message @me

Last edited by Bacardi; 02-08-2024 at 23:46.
Bacardi is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 02-10-2024 , 13:52   Re: Plugin Code & Compile Help
Reply With Quote #3

Translated into the SourcePawn programming language from the ChatGPT dialect:
PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <cstrike>

ConVar
    hQuota
;
int
    iAdd
,
    
iRemove;

public 
Plugin myinfo =
{
    
name "Bot Manager",
    
author "Your Name",
    
description "Manages bots in Counter-Strike: Source based on player round outcomes.",
    
version "1.0"
}

public 
void OnPluginStart()
{
    if(!(
hQuota FindConVar("bot_quota"))) SetFailState("Can't find convar 'bot_quota'");

    
ConVar cvar;
    
cvar CreateConVar("sm_botmanager_add""10""wins_to_add_bot"_true);
    
cvar.AddChangeHook(CVarChange_Add);
    
iAdd cvar.IntValue;

    
cvar CreateConVar("sm_botmanager_remove""8""wins_to_remove_bot"_true);
    
cvar.AddChangeHook(CVarChange_Remove);
    
iRemove cvar.IntValue;

    
HookEvent("player_death"Event_DeathEventHookMode_Post);
}

public 
void CVarChange_Add(ConVar cvar, const char[] oldValue, const char[] newValue)
{
    
iAdd cvar.IntValue;
}

public 
void CVarChange_Remove(ConVar cvar, const char[] oldValue, const char[] newValue)
{
    
iRemove cvar.IntValue;
}

public 
void Event_Death(Event event, const char[] eventNamebool dontBroadcast)
{
    
int victim GetEventInt(event"victim");
    if(!
victim || !IsClientInGame(victim))
        return;

    
int attacker GetEventInt(event"attacker");
    if(!
attacker || attacker == victim || !IsClientInGame(attacker) || IsFakeClient(attacker))
        return;

    
int losingTeam GetClientTeam(victim), num hQuota.IntValue;
    if(
GetClientTeam(attacker) != losingTeam)
    {
        if (
CS_GetTeamScore(losingTeam) >= iAdd)
            
num++;
    }
    else if(!
IsFakeClient(victim) && CS_GetTeamScore(losingTeam) >= iRemove)
        
num--;

    
hQuota.IntValue num;

But the algorithm is still flawed, LOL.
__________________
Grey83 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 04:00.


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