[Help] MoveInLineOfSight

Core/Scripts: Blade’ Edge Mountains NPC support · fc51e8c · Trista/TrinityCore · GitHub

Triying to improve this script, fixed almost all except 1 thing:

These cannons currently shoot, if there is any movement in 40 range. The problem is it only triggers when you do move. But if you stay idle flying* at one place this function is not called.

I’ve searched scripts and it seems there is no call for only, if being in range ooc.

So my question is the first time when the player is registered and shoot at, can’t he be stored somewhere somehow and called with another function that will trigger spell when he is idle in the same range?

I kinda have idea how is this handled. I suspect there are 2 npcs /and judging on wowhead there are/. One of them shoots on move and the other one shoots after the first one data set on it to inform it was shooted. So basicly we can handle the 2nd one with SAI on data set to spawn and shoot at /the stored target/. I’m pretty sure this can be done, but I don’t know how, so can anyone help with the storing + sending part? So far I see one problem the first one only check for the movement target coordinates it doesn’t store anyhting from it and that is not good for what I said. I need the player that moved to be stored. /this npc will have flag_extra 128.

updateai?

Can I use something like this for check, it isn’t finished at all, just can’t think what to use for player in range check trigger that repeats.

[SPOILER]{
public:
npc_legion_flak_cannon() : CreatureScript(“npc_legion_flak_cannon”) { }

		    struct npc_legion_flak_cannonAI : public Scripted_NoMovementAI
		    {
				    npc_legion_flak_cannonAI(Creature* creature) : Scripted_NoMovementAI(creature) { }

				    bool canShoot;
				    uint32 searchTimer;
				    uint32 shootTimer;
				    uint64 m_uiTargetGUID;

                    void Reset()
				    {
						    canShoot = true;							   
						    m_uiTargetGUID = 0;
                    	    searchTimer = 500;
                    }

				    void UpdateAI(const uint32 diff)
                    {
                        if (!UpdateVictim())
							    return;
                        me->SelectNearestPlayer(50.0f);
					    if (Unit* target = Unit::GetPlayer(*me, m_uiTargetGUID))
                        {
								    // Should not only attack when player is in air, but also on ground with a flying mount
								    if (target->HasAuraType(SPELL_AURA_FLY) || target->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED))
								    {
										    me->SetFacingToObject(target);

										    if (Creature* bunny = me->SummonCreature(NPC_FEL_CANNON_DUMMY, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ()))
											    DoCast(bunny, SPELL_FEL_CANNON_BOLT);

										    shootTimer = 3500;
										    canShoot = false;
								    }
						    }

						    if (!canShoot)
						    {
								    if (shootTimer <= diff)
										    canShoot = true;
								    else
										    shootTimer -= diff;
						    }
				    }
		    };

		    CreatureAI* GetAI(Creature* creature) const
		    {
				    return new npc_legion_flak_cannonAI(creature);
		    }

};

class npc_legion_flak_cannon : public CreatureScript

[/SPOILER]

[/SPOILER]
me->SelectNearestPlayer(50.0f);

if (Unit* target = Unit::GetPlayer(*me, m_uiTargetGUID))

can be simplified to if(Player* target = me->FindNearestPlayer(50.0f)) dunno if the argument list of the function is larger but the function itself shoudl work