mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-29 07:32:02 +00:00
Specialized Lua function for bot removal
This commit is contained in:
parent
93ec472c78
commit
a2fce68f14
3 changed files with 42 additions and 12 deletions
|
@ -2472,7 +2472,7 @@ void CL_ClearPlayer(INT32 playernum)
|
|||
//
|
||||
// Removes a player from the current game
|
||||
//
|
||||
static void CL_RemovePlayer(INT32 playernum, kickreason_t reason)
|
||||
void CL_RemovePlayer(INT32 playernum, kickreason_t reason)
|
||||
{
|
||||
// Sanity check: exceptional cases (i.e. c-fails) can cause multiple
|
||||
// kick commands to be issued for the same player.
|
||||
|
@ -2815,22 +2815,18 @@ static void Command_Kick(void)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!netgame) // Don't kick Tails in splitscreen!
|
||||
{
|
||||
CONS_Printf(M_GetText("This only works in a netgame.\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (server || IsPlayerAdmin(consoleplayer))
|
||||
{
|
||||
UINT8 buf[3 + MAX_REASONLENGTH];
|
||||
UINT8 *p = buf;
|
||||
const SINT8 pn = nametonum(COM_Argv(1));
|
||||
|
||||
// Unlike bans, kicks are used especially to remove bot players, so we'll
|
||||
// need to run a more specific check which allows kicking offline, but
|
||||
// not against splitscreen players.
|
||||
if (splitscreen && (pn == 0 || pn == 1))
|
||||
{
|
||||
CONS_Printf(M_GetText("Splitscreen players cannot be kicked.\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (pn == -1 || pn == 0)
|
||||
return;
|
||||
|
||||
|
|
|
@ -401,6 +401,7 @@ void CL_Reset(void);
|
|||
void CL_ClearPlayer(INT32 playernum);
|
||||
void CL_QueryServerList(msg_server_t *list);
|
||||
void CL_UpdateServerList(boolean internetsearch, INT32 room);
|
||||
void CL_RemovePlayer(INT32 playernum, kickreason_t reason);
|
||||
// Is there a game running
|
||||
boolean Playing(void);
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "d_netcmd.h" // IsPlayerAdmin
|
||||
#include "m_menu.h" // Player Setup menu color stuff
|
||||
#include "b_bot.h" // B_UpdateBotleader
|
||||
#include "d_clisrv.h" // CL_RemovePlayer
|
||||
|
||||
#include "lua_script.h"
|
||||
#include "lua_libs.h"
|
||||
|
@ -3463,7 +3464,7 @@ static int lib_gAddPlayer(lua_State *L)
|
|||
strcpy(player_names[newplayernum], luaL_checkstring(L, 3));
|
||||
|
||||
bot = luaL_optinteger(L, 4, 3);
|
||||
newplayer->bot = (bot >= 0 && bot <= 3) ? bot : 3;
|
||||
newplayer->bot = (bot >= BOT_NONE && bot <= BOT_MPAI) ? bot : BOT_MPAI;
|
||||
|
||||
// If our bot is a 2P type, we'll need to set its leader so it can spawn
|
||||
if (newplayer->bot == BOT_2PAI || newplayer->bot == BOT_2PHUMAN)
|
||||
|
@ -3487,6 +3488,37 @@ static int lib_gAddPlayer(lua_State *L)
|
|||
}
|
||||
|
||||
|
||||
// Bot removing function
|
||||
static int lib_gRemovePlayer(lua_State *L)
|
||||
{
|
||||
UINT8 pnum = -1;
|
||||
//const char *kickreason = luaL_checkstring(L, 2);
|
||||
|
||||
if (!lua_isnoneornil(L, 1))
|
||||
pnum = luaL_checkinteger(L, 1);
|
||||
if (&players[pnum])
|
||||
{
|
||||
if (players[pnum].bot != BOT_NONE)
|
||||
{
|
||||
// CL_RemovePlayer(pnum, *kickreason);
|
||||
CL_RemovePlayer(pnum, pnum);
|
||||
if (netgame)
|
||||
{
|
||||
char kickmsg[256];
|
||||
|
||||
strcpy(kickmsg, M_GetText("\x82*Bot %s has been removed"));
|
||||
strcpy(kickmsg, va(kickmsg, player_names[pnum], pnum));
|
||||
HU_AddChatText(kickmsg, false);
|
||||
}
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int Lcheckmapnumber (lua_State *L, int idx, const char *fun)
|
||||
{
|
||||
if (ISINLEVEL)
|
||||
|
@ -4068,6 +4100,7 @@ static luaL_Reg lib[] = {
|
|||
// g_game
|
||||
{"G_AddGametype", lib_gAddGametype},
|
||||
{"G_AddPlayer", lib_gAddPlayer},
|
||||
{"G_RemovePlayer", lib_gRemovePlayer},
|
||||
{"G_BuildMapName",lib_gBuildMapName},
|
||||
{"G_BuildMapTitle",lib_gBuildMapTitle},
|
||||
{"G_FindMap",lib_gFindMap},
|
||||
|
|
Loading…
Reference in a new issue