Keep Out Npc

I though this was an interesting one to script, and probably many people would need it too. /emoticons/default_smile.png

[CODE]-- Keep Out
SET @ENTRY := 78713;
DELETE FROM creature_template WHERE entry=@ENTRY;
INSERT INTO creature_template( entry,difficulty_entry_1,difficulty_entry_2,difficulty_entry_3,KillCredit1,KillCredit2,modelid1,modelid2,modelid3,modelid4,name,subname,IconName,gossip_menu_id,minlevel,maxlevel,exp,faction_A,faction_H,npcflag,speed_walk,speed_run,scale,rank,mindmg,maxdmg,dmgschool,attackpower,dmg_multiplier,baseattacktime,rangeattacktime,unit_class,unit_flags,dynamicflags,family,trainer_type,trainer_spell,trainer_class,trainer_race,minrangedmg,maxrangedmg,rangedattackpower,type,type_flags,lootid,pickpocketloot,skinloot,resistance1,resistance2,resistance3,resistance4,resistance5,resistance6,spell1,spell2,spell3,spell4,spell5,spell6,spell7,spell8,PetSpellDataId,VehicleId,mingold,maxgold,AIName,MovementType,InhabitType,Health_mod,Mana_mod,Armor_mod,RacialLeader,questItem1,questItem2,questItem3,questItem4,questItem5,questItem6,movementId,RegenHealth,equipment_id,mechanic_immune_mask,flags_extra,ScriptName,WDBVerified)VALUES
(@ENTRY,0,0,0,0,0,262,0,0,0,“Keep Out”,“You shouldn’t be here”,“”,0,255,255,0,35,35,0,1.5,1.5,1,1,1,1,0,1,1,1,1,1,390,0,0,0,0,0,0,1,1,1,10,8,0,0,0,500,500,500,500,500,500,0,0,0,0,0,0,0,0,0,0,0,0,“”,0,1,1,1,2.5,0,0,0,0,0,0,0,0,8,0,0,0,“npc_keep_out”,-1);[/sql]

Basic Keep Out NPC, teleports away anyone without a GM tag who gets within 15 yards of the creature.

[code]/*######

npc_keep_out

######*/

class npc_keep_out : public CreatureScript
{
public:
npc_keep_out() : CreatureScript(“npc_keep_out”) { }

	struct npc_keep_outAI : public ScriptedAI
	{
		npc_keep_outAI(Creature* creature) : ScriptedAI(creature) { }

		void MoveInLineOfSight(Unit* who)
		{
			if (!who)
				return;

			if (Player* player = who->ToPlayer())
			{
				if (player->isGameMaster()) // Only if GM tag is on we will ignore, else we will teleport this player as well
					return;

				if (!player->IsBeingTeleported() && me->IsWithinDist(player, 15.0f))
					player->TeleportTo(player->m_homebindMapId, player->m_homebindX, player->m_homebindY, player->m_homebindZ, player->GetOrientation());
			}
		}
	};

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

};[/code]

This one teleports players away if they are below a certain level. Just change the ‘xx’ to the level you want to restrict.

[spoiler][code]

/*######

npc_keep_out

######*/

class npc_keep_out : public CreatureScript
{
public:
npc_keep_out() : CreatureScript(“npc_keep_out”) { }

	struct npc_keep_outAI : public ScriptedAI
	{
		npc_keep_outAI(Creature* creature) : ScriptedAI(creature) { }

		void MoveInLineOfSight(Unit* who)
		{
			if (!who)
				return;

			if (Player* player = who->ToPlayer())
			{
				if (player->isGameMaster()) // Only if GM tag is on we will ignore, else we will teleport this player as well
					return;

				if (!player->IsBeingTeleported() && me->IsWithinDist(player, 15.0f))
					if (player->getLevel() <= xx)
						player->TeleportTo(player->m_homebindMapId, player->m_homebindX, player->m_homebindY, player->m_homebindZ, player->GetOrientation());
			}
		}
	};

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

};
[/code]
[/spoiler]

[/CODE]

That’s nice… I’m using almost the same script for some triggers.

Updated.

Yo discover I got a cool idea about this script, is it possible that instead of teleporting people away, then if people move within 15 yards of the creature they are unable to use any gm commands? Would like to spawn this dude then in ALOT of pvp areas /emoticons/default_smile.png

And, you don’t need to put anything in scriptloader.cpp to load this script?

Since ive added this script in my Custom folder, and defined it in CMakeLists.txt, but i cant put anything into scriptloader.cpp and the script aint working ingame

You need