mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-03-20 09:52:18 +00:00
Merge branch 'more-lua-map-names' into 'next'
G_BuildMapTitle for Lua, G_BuildMapName outside of levels See merge request STJr/SRB2!694
This commit is contained in:
commit
4eeae51cbb
2 changed files with 42 additions and 3 deletions
|
@ -2898,15 +2898,50 @@ static int lib_gAddGametype(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int Lcheckmapnumber (lua_State *L, int idx, const char *fun)
|
||||
{
|
||||
if (ISINLEVEL)
|
||||
return luaL_optinteger(L, idx, gamemap);
|
||||
else
|
||||
{
|
||||
if (lua_isnoneornil(L, idx))
|
||||
{
|
||||
return luaL_error(L,
|
||||
"%s can only be used without a parameter while in a level.",
|
||||
fun
|
||||
);
|
||||
}
|
||||
else
|
||||
return luaL_checkinteger(L, idx);
|
||||
}
|
||||
}
|
||||
|
||||
static int lib_gBuildMapName(lua_State *L)
|
||||
{
|
||||
INT32 map = luaL_optinteger(L, 1, gamemap);
|
||||
INT32 map = Lcheckmapnumber(L, 1, "G_BuildMapName");
|
||||
//HUDSAFE
|
||||
INLEVEL
|
||||
lua_pushstring(L, G_BuildMapName(map));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_gBuildMapTitle(lua_State *L)
|
||||
{
|
||||
INT32 map = Lcheckmapnumber(L, 1, "G_BuildMapTitle");
|
||||
char *name;
|
||||
if (map < 1 || map > NUMMAPS)
|
||||
{
|
||||
return luaL_error(L,
|
||||
"map number %d out of range (1 - %d)",
|
||||
map,
|
||||
NUMMAPS
|
||||
);
|
||||
}
|
||||
name = G_BuildMapTitle(map);
|
||||
lua_pushstring(L, name);
|
||||
Z_Free(name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_gDoReborn(lua_State *L)
|
||||
{
|
||||
INT32 playernum = luaL_checkinteger(L, 1);
|
||||
|
@ -3292,6 +3327,7 @@ static luaL_Reg lib[] = {
|
|||
// g_game
|
||||
{"G_AddGametype", lib_gAddGametype},
|
||||
{"G_BuildMapName",lib_gBuildMapName},
|
||||
{"G_BuildMapTitle",lib_gBuildMapTitle},
|
||||
{"G_DoReborn",lib_gDoReborn},
|
||||
{"G_SetCustomExitVars",lib_gSetCustomExitVars},
|
||||
{"G_EnoughPlayersFinished",lib_gEnoughPlayersFinished},
|
||||
|
|
|
@ -99,5 +99,8 @@ void COM_Lua_f(void);
|
|||
// uncomment if you want seg_t/node_t in Lua
|
||||
// #define HAVE_LUA_SEGS
|
||||
|
||||
#define INLEVEL if (gamestate != GS_LEVEL && !titlemapinaction)\
|
||||
#define ISINLEVEL \
|
||||
(gamestate == GS_LEVEL || titlemapinaction)
|
||||
|
||||
#define INLEVEL if (! ISINLEVEL)\
|
||||
return luaL_error(L, "This can only be used in a level!");
|
||||
|
|
Loading…
Reference in a new issue