• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Imbuiment System tfs 1.2

Lais Prad

Disgusting Scammer
Joined
Apr 12, 2017
Messages
153
Solutions
6
Reaction score
15
We need fix somethings, if someone can help...
there we go:

modules.cpp
/**
* This file doesn't belong to theforgottenserver developers.
*/

#include "otpch.h"

#include "modules.h"
#include "player.h"

Modules::Modules() :
scriptInterface("Modules Interface")
{
scriptInterface.initState();
}

Modules::~Modules()
{
for (const auto& it : recvbyteList) {
delete it.second;
}
}

void Modules::clear()
{
//clear recvbyte list
for (const auto& it : recvbyteList) {
it.second->clearEvent();
}

//clear lua state
scriptInterface.reInitState();
}

LuaScriptInterface& Modules::getScriptInterface()
{
return scriptInterface;
}

std::string Modules::getScriptBaseName() const
{
return "modules";
}

Event* Modules::getEvent(const std::string& nodeName)
{
if (strcasecmp(nodeName.c_str(), "module") != 0) {
return nullptr;
}
return new Module(&scriptInterface);
}

bool Modules::registerEvent(Event* event, const pugi::xml_node&)
{
Module* module = static_cast<Module*>(event);
if (module->getEventType() == MODULE_TYPE_NONE) {
std::cout << "Error: [Modules::registerEvent] Trying to register event without type!" << std::endl;
return false;
}

Module* oldModule = getEventByRecvbyte(module->getRecvbyte(), false);
if (oldModule) {
if (!oldModule->isLoaded() && oldModule->getEventType() == module->getEventType()) {
oldModule->copyEvent(module);
}
return false;
} else {
recvbyteList[module->getRecvbyte()] = module;
return true;
}
}

Module* Modules::getEventByRecvbyte(uint8_t recvbyte, bool force)
{
ModulesList::iterator it = recvbyteList.find(recvbyte);
if (it != recvbyteList.end()) {
if (!force || it->second->isLoaded()) {
return it->second;
}
}
return nullptr;
}

void Modules::executeOnRecvbyte(Player* player, NetworkMessage& msg, uint8_t byte)
{
for (const auto& it : recvbyteList) {
Module* module = it.second;
if (module->getEventType() == MODULE_TYPE_RECVBYTE && module->getRecvbyte() == byte && player->canRunModule(module->getRecvbyte())) {
player->setModuleDelay(module->getRecvbyte(), module->getDelay());
module->executeOnRecvbyte(player, msg);
return;
}
}
}
/////////////////////////////////////

Module::Module(LuaScriptInterface* interface) :
Event(interface), type(MODULE_TYPE_NONE), loaded(false) {}

bool Module::configureEvent(const pugi::xml_node& node)
{
delay = 0;

pugi::xml_attribute typeAttribute = node.attribute("type");
if (!typeAttribute) {
std::cout << "[Error - Modules::configureEvent] Missing type for module." << std::endl;
return false;
}

std::string tmpStr = asLowerCaseString(typeAttribute.as_string());
if (tmpStr == "recvbyte") {
pugi::xml_attribute byteAttribute = node.attribute("byte");
if (!byteAttribute) {
std::cout << "[Error - Modules::configureEvent] Missing byte for module typed recvbyte." << std::endl;
return false;
}

recvbyte = static_cast<uint8_t>(byteAttribute.as_int());
type = MODULE_TYPE_RECVBYTE;
} else {
std::cout << "[Error - Modules::configureEvent] Invalid type for module." << std::endl;
return false;
}

pugi::xml_attribute delayAttribute = node.attribute("delay");
if (delayAttribute) {
delay = static_cast<uint16_t>(delayAttribute.as_uint());
}

loaded = true;
return true;
}

std::string Module::getScriptEventName() const
{
switch (type) {
case MODULE_TYPE_RECVBYTE:
return "onRecvbyte";
default:
return std::string();
}
}

void Module::copyEvent(Module* module)
{
m_scriptId = module->m_scriptId;
m_scriptInterface = module->m_scriptInterface;
m_scripted = module->m_scripted;
loaded = module->loaded;
}

void Module::clearEvent()
{
m_scriptId = 0;
m_scriptInterface = nullptr;
m_scripted = false;
loaded = false;
}

void Module::executeOnRecvbyte(Player* player, NetworkMessage& msg)
{
//onAdvance(player, skill, oldLevel, newLevel)
if (!m_scriptInterface->reserveScriptEnv()) {
std::cout << "[Error - CreatureEvent::executeAdvance] Call stack overflow" << std::endl;
return;
}

ScriptEnvironment* env = m_scriptInterface->getScriptEnv();
env->setScriptId(m_scriptId, m_scriptInterface);

lua_State* L = m_scriptInterface->getLuaState();

m_scriptInterface->pushFunction(m_scriptId);
LuaScriptInterface::pushUserdata<Player>(L, player);
LuaScriptInterface::setMetatable(L, -1, "Player");

LuaScriptInterface::pushUserdata<NetworkMessage>(L, const_cast<NetworkMessage*>(&msg));
LuaScriptInterface::setWeakMetatable(L, -1, "NetworkMessage");

lua_pushnumber(L, recvbyte);

m_scriptInterface->callVoidFunction(3);
}
 
To be honest modules is not supposed to be used like that otherwise you won't get benefits and will struggle sometimes with some connections with other functions in items for example. When I first made it was used to creatr premium store which has to do with market. That caused me to move market to lua as well. And finally I did same for almost everything. You might do it in c++ for better sake as it doesn't make much sense in modules.
 
Which I mean that u said u made it available for free while u already take free sources made by others and referred it to your self. Dont act like u made even a huge progress here while I dont see a single benefit of it. I don't blame that u took any sources from anywhere but don't refer it to yourself.
 
Oh nice, you are publishing my imbuement system (incomplete) i have full source codes, but without put credits of modules to our friend Slavi Dodo and Cjaker (me :D) you are a poor user.

You are copying-parse my IMBUEMENT SYSTEM (incomplete) without credits, just go to hell.
 
Oh nice, you are publishing my imbuement system (incomplete) i have full source codes, but without put credits of modules to our friend Slavi Dodo and Cjaker (me :D) you are a poor user.

You are copying-parse my IMBUEMENT SYSTEM (incomplete) without credits, just go to hell.
I'm poor user? lol
I just separeted the codes and put here for free, my work was separate files, check diff and some edits.
I dont know the creator of this system, but now I know.
 
@Yuggi
Send me that "documentation" blah.
Only i can see a user where is trying to own the credits.

@Lais Prad
Because in your post put in final "unknow credits".
Sry anyway for the "poor user" :v
 
Back
Top