示例#1
0
// hud_get(self, id)
int ObjectRef::l_hud_get(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	RemotePlayer *player = getplayer(ref);
	if (player == NULL)
		return 0;

	u32 id = lua_tonumber(L, -1);

	HudElement *e = player->getHud(id);
	if (!e)
		return 0;

	lua_newtable(L);

	lua_pushstring(L, es_HudElementType[(u8)e->type].str);
	lua_setfield(L, -2, "type");

	push_v2f(L, e->pos);
	lua_setfield(L, -2, "position");

	lua_pushstring(L, e->name.c_str());
	lua_setfield(L, -2, "name");

	push_v2f(L, e->scale);
	lua_setfield(L, -2, "scale");

	lua_pushstring(L, e->text.c_str());
	lua_setfield(L, -2, "text");

	lua_pushnumber(L, e->number);
	lua_setfield(L, -2, "number");

	lua_pushnumber(L, e->item);
	lua_setfield(L, -2, "item");

	lua_pushnumber(L, e->dir);
	lua_setfield(L, -2, "direction");

	// Deprecated, only for compatibility's sake
	lua_pushnumber(L, e->dir);
	lua_setfield(L, -2, "dir");

	push_v3f(L, e->world_pos);
	lua_setfield(L, -2, "world_pos");

	return 1;
}
示例#2
0
// hud_get(self, id)
int ObjectRef::l_hud_get(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	RemotePlayer *player = getplayer(ref);
	if (player == NULL)
		return 0;

	u32 id = lua_tonumber(L, -1);

	HudElement *e = player->getHud(id);
	if (!e)
		return 0;
	push_hud_element(L, e);
	return 1;
}
示例#3
0
// hud_change(self, id, stat, data)
int ObjectRef::l_hud_change(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	RemotePlayer *player = getplayer(ref);
	if (player == NULL)
		return 0;

	u32 id = lua_isnumber(L, 2) ? lua_tonumber(L, 2) : -1;

	HudElement *e = player->getHud(id);
	if (!e)
		return 0;

	void *value = NULL;
	HudElementStat stat = read_hud_change(L, e, &value);

	getServer(L)->hudChange(player, id, stat, value);

	lua_pushboolean(L, true);
	return 1;
}
示例#4
0
// hud_change(self, id, stat, data)
int ObjectRef::l_hud_change(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	RemotePlayer *player = getplayer(ref);
	if (player == NULL)
		return 0;

	u32 id = lua_isnumber(L, 2) ? lua_tonumber(L, 2) : -1;

	HudElement *e = player->getHud(id);
	if (!e)
		return 0;

	HudElementStat stat = HUD_STAT_NUMBER;
	if (lua_isstring(L, 3)) {
		int statint;
		std::string statstr = lua_tostring(L, 3);
		stat = string_to_enum(es_HudElementStat, statint, statstr) ?
				(HudElementStat)statint : HUD_STAT_NUMBER;
	}

	void *value = NULL;
	switch (stat) {
		case HUD_STAT_POS:
			e->pos = read_v2f(L, 4);
			value = &e->pos;
			break;
		case HUD_STAT_NAME:
			e->name = luaL_checkstring(L, 4);
			value = &e->name;
			break;
		case HUD_STAT_SCALE:
			e->scale = read_v2f(L, 4);
			value = &e->scale;
			break;
		case HUD_STAT_TEXT:
			e->text = luaL_checkstring(L, 4);
			value = &e->text;
			break;
		case HUD_STAT_NUMBER:
			e->number = luaL_checknumber(L, 4);
			value = &e->number;
			break;
		case HUD_STAT_ITEM:
			e->item = luaL_checknumber(L, 4);
			value = &e->item;
			break;
		case HUD_STAT_DIR:
			e->dir = luaL_checknumber(L, 4);
			value = &e->dir;
			break;
		case HUD_STAT_ALIGN:
			e->align = read_v2f(L, 4);
			value = &e->align;
			break;
		case HUD_STAT_OFFSET:
			e->offset = read_v2f(L, 4);
			value = &e->offset;
			break;
		case HUD_STAT_WORLD_POS:
			e->world_pos = read_v3f(L, 4);
			value = &e->world_pos;
			break;
		case HUD_STAT_SIZE:
			e->size = read_v2s32(L, 4);
			value = &e->size;
			break;
	}

	getServer(L)->hudChange(player, id, stat, value);

	lua_pushboolean(L, true);
	return 1;
}