Post by Erictemponi on May 6, 2017 21:34:31 GMT -3
Para este tutorial, levarei em conta que você já tem o Script que quer adicionar salvado com a extensão CPP (.cpp).
Depois de ter salvado o script, você precisa copiá-lo e colá-lo na pasta dos Scripts Personalizados, que fica em Core\src\server\scripts\Custom
Se você abrir um Script C++ com o algum editor de texto, verá que no final dele sempre terá um bagulho parecido com este:
void AddSC_my_script()
{
new my_script_class();
}
Tanto o my_script() quanto o my_script_class(); vão mudar de script para script, vai depender do nome da função do mesmo, mas isso não importa, o que importa é que você achou o void. Independentemente de qual seja o script, todos terão um void no final, que é a declaração da função do script (não vou entrar em detalhes técnicos).
Dentro da pasta Custom terá um arquivo chamado "custom_script_loader.cpp", abra ele. Por padrão, será assim:
/*
* Copyright (C) 2008-2017 TrinityCore <www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <www.gnu.org/licenses/>.
*/
// This is where scripts' loading functions should be declared:
// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
void AddCustomScripts()
{
}
Logo abaixo de
// This is where scripts' loading functions should be declared:
você vai colocar o void do seu script e acrescentará um ponto e vírgula ( depois dele.
E dentro das chaves ({ }) do
void AddCustomScripts()
{
}
você adiciona o void, só que sem a palavra void, você vai adicionar a partir do AddSC, ficando assim:
/*
* Copyright (C) 2008-2017 TrinityCore <www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <www.gnu.org/licenses/>.
*/
// This is where scripts' loading functions should be declared:
void AddSC_my_script();
// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
void AddCustomScripts()
{
AddSC_my_script();
}
Feito isso, salve o arquivo "custom_script_loader.cpp" e feche-o. Agora é só recompilar seu servidor (desde a parte do CMake).
OBS: Se der erro na hora da compilação, provavelmente o seu Script está desatualizado. Aí o que tem pra fazer é procurar um já atualizado ou atualizar o script você mesmo ou pedir para alguém atualizar ou removê-lo.
Beleza, até aqui tudo bem, agora vamos "linkar" o script C++ ao banco de dados para funcionar certinho. Não entendeu o que eu falei? Veja bem, se você adicionar um Script C++ de um NPC, você precisará vincular tal script a algum NPC, correto? Então, é isso que vamos fazer agora.
Para você linkar um Script C++ de um NPC a um NPC qualquer é muito simples, basta você definir este NPC como gossip e adicionar o ScriptName do seu Script nele.
Para definir um NPC como gossip você precisa mudar as flags dele para 1 (Gossip). Você faz isso no seu Banco de Dados world, tabela creature_template, coluna npcflag (basta mudar para 1)
Ainda na tabela creature_template tem uma coluna chamada ScriptName. É nela que você adicionará o ScriptName do seu Script, o qual você encontrará dentro do próprio script, que virá sempre deste jeito:
public:
my_script_class() : CreatureScript("my_script") { }
O my_script sempre será o seu ScriptName, aí é só você adicionar ele lá na coluna ScriptName.
Feito isso, reinicie seu servidor e seja feliz.
Depois de ter salvado o script, você precisa copiá-lo e colá-lo na pasta dos Scripts Personalizados, que fica em Core\src\server\scripts\Custom
Se você abrir um Script C++ com o algum editor de texto, verá que no final dele sempre terá um bagulho parecido com este:
void AddSC_my_script()
{
new my_script_class();
}
Tanto o my_script() quanto o my_script_class(); vão mudar de script para script, vai depender do nome da função do mesmo, mas isso não importa, o que importa é que você achou o void. Independentemente de qual seja o script, todos terão um void no final, que é a declaração da função do script (não vou entrar em detalhes técnicos).
Dentro da pasta Custom terá um arquivo chamado "custom_script_loader.cpp", abra ele. Por padrão, será assim:
/*
* Copyright (C) 2008-2017 TrinityCore <www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <www.gnu.org/licenses/>.
*/
// This is where scripts' loading functions should be declared:
// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
void AddCustomScripts()
{
}
Logo abaixo de
// This is where scripts' loading functions should be declared:
você vai colocar o void do seu script e acrescentará um ponto e vírgula ( depois dele.
E dentro das chaves ({ }) do
void AddCustomScripts()
{
}
você adiciona o void, só que sem a palavra void, você vai adicionar a partir do AddSC, ficando assim:
/*
* Copyright (C) 2008-2017 TrinityCore <www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <www.gnu.org/licenses/>.
*/
// This is where scripts' loading functions should be declared:
void AddSC_my_script();
// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
void AddCustomScripts()
{
AddSC_my_script();
}
Feito isso, salve o arquivo "custom_script_loader.cpp" e feche-o. Agora é só recompilar seu servidor (desde a parte do CMake).
OBS: Se der erro na hora da compilação, provavelmente o seu Script está desatualizado. Aí o que tem pra fazer é procurar um já atualizado ou atualizar o script você mesmo ou pedir para alguém atualizar ou removê-lo.
Beleza, até aqui tudo bem, agora vamos "linkar" o script C++ ao banco de dados para funcionar certinho. Não entendeu o que eu falei? Veja bem, se você adicionar um Script C++ de um NPC, você precisará vincular tal script a algum NPC, correto? Então, é isso que vamos fazer agora.
Para você linkar um Script C++ de um NPC a um NPC qualquer é muito simples, basta você definir este NPC como gossip e adicionar o ScriptName do seu Script nele.
Para definir um NPC como gossip você precisa mudar as flags dele para 1 (Gossip). Você faz isso no seu Banco de Dados world, tabela creature_template, coluna npcflag (basta mudar para 1)
Ainda na tabela creature_template tem uma coluna chamada ScriptName. É nela que você adicionará o ScriptName do seu Script, o qual você encontrará dentro do próprio script, que virá sempre deste jeito:
public:
my_script_class() : CreatureScript("my_script") { }
O my_script sempre será o seu ScriptName, aí é só você adicionar ele lá na coluna ScriptName.
Feito isso, reinicie seu servidor e seja feliz.