Merge branch 'skinusablua' into 'master'

Skin UsabLua

See merge request STJr/SRB2Internal!458
This commit is contained in:
MascaraSnake 2019-11-13 13:59:36 -05:00
commit 750e826310
1 changed files with 43 additions and 5 deletions

View File

@ -2205,27 +2205,64 @@ static int lib_rFrame2Char(lua_State *L)
static int lib_rSetPlayerSkin(lua_State *L)
{
player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
INT32 i = -1, j = -1;
NOHUD
INLEVEL
if (!player)
return LUA_ErrInvalid(L, "player_t");
j = (player-players);
if (lua_isnoneornil(L, 2))
return luaL_error(L, "argument #2 not given (expected number or string)");
else if (lua_type(L, 2) == LUA_TNUMBER) // skin number
{
INT32 i = luaL_checkinteger(L, 2);
if (i < 0 || i >= MAXSKINS)
return luaL_error(L, "skin number (argument #2) %d out of range (0 - %d)", i, MAXSKINS-1);
SetPlayerSkinByNum(player-players, i);
i = luaL_checkinteger(L, 2);
if (i < 0 || i >= numskins)
return luaL_error(L, "skin %d (argument #2) out of range (0 - %d)", i, numskins-1);
}
else // skin name
{
const char *skinname = luaL_checkstring(L, 2);
SetPlayerSkin(player-players, skinname);
i = R_SkinAvailable(skinname);
if (i == -1)
return luaL_error(L, "skin %s (argument 2) is not loaded", skinname);
}
if (!R_SkinUsable(j, i))
return luaL_error(L, "skin %d (argument 2) not usable - check with R_SkinUsable(player_t, skin) first.", i);
SetPlayerSkinByNum(j, i);
return 0;
}
static int lib_rSkinUsable(lua_State *L)
{
player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
INT32 i = -1, j = -1;
if (player)
j = (player-players);
else if (netgame || multiplayer)
return luaL_error(L, "player_t (argument #1) must be provided in multiplayer games");
if (lua_isnoneornil(L, 2))
return luaL_error(L, "argument #2 not given (expected number or string)");
else if (lua_type(L, 2) == LUA_TNUMBER) // skin number
{
i = luaL_checkinteger(L, 2);
if (i < 0 || i >= numskins)
return luaL_error(L, "skin %d (argument #2) out of range (0 - %d)", i, numskins-1);
}
else // skin name
{
const char *skinname = luaL_checkstring(L, 2);
i = R_SkinAvailable(skinname);
if (i == -1)
return luaL_error(L, "skin %s (argument 2) is not loaded", skinname);
}
lua_pushboolean(L, R_SkinUsable(j, i));
return 1;
}
// R_DATA
////////////
@ -2913,6 +2950,7 @@ static luaL_Reg lib[] = {
{"R_Char2Frame",lib_rChar2Frame},
{"R_Frame2Char",lib_rFrame2Char},
{"R_SetPlayerSkin",lib_rSetPlayerSkin},
{"R_SkinUsable",lib_rSkinUsable},
// r_data
{"R_CheckTextureNumForName",lib_rCheckTextureNumForName},