Maxximou5 / csgo-deathmatch

Enables deathmatch style gameplay (respawning, gun selection, spawn protection, etc).
GNU General Public License v3.0
161 stars 42 forks source link

Bot buys #126

Closed EastSideKenny closed 1 year ago

EastSideKenny commented 3 years ago

Is there any way to tell the bots what they are chosing? It seems as if they were picking random but we would only like to have bots with AK/M4 , I made the bot_allow and the preferred weapons but I still have bots runnning around with knife only as they bought an SMG they can´t use

zahti commented 3 years ago

I'm having the same issue. I cannot figure out how to get the bots to spawn with just ak47 or a specified weapon.

I found this thread with another user having a similar issue, but no luck with the original code by LuqS: https://forums.alliedmods.net/showthread.php?p=2684712

#include <sourcemod>
#include <sdktools>
#include <cstrike>

#pragma newdecls required
#pragma semicolon 1

ConVar g_cvEnabled;
ConVar g_cvWeapon;

public Plugin myinfo = 
{
    name = "Bot Weapon spawner",
    author = "LuqS",
    description = "Gives a specific item to all bots",
    version = "1.0",
    url = ""
};

public void OnPluginStart()
{
    // Not gonna waste time :D //
    if(GetEngineVersion() != Engine_CSGO) 
        SetFailState("This plugin is for CSGO only.");

    g_cvEnabled = CreateConVar("bws_enabled", "1", "Whether the 'Bot Weapon Spawner' Plugin is enabled");
    g_cvWeapon = CreateConVar("bws_weapon", "ak47", "Weapon to give");

    HookEvent("player_spawn", Event_PlayerSpawn);
}

public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
    int client = GetClientOfUserId(event.GetInt("userid"));
    if(g_cvEnabled.BoolValue && IsClientInGame(client) && IsPlayerAlive(client) && IsFakeClient(client))
    {
        char weapon[32];
        g_cvWeapon.GetString(weapon, sizeof(weapon));
        Format(weapon, sizeof(weapon), "weapon_%s", weapon);

        if(GivePlayerItem(client, weapon) == -1)
            PrintToServer("Failed to give %N weapon - %s", client, weapon);
    }
}

Also, the follow-up code posted by Cruze does not compile otherwise I would try it:

#include <sourcemod>
#include <sdktools>
#include <cstrike>

#pragma newdecls required
#pragma semicolon 1

ConVar g_cvEnabled;
ConVar g_cvWeapon;

char WeaponsList[][] = //From advadmin
{
    "c4", "knife", "knifegg", "taser", "healthshot", //misc
    "decoy", "flashbang", "hegrenade", "molotov", "incgrenade", "smokegrenade", "tagrenade", //grenades
    "usp_silencer", "glock", "tec9", "p250", "hkp2000", "cz75a", "deagle", "revolver", "fiveseven", "elite", //pistoles
    "nova", "xm1014", "sawedoff", "mag7", "m249", "negev", //heavy
    "mp9", "mp7", "ump45", "p90", "bizon", "mac10", "mp5sd", //smgs
    "ak47", "aug", "famas", "sg556", "galilar", "m4a1", "m4a1_silencer", //rifles
    "awp", "ssg08", "scar20", "g3sg1" //snipers
};

public Plugin myinfo = 
{
    name = "Bot Weapon spawner",
    author = "LuqS",
    description = "Gives a specific item to all bots",
    version = "1.1",
    url = ""
};

public void OnPluginStart()
{
    // Not gonna waste time :D //
    if(GetEngineVersion() != Engine_CSGO) 
        SetFailState("This plugin is for CSGO only.");

    g_cvEnabled = CreateConVar("bws_enabled", "1", "Whether the 'Bot Weapon Spawner' Plugin is enabled");
    g_cvWeapon = CreateConVar("bws_weapon", "ak47", "Weapon to give");

    HookEvent("player_spawn", Event_PlayerSpawn);
}

public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
    int client = GetClientOfUserId(event.GetInt("userid"));
    if(g_cvEnabled.BoolValue && IsFakeClient(client) && IsPlayerAlive(client))
    {
        char weapon[32];
        g_cvWeapon.GetString(weapon, sizeof(weapon));
        Format(weapon, sizeof(weapon), "weapon_%s", weapon);

        if(!GivePlayerWeapon(client, weapon))
            PrintToServer("Failed to give %N weapon - %s", client, weapon);
    }
}
int GivePlayerWeapon(int client, char[] weapon)
{
        for(int i = 0; i < sizeof(WeaponsList[]); i++)
        {
                 if(StrEqual(weapon[7], WeaponList[i], false))
                 {
                         GivePlayerItem(client, weapon);
                         return 1;
                 }
        }
        return -1;
}

Compiler used: https://spider.limetech.io/

SourcePawn Compiler 1.10
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2018 AlliedModders LLC

plugin.sp(58) : error 072: "sizeof" operator is invalid on "function" symbols
plugin.sp(60) : error 017: undefined symbol "WeaponList"
plugin.sp(60) : warning 215: expression has no effect
plugin.sp(60) : error 001: expected token: ";", but found "]"
plugin.sp(60) : error 029: invalid expression, assumed zero
plugin.sp(60) : fatal error 190: too many error messages on one line

Compilation aborted.
5 Errors.
zahti commented 3 years ago

After downloading SPCode, I was able to compile the plugin with the includes. Here is my repo: https://github.com/zahti/csgo-bot-weapon-spawner/

This is a combination of code from @Natanel-Shitrit and @Cruze03

One important note is that you need this plugin to be loaded after the DM plugin. To do this manually after joining the server... rcon sm plugins unload botweaponspawner rcon sm plugins load botweaponspawner

This will make it so after a bot dies and respawns, it should spawn with an ak47. However, it is not 100% reliable and I have noticed that some of the bot profiles do not ever spawn with an ak47.

Please create a new issue on my repo if you have any issues or questions with my plugin.