Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
SRB2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
John Peter Sa
SRB2
Commits
4e029dbc
Commit
4e029dbc
authored
Jan 15, 2021
by
Claire Ellis
Browse files
Options
Downloads
Patches
Plain Diff
Update lua_baselib.c
parent
00462323
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lua_baselib.c
+77
-0
77 additions, 0 deletions
src/lua_baselib.c
with
77 additions
and
0 deletions
src/lua_baselib.c
+
77
−
0
View file @
4e029dbc
...
@@ -3407,6 +3407,82 @@ static int lib_gAddGametype(lua_State *L)
...
@@ -3407,6 +3407,82 @@ static int lib_gAddGametype(lua_State *L)
return
0
;
return
0
;
}
}
// Bot adding function!
// Partly lifted from Got_AddPlayer
static
int
lib_gAddPlayer
(
lua_State
*
L
)
{
INT16
i
,
newplayernum
,
botcount
=
1
;
player_t
*
newplayer
;
INT8
skinnum
=
0
,
bot
;
for
(
i
=
0
;
i
<
MAXPLAYERS
;
i
++
)
{
if
(
!
playeringame
[
i
])
break
;
if
(
players
[
i
].
bot
)
botcount
++
;
// How many of us are there already?
}
if
(
i
>=
MAXPLAYERS
)
{
lua_pushnil
(
L
);
return
1
;
}
newplayernum
=
i
;
//if (!splitscreen && !botingame)
CL_ClearPlayer
(
newplayernum
);
playeringame
[
newplayernum
]
=
true
;
G_AddPlayer
(
newplayernum
);
newplayer
=
&
players
[
newplayernum
];
newplayer
->
jointime
=
0
;
newplayer
->
quittime
=
0
;
// I hereby name you Bot X
strcpy
(
player_names
[
newplayernum
],
va
(
"Bot %d"
,
botcount
));
// Read the skin string!
if
(
!
lua_isnoneornil
(
L
,
1
))
{
skinnum
=
R_SkinAvailable
(
luaL_checkstring
(
L
,
1
));
skinnum
=
skinnum
<
0
?
0
:
skinnum
;
}
// Read the color!
if
(
!
lua_isnoneornil
(
L
,
2
))
newplayer
->
skincolor
=
R_GetColorByName
(
luaL_checkstring
(
L
,
2
));
else
newplayer
->
skincolor
=
skins
[
newplayer
->
skin
].
prefcolor
;
// Read the bot name, if given!
if
(
!
lua_isnoneornil
(
L
,
3
))
strcpy
(
player_names
[
newplayernum
],
luaL_checkstring
(
L
,
3
));
bot
=
luaL_optinteger
(
L
,
4
,
3
);
newplayer
->
bot
=
(
bot
>=
0
&&
bot
<=
3
)
?
bot
:
3
;
// Set the skin (needed to set bot first!)
SetPlayerSkinByNum
(
newplayernum
,
skinnum
);
if
(
netgame
)
{
char
joinmsg
[
256
];
strcpy
(
joinmsg
,
M_GetText
(
"
\x82
*Bot %s has joined the game (player %d)"
));
strcpy
(
joinmsg
,
va
(
joinmsg
,
player_names
[
newplayernum
],
newplayernum
));
HU_AddChatText
(
joinmsg
,
false
);
}
LUA_PushUserdata
(
L
,
newplayer
,
META_PLAYER
);
return
0
;
}
static
int
Lcheckmapnumber
(
lua_State
*
L
,
int
idx
,
const
char
*
fun
)
static
int
Lcheckmapnumber
(
lua_State
*
L
,
int
idx
,
const
char
*
fun
)
{
{
if
(
ISINLEVEL
)
if
(
ISINLEVEL
)
...
@@ -3987,6 +4063,7 @@ static luaL_Reg lib[] = {
...
@@ -3987,6 +4063,7 @@ static luaL_Reg lib[] = {
// g_game
// g_game
{
"G_AddGametype"
,
lib_gAddGametype
},
{
"G_AddGametype"
,
lib_gAddGametype
},
{
"G_AddPlayer"
,
lib_gAddPlayer
},
{
"G_BuildMapName"
,
lib_gBuildMapName
},
{
"G_BuildMapName"
,
lib_gBuildMapName
},
{
"G_BuildMapTitle"
,
lib_gBuildMapTitle
},
{
"G_BuildMapTitle"
,
lib_gBuildMapTitle
},
{
"G_FindMap"
,
lib_gFindMap
},
{
"G_FindMap"
,
lib_gFindMap
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment