diff --git a/changelog.txt b/changelog.txt index 2d53f202c..a7a2b0332 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,8 @@ EQEMu Changelog (Started on Sept 24, 2003 15:50) ------------------------------------------------------- +== 01/18/2014 == +sorvani: Implemented for Lua eq.get_characters_in_instance(uint16 instance_id), return a Lua HashTable + == 01/13/2014 == Kayen: Numerous minor fixes to spell effects. Kayen: Changed SE_ArcheryDoubleAttack -> SE_DoubleRangedAttack (now works with throwing ect) diff --git a/common/database.cpp b/common/database.cpp index 0ea3b8861..ace5bf4ea 100644 --- a/common/database.cpp +++ b/common/database.cpp @@ -2834,6 +2834,26 @@ uint16 Database::GetInstanceID(uint32 zone, uint32 charid, int16 version) return 0; } +void Database::GetCharactersInInstance(uint16 instance_id, std::list &charid_list) { + char errbuf[MYSQL_ERRMSG_SIZE]; + char *query = 0; + MYSQL_RES *result; + MYSQL_ROW row; + + if (RunQuery(query, MakeAnyLenString(&query, "SELECT charid FROM instance_lockout_player WHERE id=%u", instance_id), errbuf, &result)) { + safe_delete_array(query); + while ((row = mysql_fetch_row(result))) + { + charid_list.push_back(atoi(row[0])); + } + mysql_free_result(result); + } + else { + LogFile->write(EQEMuLog::Error, "Error in GetCharactersInInstace query '%s': %s", query, errbuf); + safe_delete_array(query); + } +} + void Database::AssignGroupToInstance(uint32 gid, uint32 instance_id) { char errbuf[MYSQL_ERRMSG_SIZE]; diff --git a/common/database.h b/common/database.h index 849f6f63d..300fc9875 100644 --- a/common/database.h +++ b/common/database.h @@ -163,6 +163,7 @@ public: uint16 GetInstanceVersion(uint16 instance_id); uint16 GetInstanceID(const char* zone, uint32 charid, int16 version); uint16 GetInstanceID(uint32 zone, uint32 charid, int16 version); + void GetCharactersInInstance(uint16 instance_id, std::list &charid_list); void AssignGroupToInstance(uint32 gid, uint32 instance_id); void AssignRaidToInstance(uint32 rid, uint32 instance_id); void FlagInstanceByGroupLeader(uint32 zone, int16 version, uint32 charid, uint32 gid); diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 5bddbd2c3..571432783 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -781,6 +781,21 @@ int lua_get_zone_instance_version() { return zone->GetInstanceVersion(); } +luabind::object lua_get_characters_in_instance(lua_State *L, uint16 instance_id) { + luabind::object ret = luabind::newtable(L); + + std::list charid_list; + uint16 i = 1; + database.GetCharactersInInstance(instance_id,charid_list); + auto iter = charid_list.begin(); + while(iter != charid_list.end()) { + ret[i] = *iter; + ++i; + ++iter; + } + return ret; +} + int lua_get_zone_weather() { if(!zone) return 0; @@ -1164,6 +1179,7 @@ luabind::scope lua_register_general() { luabind::def("create_instance", &lua_create_instance), luabind::def("destroy_instance", &lua_destroy_instance), luabind::def("get_instance_id", &lua_get_instance_id), + luabind::def("get_characters_in_instance", &lua_get_characters_in_instance), luabind::def("assign_to_instance", &lua_assign_to_instance), luabind::def("assign_group_to_instance", &lua_assign_group_to_instance), luabind::def("assign_raid_to_instance", &lua_assign_raid_to_instance),