mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-13 23:01:30 +00:00
Small bug fixes with encounters, also added eq.load_encounter_with_data(encounter_name, data_string) and unload as well. Allows you to send a message via the encounter system load
This commit is contained in:
parent
b417e23d97
commit
1619324d06
@ -39,10 +39,63 @@ void load_encounter(std::string name) {
|
|||||||
parse->EventEncounter(EVENT_ENCOUNTER_LOAD, name, 0);
|
parse->EventEncounter(EVENT_ENCOUNTER_LOAD, name, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void load_encounter_with_data(std::string name, std::string info_str) {
|
||||||
|
std::vector<EQEmu::Any> info_ptrs;
|
||||||
|
info_ptrs.push_back(&info_str);
|
||||||
|
parse->EventEncounter(EVENT_ENCOUNTER_LOAD, name, 0, &info_ptrs);
|
||||||
|
}
|
||||||
|
|
||||||
void unload_encounter(std::string name) {
|
void unload_encounter(std::string name) {
|
||||||
|
auto liter = lua_encounter_events_registered.begin();
|
||||||
|
while(liter != lua_encounter_events_registered.end()) {
|
||||||
|
std::list<lua_registered_event> &elist = liter->second;
|
||||||
|
auto iter = elist.begin();
|
||||||
|
while(iter != elist.end()) {
|
||||||
|
if((*iter).encounter_name.compare(name) == 0) {
|
||||||
|
iter = elist.erase(iter);
|
||||||
|
} else {
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(elist.size() == 0) {
|
||||||
|
lua_encounter_events_registered.erase(liter++);
|
||||||
|
} else {
|
||||||
|
++liter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
parse->EventEncounter(EVENT_ENCOUNTER_UNLOAD, name, 0);
|
parse->EventEncounter(EVENT_ENCOUNTER_UNLOAD, name, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void unload_encounter_with_data(std::string name, std::string info_str) {
|
||||||
|
|
||||||
|
auto liter = lua_encounter_events_registered.begin();
|
||||||
|
while(liter != lua_encounter_events_registered.end()) {
|
||||||
|
std::list<lua_registered_event> &elist = liter->second;
|
||||||
|
auto iter = elist.begin();
|
||||||
|
while(iter != elist.end()) {
|
||||||
|
if((*iter).encounter_name.compare(name) == 0) {
|
||||||
|
iter = elist.erase(iter);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(elist.size() == 0) {
|
||||||
|
lua_encounter_events_registered.erase(liter++);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
++liter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<EQEmu::Any> info_ptrs;
|
||||||
|
info_ptrs.push_back(&info_str);
|
||||||
|
parse->EventEncounter(EVENT_ENCOUNTER_UNLOAD, name, 0, &info_ptrs);
|
||||||
|
}
|
||||||
|
|
||||||
void register_event(std::string package_name, std::string name, int evt, luabind::adl::object func) {
|
void register_event(std::string package_name, std::string name, int evt, luabind::adl::object func) {
|
||||||
lua_registered_event e;
|
lua_registered_event e;
|
||||||
e.encounter_name = name;
|
e.encounter_name = name;
|
||||||
@ -55,7 +108,7 @@ void register_event(std::string package_name, std::string name, int evt, luabind
|
|||||||
elist.push_back(e);
|
elist.push_back(e);
|
||||||
lua_encounter_events_registered[package_name] = elist;
|
lua_encounter_events_registered[package_name] = elist;
|
||||||
} else {
|
} else {
|
||||||
std::list<lua_registered_event> elist = liter->second;
|
std::list<lua_registered_event> &elist = liter->second;
|
||||||
auto iter = elist.begin();
|
auto iter = elist.begin();
|
||||||
while(iter != elist.end()) {
|
while(iter != elist.end()) {
|
||||||
if(iter->event_id == evt && iter->encounter_name.compare(name) == 0) {
|
if(iter->event_id == evt && iter->encounter_name.compare(name) == 0) {
|
||||||
@ -66,7 +119,6 @@ void register_event(std::string package_name, std::string name, int evt, luabind
|
|||||||
}
|
}
|
||||||
|
|
||||||
elist.push_back(e);
|
elist.push_back(e);
|
||||||
lua_encounter_events_registered[package_name] = elist;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1141,6 +1193,8 @@ luabind::scope lua_register_general() {
|
|||||||
[
|
[
|
||||||
luabind::def("load_encounter", &load_encounter),
|
luabind::def("load_encounter", &load_encounter),
|
||||||
luabind::def("unload_encounter", &unload_encounter),
|
luabind::def("unload_encounter", &unload_encounter),
|
||||||
|
luabind::def("load_encounter_with_data", &load_encounter_with_data),
|
||||||
|
luabind::def("unload_encounter_with_data", &unload_encounter_with_data),
|
||||||
luabind::def("register_npc_event", ®ister_npc_event),
|
luabind::def("register_npc_event", ®ister_npc_event),
|
||||||
luabind::def("unregister_npc_event", &unregister_npc_event),
|
luabind::def("unregister_npc_event", &unregister_npc_event),
|
||||||
luabind::def("register_player_event", ®ister_player_event),
|
luabind::def("register_player_event", ®ister_player_event),
|
||||||
|
|||||||
@ -601,6 +601,12 @@ int LuaParser::_EventEncounter(std::string package_name, QuestEventID evt, std::
|
|||||||
lua_pushstring(L, encounter_name.c_str());
|
lua_pushstring(L, encounter_name.c_str());
|
||||||
lua_setfield(L, -2, "name");
|
lua_setfield(L, -2, "name");
|
||||||
|
|
||||||
|
if(extra_pointers) {
|
||||||
|
std::string *str = EQEmu::any_cast<std::string*>(extra_pointers->at(0));
|
||||||
|
lua_pushstring(L, str->c_str());
|
||||||
|
lua_setfield(L, -2, "data");
|
||||||
|
}
|
||||||
|
|
||||||
quest_manager.StartQuest(nullptr, nullptr, nullptr);
|
quest_manager.StartQuest(nullptr, nullptr, nullptr);
|
||||||
if(lua_pcall(L, 1, 1, 0)) {
|
if(lua_pcall(L, 1, 1, 0)) {
|
||||||
std::string error = lua_tostring(L, -1);
|
std::string error = lua_tostring(L, -1);
|
||||||
@ -839,7 +845,7 @@ void LuaParser::ReloadQuests() {
|
|||||||
if(f) {
|
if(f) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
if(luaL_dofile(L, "quests/global/script_init.lua")) {
|
if(luaL_dofile(L, path.c_str())) {
|
||||||
std::string error = lua_tostring(L, -1);
|
std::string error = lua_tostring(L, -1);
|
||||||
AddError(error);
|
AddError(error);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user