Difference between revisions of "Valve Developer Community:Sandbox"

From Valve Developer Community
Jump to: navigation, search
(bots_vs_humans41.sma)
(.)
 
(22 intermediate revisions by 7 users not shown)
Line 1: Line 1:
<!-- Do not edit this line! -->{{sandbox}}<!-- Don't you dare! -->
+
<!-- Do not edit this line! -->{{sandbox}}<!-- Don't you dare! --> <!-- I edited it - Joshua Ashton -->
/*
+
----
 +
{{otherlang2
 +
|noborder=true
 +
|tr=
 +
|ru=Valve Developer Community:Sandbox:ru
 +
|es=
 +
|cs=Valve Developer Community:Sandbox:cs
 +
}}__NOTOC__
  
Bots vs. Humans plugin for FoxBot / Team Fortress Classic
+
{{TestTemplate|ep2=1|portal2=1}}
  
Features
+
{{LOCALMONTHNAME}} {{LOCALDAY2}}, {{LOCALYEAR}}
  
- Forces bots into one team, humans into another.
+
{{LOCALTIMESTAMP}}
- Maintains a chosen bot-to-human ratio.
 
  
CVARs
+
20180818062810
 
 
bvh_enabled (default=1) // 1 = plugin enabled, 0 = disabled
 
bvh_ratio (default=4) // bot-to-human ratio, bot count = humans * ratio
 
bvh_bot_team (default=1) // Which team should bots join? (1=blue, 2=red, 3=yellow, 4=green)
 
bvh_human_team (default=2) // Which team should humans join? (1=blue, 2=red, 3=yellow, 4=green)
 
 
 
Requirements
 
============
 
 
 
FoxBot settings:
 
 
 
bot_bot_balance 0
 
bot_team_balance 0
 
min_bots -1
 
max_bots -1
 
 
 
History
 
=======
 
 
 
4.0 Initial plugin submission
 
4.1 Changes:
 
- Replaced looping bot check task in "plugin_init" with single task in "logevent".
 
- Removing existing bot check tasks prior to setting up a new one.
 
- Using "get_players".
 
- Check bots again later if at least one of the bots is in the wrong team or hasn't picked a class (is_something_wrong).
 
 
 
*/
 
 
 
#include <amxmodx>
 
#include <engine>
 
 
 
#define PLUGIN "Bots vs. Humans"
 
#define VERSION "4.1"
 
#define AUTHOR "pizzahut"
 
 
 
new g_bot_cvar, g_bvh_enabled, g_bvh_ratio, g_bvh_bot_team, g_bvh_human_team
 
 
 
public plugin_init()
 
{
 
register_plugin(PLUGIN, VERSION, AUTHOR)
 
g_bot_cvar = get_cvar_pointer("bot") // FoxBot cvar through which commands are passed to the bots
 
g_bvh_enabled = register_cvar("bvh_enabled", "1") // 1 = plugin enabled, 0 = disabled
 
g_bvh_ratio = register_cvar("bvh_ratio", "4") // bot-to-human ratio, bot count = humans * ratio
 
g_bvh_bot_team = register_cvar("bvh_bot_team", "1") // Which team should bots join? (1=blue, 2=red, 3=yellow, 4=green)
 
g_bvh_human_team = register_cvar("bvh_human_team", "2") // Which team should humans join? (1=blue, 2=red, 3=yellow, 4=green)
 
register_clcmd("jointeam", "clcmd_jointeam") // Only humans use client commands.
 
register_clcmd("spectate", "clcmd_spectate") // Spectators use the "spectate" command.
 
register_logevent("logevent", 3, "1=joined team") // Switch bots to correct team.
 
// set_task(1.0,"task_check_bot_team",_,_,_,"b")
 
}
 
 
 
///////////////////////////////////////////
 
// Make sure humans join the human team. //
 
///////////////////////////////////////////
 
 
 
public clcmd_jointeam(id)
 
{
 
static Arg1[2], newteam
 
 
 
if(!get_pcvar_num(g_bvh_enabled)) // Plugin enabled?
 
return PLUGIN_CONTINUE // No --> Do nothing.
 
 
 
read_argv(1, Arg1, charsmax(Arg1))
 
newteam = str_to_num(Arg1)
 
if(newteam != get_pcvar_num(g_bvh_human_team))
 
{
 
client_cmd(id, "jointeam %d", get_pcvar_num(g_bvh_human_team))
 
return PLUGIN_HANDLED // Block the jointeam command.
 
}
 
set_task(1.0, "task_adjust_bot_count") // Adjust bot count when a human player joins a team.
 
return PLUGIN_CONTINUE
 
}
 
 
 
public clcmd_spectate(id)
 
{
 
set_task(1.0, "task_adjust_bot_count") // Adjust bot count if a human player changes to spectators.
 
return PLUGIN_CONTINUE
 
}
 
 
 
public client_disconnect(id)
 
set_task(1.0, "task_adjust_bot_count") // Adjust bot count if a player disconnects.
 
 
 
//////////////////////
 
// Adjust bot count //
 
//////////////////////
 
 
 
public task_adjust_bot_count(task_id)
 
{
 
static HumanCount, i, playerCount, Players[32], SpecCount, teamnumber
 
 
 
if(!get_pcvar_num(g_bvh_enabled)) // Plugin enabled?
 
return // No --> Do nothing.
 
 
 
HumanCount = 0 // How many humans in teams?
 
SpecCount = 0 // How many spectating humans?
 
 
 
get_players(Players, playerCount, "c") // skip bots, don't skip the HLTV
 
for(i = 0; i < playerCount; i++)
 
{
 
teamnumber = get_user_team(Players[i])
 
if((1 <= teamnumber) && (teamnumber <= 4))
 
HumanCount++
 
else
 
SpecCount++
 
}
 
if(HumanCount == 0)
 
HumanCount = 1 // Add some bots when server is empty. (Pretend we have 1 human player.)
 
static bot_cmd[12]
 
format(bot_cmd, charsmax(bot_cmd), "max_bots %d", HumanCount * (get_pcvar_num(g_bvh_ratio) + 1) + SpecCount)
 
set_pcvar_string(g_bot_cvar, bot_cmd) // Send a command to FoxBot on a dedicated server.
 
server_cmd(bot_cmd) // Send a command to FoxBot on a listen server.
 
}
 
 
 
//////////////////////////////////
 
// Change bots to the bot team. //
 
//////////////////////////////////
 
 
 
public logevent()
 
{
 
remove_task(33) // Remove already running tasks.
 
set_task(0.1, "task_check_bot_team", 33) // Switch bots to correct team.
 
}
 
 
 
public task_check_bot_team(task_id)
 
{
 
static bot_team[2], i, id, bool:is_something_wrong, playerCount, Players[32]
 
 
 
if(!get_pcvar_num(g_bvh_enabled))
 
return
 
is_something_wrong = false
 
get_players(Players, playerCount, "dh") // skip real players, skip HLTV
 
for(i = 0; i < playerCount; i++)
 
{
 
id = Players[i]
 
if(entity_get_int(id, EV_INT_playerclass) == 0)
 
{
 
is_something_wrong = true
 
switch(random_num(1,10))
 
{
 
case 1: engclient_cmd(id, "scout")
 
case 2: engclient_cmd(id, "sniper")
 
case 3: engclient_cmd(id, "soldier")
 
case 4: engclient_cmd(id, "demoman")
 
case 5: engclient_cmd(id, "medic")
 
case 6: engclient_cmd(id, "hwguy")
 
case 7: engclient_cmd(id, "pyro")
 
case 8: engclient_cmd(id, "spy")
 
case 9: engclient_cmd(id, "engineer")
 
case 10: engclient_cmd(id, "randompc")
 
}
 
}
 
if(get_user_team(id) != get_pcvar_num(g_bvh_bot_team))
 
{
 
is_something_wrong = true
 
get_pcvar_string(g_bvh_bot_team, bot_team, charsmax(bot_team))
 
engclient_cmd(id, "jointeam", bot_team)
 
}
 
}
 
if(is_something_wrong)
 
set_task(0.1, "task_check_bot_team", 33) // Make damn sure that bots switch to the correct team.
 
}
 

Latest revision as of 21:52, 6 October 2018

The Sandbox (Valve Developer Community:Sandbox) is a VDC namespace page designed for testing and experimenting with Wiki syntax. Feel free to try your skills at formatting here: click on edit, make your changes, and click 'Save page' when you are finished. Content added here will not stay permanently.

Please do not edit the "markup" text, at the top of the editing window, that reads "{{sandbox}}".


Čeština Русский

}}{{

October 18, 2019

20191018162354

20180818062810