mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-08 17:48:46 -10:00
130 lines
3.5 KiB
C++
130 lines
3.5 KiB
C++
//
|
|
//
|
|
|
|
#include "player.h"
|
|
|
|
#include "playerman/player.h"
|
|
#include "mission/missioncampaign.h"
|
|
#include "menuui/mainhallmenu.h"
|
|
|
|
namespace scripting {
|
|
namespace api {
|
|
|
|
|
|
//**********HANDLE: Player
|
|
ADE_OBJ(l_Player, int, "player", "Player handle");
|
|
|
|
ADE_FUNC(isValid, l_Player, NULL, "Detects whether handle is valid", "boolean", "true if valid, false if handle is invalid, nil if a syntax/type error occurs")
|
|
{
|
|
int idx;
|
|
if(!ade_get_args(L, "o", l_Player.Get(&idx)))
|
|
return ADE_RETURN_NIL;
|
|
|
|
if (idx < 0 || idx >= MAX_PLAYERS)
|
|
return ADE_RETURN_FALSE;
|
|
|
|
return ADE_RETURN_TRUE;
|
|
}
|
|
|
|
ADE_FUNC(getName, l_Player, NULL, "Gets current player name", "string", "Player name, or empty string if handle is invalid")
|
|
{
|
|
int idx;
|
|
if(!ade_get_args(L, "o", l_Player.Get(&idx)))
|
|
return ade_set_error(L, "s", "");
|
|
|
|
if (idx < 0 || idx >= MAX_PLAYERS)
|
|
return ade_set_error(L, "s", "");
|
|
|
|
return ade_set_args(L, "s", Players[idx].callsign);
|
|
}
|
|
|
|
ADE_FUNC(getCampaignFilename, l_Player, NULL, "Gets current player campaign filename", "string", "Campaign name, or empty string if handle is invalid")
|
|
{
|
|
int idx;
|
|
if(!ade_get_args(L, "o", l_Player.Get(&idx)))
|
|
return ade_set_error(L, "s", "");
|
|
|
|
if (idx < 0 || idx >= MAX_PLAYERS)
|
|
return ade_set_error(L, "s", "");
|
|
|
|
return ade_set_args(L, "s", Players[idx].current_campaign);
|
|
}
|
|
|
|
ADE_FUNC(getImageFilename, l_Player, NULL, "Gets current player image filename", "string", "Player image filename, or empty string if handle is invalid")
|
|
{
|
|
int idx;
|
|
if(!ade_get_args(L, "o", l_Player.Get(&idx)))
|
|
return ade_set_error(L, "s", "");
|
|
|
|
if (idx < 0 || idx >= MAX_PLAYERS)
|
|
return ade_set_error(L, "s", "");
|
|
|
|
return ade_set_args(L, "s", Players[idx].image_filename);
|
|
}
|
|
|
|
ADE_FUNC(getMainHallName, l_Player, NULL, "Gets player's current main hall name", "string", "Main hall name, or name of first mainhall in campaign if something goes wrong")
|
|
{
|
|
SCP_string hallname;
|
|
// FS2-->Lua
|
|
if (Campaign.next_mission == -1) {
|
|
hallname = Campaign.missions[0].main_hall;
|
|
} else {
|
|
hallname = Campaign.missions[Campaign.next_mission].main_hall;
|
|
}
|
|
|
|
return ade_set_args(L, "i", hallname.c_str());
|
|
}
|
|
|
|
// use getMainHallName if at all possible.
|
|
ADE_FUNC(getMainHallIndex, l_Player, NULL, "Gets player's current main hall number", "number", "Main hall index, or index of first mainhall in campaign if something goes wrong")
|
|
{
|
|
int hallnum = 0;
|
|
//FS2-->Lua
|
|
if (Campaign.next_mission == -1) {
|
|
hallnum = main_hall_get_index(Campaign.missions[0].main_hall);
|
|
} else {
|
|
hallnum = main_hall_get_index(Campaign.missions[Campaign.next_mission].main_hall);
|
|
}
|
|
|
|
return ade_set_args(L, "i", hallnum);
|
|
}
|
|
|
|
ADE_FUNC(getSquadronName, l_Player, NULL, "Gets current player squad name", "string", "Squadron name, or empty string if handle is invalid")
|
|
{
|
|
int idx;
|
|
if(!ade_get_args(L, "o", l_Player.Get(&idx)))
|
|
return ade_set_error(L, "s", "");
|
|
|
|
if (idx < 0 || idx >= MAX_PLAYERS)
|
|
return ade_set_error(L, "s", "");
|
|
|
|
return ade_set_args(L, "s", Players[idx].s_squad_name);
|
|
}
|
|
|
|
ADE_FUNC(getMultiSquadronName, l_Player, NULL, "Gets current player multi squad name", "string", "Squadron name, or empty string if handle is invalid")
|
|
{
|
|
int idx;
|
|
if(!ade_get_args(L, "o", l_Player.Get(&idx)))
|
|
return ade_set_error(L, "s", "");
|
|
|
|
if (idx < 0 || idx >= MAX_PLAYERS)
|
|
return ade_set_error(L, "s", "");
|
|
|
|
return ade_set_args(L, "s", Players[idx].m_squad_name);
|
|
}
|
|
|
|
//WMC - This isn't working
|
|
/*
|
|
ADE_FUNC(getSquadronImage, l_Player, NULL, "Squad image (string)", "Gets current player squad image")
|
|
{
|
|
int idx;
|
|
player_helper(L, &idx);
|
|
|
|
return ade_set_args(L, "s", Players[idx].squad_filename);
|
|
}*/
|
|
|
|
|
|
}
|
|
}
|
|
|