-
Notifications
You must be signed in to change notification settings - Fork 6.2k
c++ SCript for the Quest Zero Tolerance and spellfix spell_zuldrak_gymers_grab #31196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 3.3.5
Are you sure you want to change the base?
Conversation
based on this Commit TrinityCore#30286 (comment) I personally think that the whole thing can be designed better with c++, so here is my c++ idea Here's my link with the C++ code and two videos TrinityCore#30286 (comment)
Fix Register AI Class
} | ||
|
||
enum Events | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this must be outside of class
npc_servant_of_drakuruAI(Creature* creature) | ||
: ScriptedAI(creature), _controller(nullptr), _checkTimer(1000), _controlled(false) | ||
{ | ||
_events.Reset(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't manipulate EventMap in ctor
|
||
void SpellHit(WorldObject* caster, SpellInfo const* spell) override | ||
{ | ||
if (!spell) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpellInfo cannot ever be null here
{ | ||
if (caster && caster->GetTypeId() == TYPEID_PLAYER) | ||
{ | ||
Player* player = caster->ToPlayer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is redundant, cast ToPlayer and then check for nullability in that case
|
||
void UpdateAI(uint32 diff) override | ||
{ | ||
if (_controlled) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this checks per ms, use an event to delay the checks by 500ms-1s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Essentially, the script does exactly what it's supposed to, and therefore there were no compilation errors in the logs or in the game.
I assumed it was solid code that I had created with the help of a friend from back then. You can see in the video that it does what it's supposed to.
But okay, I'm not a professional programmer and I'm not afraid of corrections during the learning phase. So I'm sorry my first attempt isn't good enough for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just because a piece of code doesn't throw errors, exceptions, or cause crashes doesn't mean it's optimized to its best. You don't need to check that particular case every tick of Update, it's okay to delay it by 500-1000ms to optimize resources; it's not a deal of not being good enough for me, it's just a suggestion you can take or leave.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just because a piece of code doesn't throw errors, exceptions, or cause crashes doesn't mean it's optimized to its best. You don't need to check that particular case every tick of Update, it's okay to delay it by 500-1000ms to optimize resources; it's not a deal of not being good enough for me, it's just a suggestion you can take or leave.
That wasn't what I meant. I'll take it to heart and try to optimize it. As I said, I'm still learning and don't know everything yet, and this is my first attempt at a PR. When I get home, I'll try to implement it, so there's a one-time delay. You're right that once the action is completed, no further updates are necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have now revised it and would like to submit it as is.
#include "ScriptMgr.h"
#include "Creature.h"
#include "SpellInfo.h"
#include "Unit.h"
#include "Player.h"
#include "ScriptedCreature.h"
enum
{
SPELL_TRIGGER_ID = 52390,
NPC_ENTRY_CONTROLLED = 28805,
QUEST_ID = 12686,
SPELL_CAST = 50361,
EVENT_CAST_SPELL = 1,
EVENT_CONTROL_CHECK = 2,
};
class npc_servant_of_drakuru : public CreatureScript
{
public:
npc_servant_of_drakuru() : CreatureScript("npc_servant_of_drakuru") {}
struct npc_servant_of_drakuruAI : public ScriptedAI
{
npc_servant_of_drakuruAI(Creature* creature): ScriptedAI(creature), _controller(nullptr), _controlled(false) { }
void JustEngagedWith(Unit* /*who*/) override
{
_events.Reset();
_events.ScheduleEvent(EVENT_CAST_SPELL, 4s);
_events.ScheduleEvent(EVENT_CONTROL_CHECK, 1s);
}
void SpellHit(WorldObject* caster, SpellInfo const* spell) override
{
if (spell->Id == SPELL_TRIGGER_ID)
{
if (Player* player = caster->ToPlayer())
{
if (player->GetQuestStatus(QUEST_ID) == QUEST_STATUS_INCOMPLETE)
{
_controller = player;
Talk(0);
me->UpdateEntry(NPC_ENTRY_CONTROLLED);
me->SetHealth(me->GetMaxHealth());
_controlled = true;
}
}
}
}
void UpdateAI(uint32 diff) override
{
_events.Update(diff);
while (uint32 eventId = _events.ExecuteEvent())
{
switch (eventId)
{
case EVENT_CAST_SPELL:
if (!_controlled)
{
if (Unit* target = me->GetVictim())
me->CastSpell(target, SPELL_CAST, true);
}
_events.ScheduleEvent(EVENT_CAST_SPELL, 12s, 14s);
break;
case EVENT_CONTROL_CHECK:
if (_controlled)
{
if (me->GetCharmerOrOwner() != _controller)
{
if (_controller && _controller->GetQuestStatus(QUEST_ID) == QUEST_STATUS_INCOMPLETE)
me->DespawnOrUnsummon(1s, 3s);
_controlled = false;
_controller = nullptr;
_events.Reset();
return;
}
}
_events.ScheduleEvent(EVENT_CONTROL_CHECK, 1s);
break;
}
}
if (!_controlled)
ScriptedAI::UpdateAI(diff);
}
private:
EventMap _events;
Player* _controller;
bool _controlled;
};
CreatureAI* GetAI(Creature* creature) const override
{
return new npc_servant_of_drakuruAI(creature);
}
};
void AddSC_npc_servant_of_drakuru()
{
new npc_servant_of_drakuru();
}
Code optimization and I hope it's ok this time ^^
you may want to put sql code in a file inside 3.3.5 update path too. |
Do I have to send it separately as a PR? |
separate file, in same PR, you can temporary name it 2025_99_99_99_world.sql |
Okay, I'll give it a try ^^ |
SQL for the PR Quest Zero Tolerance: TrinityCore#31196
ok i have added the SQL File |
Missing Healing Effect after grabbed the Storm Cloud with this fix now works
Fix Spellscript spell_zuldrak_gymers_grab
if (GetHitCreature()->GetEntry() == NPC_STORM_CLOUD) // Storm Cloud | ||
GetHitCreature()->CastSpell(GetCaster(), SPELL_HEALING_WINDS, true); // Healing Winds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (GetHitCreature()->GetEntry() == NPC_STORM_CLOUD) // Storm Cloud | |
GetHitCreature()->CastSpell(GetCaster(), SPELL_HEALING_WINDS, true); // Healing Winds | |
if (GetHitCreature()->GetEntry() == NPC_STORM_CLOUD) // Storm Cloud | |
GetHitCreature()->CastSpell(GetCaster(), SPELL_HEALING_WINDS, true); // Healing Winds |
Isnt here missing space ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah it is
Apparently, reading the comments here, they don't want my fixes. It was worth a try. |
based on this Commit #30286 (comment)
I personally think that the whole thing can be designed better with c++, so here is my c++ idea
Here's my link with the C++ code and two videos
#30286 (comment)
This is my first PR so please forgive me if I forgot something