mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-03-21 18:32:08 +00:00
* Add R_SkinUsable to Lua.
* Make R_SetPlayerSkin check for usability of skin before setting, and error otherwise.
This commit is contained in:
parent
2f22547889
commit
acc13c1a4a
1 changed files with 43 additions and 5 deletions
|
@ -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},
|
||||
|
|
Loading…
Reference in a new issue