Info1
November 11, 2016, 6:27pm
1
Hi, why doesn’t that code work ?
class spell_gen_base_attack_custom : public SpellScriptLoader
{
public:
spell_gen_base_attack_custom() : SpellScriptLoader(“spell_gen_base_attack_custom”) { }
class spell_gen_base_attack_custom_SpellScript : public SpellScript
{
void OnSpellCast(Player* player, Spell* spell, bool skipCheck)
{
if (!player)
return;
if (player->GetTypeId() == INVTYPE_2HWEAPON)
player->CastSpell(player, 90023, true);
if (player->GetTypeId() == INVTYPE_WEAPONMAINHAND && !INVTYPE_2HWEAPON)
player->CastSpell(player, 90025, true);
if (player->GetTypeId() == INVTYPE_WEAPONMAINHAND && INVTYPE_WEAPONOFFHAND)
player->CastSpell(player, 90025, true);
player->CastSpell(player, 90026, true);
}
};
SpellScript* GetSpellScript() const override
{
return new spell_gen_base_attack_custom_SpellScript();
}
};
Does it give any errors? I’m new to C++ so diagnosing with errors is hard enough, No errors and you’ve thrown me to the wolves…
Info1
November 11, 2016, 6:42pm
3
I have a error on
return new spell_gen_base_attack_custom_SpellScript();
Compiles fine, just doesn’t do what you want it to?
Do you have it in the scriptloader?
Info1
November 11, 2016, 6:48pm
7
The code is in spell_generic.cpp
spell_generic.cpp is already in the scriptloader
— Canned message start —
This thread is not related to the official Trinity codebase and was moved to the Custom Code section.
Please read the stickies next time.
— Canned message end —
Info1
November 11, 2016, 8:31pm
9
if 2H weapon equiped, that cast a spell
if 1H weapon equiped, that cast an other spell
Rochet2
November 11, 2016, 9:35pm
10
you are missing https://github.com/TrinityCore/TrinityCore/blob/a249d86b00eb0854cb925f8bea76ddbb364208df/src/server/scripts/Spells/spell_warrior.cpp#L93 that.
However the hook is also wrong…
Spellscript doesnt have such a hook. And even if it does, you usually would need to register hooks like this: https://github.com/TrinityCore/TrinityCore/blob/a249d86b00eb0854cb925f8bea76ddbb364208df/src/server/scripts/Spells/spell_warrior.cpp#L114-L118
Though there may be exceptions to that. For example this: https://github.com/TrinityCore/TrinityCore/blob/8ff5b35be1256d03b85438b130dcec7cd4cae6e1/src/server/game/Spells/SpellScript.h#L279
OnSpellCast is defined here, not in the spellscript: [https://github.com/TrinityCore/TrinityCore/blob/a249d86b00eb0854cb925f8bea76ddbb364208df/src/server/game/Scripting/ScriptMgr.h#L710](https://github.com/TrinityCore/TrinityCore/blob/a249d86b00eb0854cb925f8bea76ddbb364208df/src/server/game/Scripting/ScriptMgr.h#L710)
Info1
November 12, 2016, 11:57am
11
My new script, don’t works… 12 errors about & and ==
class spell_cus_base_attack : public SpellScriptLoader
{
public:
spell_cus_base_attack() : SpellScriptLoader(“spell_cus_base_attack”) { }
class spell_cus_base_attack_SpellScript : public SpellScript
{
PrepareSpellScript(spell_cus_base_attack_SpellScript);
void HandleDummy(SpellEffIndex /* index */)
{
Unit* caster = GetCaster();
if (!caster)
return;
if (caster->GetTypeId == INVTYPE_2HWEAPON)
{
caster->CastSpell(caster, 90023, true);
}
if (caster->GetTypeId == INVTYPE_WEAPONMAINHAND && caster->GetTypeId =! INVTYPE_2HWEAPON)
{
caster->CastSpell(caster, 90023, true);
}
if (caster->GetTypeId == INVTYPE_WEAPONMAINHAND && caster->GetTypeId =! INVTYPE_WEAPONOFFHAND)
{
caster->CastSpell(caster, 90023, true);
}
}
void Register()
{
OnEffectHitTarget += SpellEffectFn(spell_cus_base_attack_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
}
};
SpellScript * GetSpellScript() const
{
return new spell_cus_base_attack_SpellScript;
}
};