mirror of
https://github.com/edubart/otclient.git
synced 2025-10-16 04:24:54 +02:00
add option custom user script, otclientrc.lua
This commit is contained in:
@@ -286,6 +286,10 @@ void Application::registerLuaFunctions()
|
||||
g_lua.bindClassStaticFunction<Logger>("fireOldMessages", std::bind(&Logger::fireOldMessages, &g_logger));
|
||||
g_lua.bindClassStaticFunction<Logger>("setOnLog", std::bind(&Logger::setOnLog, &g_logger, _1));
|
||||
|
||||
// Lua
|
||||
g_lua.registerStaticClass("g_lua");
|
||||
g_lua.bindClassStaticFunction("g_lua", "runScript", std::bind(&LuaInterface::runScript, &g_lua, _1));
|
||||
|
||||
// UI
|
||||
g_lua.registerStaticClass("g_ui");
|
||||
g_lua.bindClassStaticFunction("g_ui", "importStyle", std::bind(&UIManager::importStyle, &g_ui, _1));
|
||||
|
@@ -268,6 +268,11 @@ int Game::getThingStackpos(const ThingPtr& thing)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Game::talk(const std::string& message)
|
||||
{
|
||||
talkChannel(1, 0, message);
|
||||
}
|
||||
|
||||
void Game::talkChannel(int channelType, int channelId, const std::string& message)
|
||||
{
|
||||
if(!m_online || !checkBotProtection())
|
||||
|
@@ -58,6 +58,7 @@ public:
|
||||
void follow(const CreaturePtr& creature);
|
||||
void cancelFollow();
|
||||
void rotate(const ThingPtr& thing);
|
||||
void talk(const std::string& message);
|
||||
void talkChannel(int channelType, int channelId, const std::string& message);
|
||||
void talkPrivate(int channelType, const std::string& receiver, const std::string& message);
|
||||
void inviteToParty(int creatureId);
|
||||
|
@@ -108,6 +108,9 @@ void OTClient::registerLuaFunctions()
|
||||
g_lua.bindClassStaticFunction<Game>("removeVip", std::bind(&Game::removeVip, &g_game, _1));
|
||||
g_lua.bindClassStaticFunction<Game>("getAttackingCreature", std::bind(&Game::getAttackingCreature, &g_game));
|
||||
g_lua.bindClassStaticFunction<Game>("getFollowingCreature", std::bind(&Game::getFollowingCreature, &g_game));
|
||||
g_lua.bindClassStaticFunction<Game>("talk", std::bind(&Game::talk, &g_game, _1));
|
||||
g_lua.bindClassStaticFunction<Game>("talkChannel", std::bind(&Game::talkChannel, &g_game, _1, _2, _3));
|
||||
g_lua.bindClassStaticFunction<Game>("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3));
|
||||
|
||||
g_lua.registerClass<UIItem, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); } );
|
||||
@@ -125,8 +128,4 @@ void OTClient::registerLuaFunctions()
|
||||
g_lua.registerClass<UIGame, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UIGame>("create", []{ return UIGamePtr(new UIGame); } );
|
||||
|
||||
#ifdef FORBIDDEN_FUNCTIONS
|
||||
g_lua.bindClassStaticFunction<Game>("talkChannel", std::bind(&Game::talkChannel, &g_game, _1, _2, _3));
|
||||
g_lua.bindClassStaticFunction<Game>("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3));
|
||||
#endif
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@
|
||||
#include "otclient.h"
|
||||
#include <framework/core/modulemanager.h>
|
||||
#include "core/game.h"
|
||||
#include <framework/core/resourcemanager.h>
|
||||
|
||||
OTClient::OTClient() : Application(Otc::AppCompactName)
|
||||
{
|
||||
@@ -38,4 +39,13 @@ void OTClient::init(const std::vector<std::string>& args)
|
||||
g_modules.autoLoadModules(100);
|
||||
g_modules.ensureModuleLoaded("client");
|
||||
g_modules.autoLoadModules(1000);
|
||||
|
||||
// load otclientrc.lua
|
||||
if(g_resources.fileExists("/otclientrc.lua")) {
|
||||
try {
|
||||
g_lua.runScript("/otclientrc.lua");
|
||||
} catch(LuaException& e) {
|
||||
logError("failed to load otclientrc.lua: ", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ bool UIGame::onKeyPress(uchar keyCode, std::string keyText, int keyboardModifier
|
||||
g_game.walk(Otc::NorthWest);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyReturn || keyCode == Fw::KeyEnter) {
|
||||
g_game.talkChannel(1, 0, chatLineEdit->getText());
|
||||
g_game.talk(chatLineEdit->getText());
|
||||
chatLineEdit->clearText();
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyDelete) {
|
||||
|
Reference in New Issue
Block a user