ArcEmu: [c++] Getting Started - Basic Creature Script Tutorial! - ArcEmu

Jump to content

Toggle shoutbox Lastest Announcements

dfighter  : (07 December 2014 - 12:06 PM) Arcemu is in hibernation mode, please read http://arcemu.org/fo...showtopic=26903
dfighter  : (01 January 2013 - 05:56 PM) Arcemu wishes you all a happy new year!
Hasbro  : (12 September 2012 - 10:01 AM) Please excuse our outage from the web! Our web host had a major malfunction!
dfighter  : (01 September 2012 - 04:05 PM) Since the spam bots just don't want to stop, I've enabled admin verification when registering.
dfighter  : (23 January 2012 - 09:56 PM) Please note that from now on you will need to confirm your email on the wiki in order to edit it!
Hasbro  : (31 December 2011 - 12:50 PM) Happy New Years all!
Navid  : (26 December 2011 - 04:09 AM) Merry Christmas !!!!!! Happy holidays all :)
WAmadeus  : (24 December 2011 - 03:54 PM) Merry Christmas to all!
dfighter  : (24 December 2011 - 11:05 AM) The Arcemu team wishes y'all a Merry Christmukkah!
Hasbro  : (05 October 2011 - 12:53 PM) Looking for web designers for upcoming web related project. If you're interested in designing user interfaces contact me
dfighter  : (02 September 2011 - 03:47 PM) So who here wants vehicles in Arcemu? :P http://arcemu.org/fo...showtopic=25440
Hasbro  : (14 August 2011 - 03:25 PM) Join us on irc, grab an irc client and connect to irc.freenode.net join channel #arcemu /server irc.freenode.net:6667 /join #arcemu
jackpoz  : (03 August 2011 - 05:33 AM) to all Lua Engine (old one) users: please check http://arcemu.org/fo...showtopic=25274
Hasbro  : (20 May 2011 - 05:27 PM) Looking for people experienced with CMake configuration and setup! Contact me asap
Hasbro  : (15 May 2011 - 05:03 PM) ArcEmu is recruiting C++ programmers, contact Hasbro if interested.
paroxysm  : (03 May 2011 - 06:26 PM) Updated luabridge gossip example to describe the whole gossip creation process rather than just how to create menu. Gossip tutorial
paroxysm  : (23 April 2011 - 11:35 AM) Lua writers can refer to the Luabridge Tutorials section in the Wiki to learn how to write gossip code correctly.
Hasbro  : (20 April 2011 - 05:22 PM) Thank you for your continuous contribution of bug reports, we are working on them.
Hasbro  : (17 April 2011 - 03:20 AM) Please consider donating to support our bills. Donations can be sent using PayPal to donations@arcemu.org - Thank you for your support.
paroxysm  : (10 April 2011 - 12:43 AM) Refer to the Luabridge Tutorials section in the Wiki to learn the new syntax of luabridge.
Resize Shouts Area

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[c++] Getting Started - Basic Creature Script Tutorial! Learn basic usage of MoonScriptCreatureAI Class, simple and easy!

#1 User is offline   Azolex 

  • Member
  • Group: Contributor
  • Posts: 54
  • Joined: 08-August 08
  • Gender:Male
  • Location:Serbia
  • Interests:Music, Computers, School and Girls!

Posted 29 January 2010 - 05:49 PM

Hello, i think it was about time to write scripting documentation!

Here are main requirements:
~ Basic programming knowladge ( Nothing particular just definitions/basic code knowladge )
~ Basic AI knowledge ( For example events, movement and what else you want to use )
~ Will -- Most important thing


Lesson #1 -- Class constructors ->

What is class constructor? class constructor is place where we ( scripters in this case ) will store spells, emotes and assign other variables for they future use. Class constructor for Creature AI in ArcEmu is triggered when creature it self is constructed, and loaded/spawned ( Creature - AI Holder ). I will show you what do you need to place in constructor:

class NameOfAI : public MoonScriptCreatureAI // we declare class and inerhate MoonScriptCreatureAI so we can use base handlers for AI
{
         /// assign parent class 
         MOONSCRIPT_FACTORY_FUNCTION( NameOfAI, MoonScriptCreatureAI ); // left -- this class, right parent clasl
         NameOfAI(Creature* pCreature) : MoonScriptCreatureAI(pCreature) // class constructor!
         {
                // example
                AddSpell( 5, Target_Current, 25, 0, 1 );
                
                AddEmote( Event_OnCombatStart, "I am example!" );

                // assign some class var
                randVar = 5; // 5 phases for example or he repeats p1 5 times or w/e you want to use it for
         }; 

    uint32 randVar; // here we actually declare var but without any value
}; 


So what i did in code above in class constructor is just assigned, added stuff( spells, emotes and some numbers) for future usage.
See ya in lesson #2 for explanation of events!

Lesson #2 -- Events ->

Each time something happens to ai holder corresponding event is triggered, example when we attack npc he will enter combat triggering enter combat event( OnCombatStart with Unit argument that are we, the attackers )
Or maybe when AI holder kills us as last target he will trigger 2 events, OnCombatStop with unit argument and OnTargetDied again unit argument in this case we are that unit :P. Here is example how to take advantage of that!

class NameOfAI : public MoonScriptCreatureAI // we declare class and inerhate MoonScriptCreatureAI so we can use base handlers for AI
{
         /// assign parent class 
         MOONSCRIPT_FACTORY_FUNCTION( NameOfAI, MoonScriptCreatureAI ); // left -- this class, right parent clasl
         NameOfAI(Creature* pCreature) : MoonScriptCreatureAI(pCreature) // class constructor!
         {
                // example
                AddSpell( 5, Target_Current, 25, 0, 1 );
                
                AddEmote( Event_OnCombatStart, "I am example!" );

                // assign some class var
                randVar = 5; // 5 phases for example or he repeats p1 5 times or w/e you want to use it for
         }; 
		
		void OnCombatStart( Unit* pTarget )
		{
			MoveTo( pTarget ); // lets move to target that attacked us
			_unit->CastSpell( pTarget, 11, true ); // and lets for example attack him with spell
			// there are milion of possibilities!
			
			// ParentClass 
			ParentClass::OnCombatStart( pTarget ); // we will now do default parent class event handler( in this case on Combat start! )
			// it will do default base class operations for this events such as do emotes for this AI/creature or start timers...
		};
		
		void OnCombatStop( Unit* pTarget )
		{
			randVar = 5; // lets re-assign randVar to 5 just as example
			
			ParentClass::OnCombatStop( pTarget ); // lets again let base class handle event on its own
		};
    uint32 randVar; // here we actually declare var but without any value
};


You can find a list of events in MoonScriptCreatureAI library.
All events have handler by default but if you want to add something to it you need to make sure base class does it part, that is what ParentClass::Event(arg); is for!
You ofc do not need to use it if you dont want.
Next lesson #3 functions!

Lesson #3 -- Functions ->

In scripting functions are main part, it allows you to script, functions here are like instructions to npc/ai that will make npc fallow them.
There are also functions that don't instruct npc to do anything but do some server side operation, for example gets instance script or gets nearest creature, etc.

Function example:
MoveTo( Unit* pUnit );
MoveTo -- name of functions
Unit* pUnit -- argument of functions

Library: < CoomingSoon! >
Posted Image
1

#2 User is offline   Darren 

  • Occasional Poster
  • PipPip
  • Group: Members
  • Posts: 104
  • Joined: 18-June 08

Posted 31 January 2010 - 07:02 AM

Very useful, thanks :blink:
0

#3 User is offline   Azolex 

  • Member
  • Group: Contributor
  • Posts: 54
  • Joined: 08-August 08
  • Gender:Male
  • Location:Serbia
  • Interests:Music, Computers, School and Girls!

Posted 02 February 2010 - 06:14 AM

Ill add library to wiki and link it soon, also instance scirpt tutorial etc...no time atm
Posted Image
0

#4 User is offline   OuttCastt 

  • Member
  • Pip
  • Group: Members
  • Posts: 73
  • Joined: 13-September 08
  • Location:Hilo,Hawaii

Posted 13 February 2010 - 02:21 AM

Very nice, could you possibly set up a tutorial for gossip scripts?
Owner Of the Kingdom Of Many-Arrows

I am 43% addicted to World of Warcraft. What about you?
Excues me blizzard there is this guy named Hasbro on Arcemu.org and he wont let me download his private server emulator! can you please send me a copy tankz
0

#5 User is offline   ckrat67 

  • Member
  • Pip
  • Group: Members
  • Posts: 24
  • Joined: 12-October 09

Posted 23 February 2010 - 09:47 AM

good can you tell me something about instance scripts modifications in the VCproj be4 compiling to fix bugs?
0

#6 User is offline   HalestormXV 

  • The Ultimatum
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,031
  • Joined: 07-June 08
  • Gender:Male

Posted 27 February 2010 - 01:31 PM

Mind if i spread this guide around with credits to you of course? And is it really still MoonScriptCreatureAI? I thought it was ArcScriptCreatureAI? Unless I am thinking of bosses?
**Owner of the Serenade of Sorrow Funserver**
My Most Recent Video: The Book of Kidou
Posted Image
0

#7 User is offline   Guruman 

  • Newbie
  • Group: Members
  • Posts: 1
  • Joined: 31-May 10
  • Gender:Male

Posted 31 May 2010 - 03:11 PM

Thanks! This was really useful. Gave me a better insight of scripting.
0

#8 User is offline   lesone 

  • Enthusiast
  • Group: Retired
  • Posts: 294
  • Joined: 07-June 08
  • Gender:Male
  • Location:Zpain
  • Interests:Programming--
  • Server OS:Windows

Posted 01 June 2010 - 05:05 AM

Azolex going to PIN this topic.

Good info.
lesone-
Posted Image
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users