daora ![]()
bem útil mesmo, rep+
será que funciona no tfs 0.2 '-'?
----------
acho que pode ser util pro negocio que eu tava fazendo, de mandar msgs em cores..
function onWriteToChannel(cid, channelId, text)
local acess = {
[1] = "branca",
[2] = "azul",
[3] = "vermelho"
}
for _, k in pairs(getPlayersOnline()) do
return doPlayerSendTextMessage(k, acess[getPlayerAcess(cid)], text)
end
end






info
Grupo: Marquês
Registrado: 05/07/09
Posts: 1.3k
Reputação: +732
Nome: onWriteToChannel(cid, channelId, text)
Tipo: Código C++
Autor: Colandus, Oneshot (Adaptação 0.4 + Default Channel)
Fala, galera.
Esse é um código C++ que serve como add-on para o seu servidor, ele adiciona um novo tipo de função para os creaturescripts, que é executado toda vez que um jogador envia uma mensagem ao servidor.
Foi criado por Colandus e estou trazendo ao XTibia por ser um código muito útil e interessante de se usar nos servidores.
Lembrando que os passos abaixo devem ser seguidos em um IDE de sua preferência para posterior compilação.
Em creatureevent.h, procure por:
Adicione logo abaixo:
Ainda em creatureevent.h, procure por:
Adicione abaixo:
Agora em creaturescripts.cpp, logo abaixo de:
Adicione:
Abaixo de:
Adicione:
Abaixo de:
Adicione:
Logo após o fim da função:
Adicione:
uint32_t CreatureEvent::executeChannelWrite(Player* player, uint16_t channelId, std::string text) { //onWriteToChannel(cid, channel, text) if(m_scriptInterface->reserveScriptEnv()) { ScriptEnviroment* env = m_scriptInterface->getScriptEnv(); if(m_scripted == EVENT_SCRIPT_BUFFER) { env->setRealPos(player->getPosition()); std::stringstream scriptstream; scriptstream << "local cid = " << env->addThing(player) << std::endl; scriptstream << "local channel = " << channelId << std::endl; scriptstream << "local text = " << text << std::endl; scriptstream << m_scriptData; bool result = true; if(m_scriptInterface->loadBuffer(scriptstream.str()) != -1) { lua_State* L = m_scriptInterface->getLuaState(); result = m_scriptInterface->getGlobalBool(L, "_result", true); } m_scriptInterface->releaseScriptEnv(); return result; } else { #ifdef __DEBUG_LUASCRIPTS__ char desc[35]; sprintf(desc, "%s", player->getName().c_str()); env->setEventDesc(desc); #endif env->setScriptId(m_scriptId, m_scriptInterface); env->setRealPos(player->getPosition()); lua_State* L = m_scriptInterface->getLuaState(); m_scriptInterface->pushFunction(m_scriptId); lua_pushnumber(L, env->addThing(player)); lua_pushnumber(L, channelId); lua_pushstring(L, text.c_str()); bool result = m_scriptInterface->callFunction(3); m_scriptInterface->releaseScriptEnv(); return result; } } else { std::cout << "[Error - CreatureEvent::executeChannelWrite] Call stack overflow." << std::endl; return 0; } }0.4
uint32_t CreatureEvent::executeChannelWriteTo(Player* player, uint16_t channelId, std::string text) { //onWriteToChannel(cid, channel, text) if(m_interface->reserveEnv()) { ScriptEnviroment* env = m_interface->getEnv(); if(m_scripted == EVENT_SCRIPT_BUFFER) { env->setRealPos(player->getPosition()); std::stringstream scriptstream; scriptstream << "local cid = " << env->addThing(player) << std::endl; scriptstream << "local channel = " << channelId << std::endl; scriptstream << "local text = " << text << std::endl; scriptstream << m_scriptData; bool result = true; if(m_interface->loadBuffer(scriptstream.str()) != -1) { lua_State* L = m_interface->getState(); result = m_interface->getGlobalBool(L, "_result", true); } m_interface->releaseEnv(); return result; } else { #ifdef __DEBUG_LUASCRIPTS__ char desc[35]; sprintf(desc, "%s", player->getName().c_str()); env->setEventDesc(desc); #endif env->setScriptId(m_scriptId, m_interface); env->setRealPos(player->getPosition()); lua_State* L = m_interface->getState(); m_interface->pushFunction(m_scriptId); lua_pushnumber(L, env->addThing(player)); lua_pushnumber(L, channelId); lua_pushstring(L, text.c_str()); bool result = m_interface->callFunction(3); m_interface->releaseEnv(); return result; } } else { std::cout << "[Error - CreatureEvent::executeChannelWrite] Call stack overflow." << std::endl; return 0; } }Em game.cpp, procure pela função:
Acima de:
if(player->isAccountManager()) { if(mute) player->removeMessageBuffer(); return internalCreatureSay(player, SPEAK_SAY, text, false); }Adicione:
Finalmente no chat.cpp, procure pela função:
Acima de:
Adicione:
Exemplo de Uso:
function onWriteToChannel(cid, channelId, text) if text:lower():find(".servegame.com") then doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "É proibido divulgar servidores aqui.") return false end return true endSão várias as possibilidades de uso.
Abraços.
Editado Julho 17 por Oneshot