ArcEmu: Scripting In .net - 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

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Scripting In .net A wrapper to enable C#, vb.NET, C++/CLI as scripts

#1 User is offline   Cromon 

  • Occasional Poster
  • Group: Contributor
  • Posts: 118
  • Joined: 07-June 08
  • Gender:Male
  • Location:Switzerland

Posted 11 April 2010 - 04:46 AM

Hello everybody

Yesterday i had the idea to make it possible creating scripts in .NET as a lot of people find those languages a lot more comfortable then C++ and LUA. So i made a litte wrapper during the evening which gets loaded as DLL like any other in script_bin. You can then create DLLs in C# or VB.NET or if you like in C++/CLI and add this wrapper as reference and create this DLL into script_bin also. The wrapper loads these assembly on startup and creates an instance of the ScriptProvider class (example later). There you register the scripts. During runtime the wrapper serves as connector between the managed DLLs and the unmanaged code.

Here you can see what i implemented as an example yet in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WoW;

namespace Wrapper
{
    public class ScriptProvider : IScriptProvider
    {
        public ScriptProvider()
        {
        }

        public void InitLib(ScriptMgr init)
        {
            init.RegisterChatHook(new Scripting.ChatHook());
            init.RegisterCreatureAI(100, new Scripting.GnollScript());
        }
    }
}

namespace Scripting
{
    public class ChatHook : IOnChatHook
    {
        public void Execute(Player sender, string message)
        {
            uint newLevel = 0;
            if (uint.TryParse(message, out newLevel))
            {
                uint level = sender.GetUInt32Value(UnitFields.UNIT_FIELD_LEVEL);
                sender.SetUInt32Value(UnitFields.UNIT_FIELD_LEVEL, level + newLevel);
                sender.BroadcastMessage("Increased your level by " + newLevel);
            }

        }
    }

    public class GnollScript : ICreatureAI
    {
        public override void OnCombatStart(Unit attacker)
        {
            if (attacker is Player)
            {
                Vector pos = attacker.GetPosition();
                string msg = "Combat started by '" + ((Player)attacker).GetName() + "' ";
                msg += "at position (" + pos.x + "/" + pos.y + "/" + pos.z + ")!";
                ((Player)attacker).BroadcastMessage(msg);
            }
            else
                Console.WriteLine("Combat was not started by a player!");
        }
    }
}


Registering is very simple. You just need to have a class ScriptProvider in the namespace Wrapper which implements IScriptProvider. On startup then InitLib gets called.

Ok, but now what i wanted to discuss about:
What do you think about that? Should i continue adding further functions to that project (like GameobjectAI, dummyspells, ...)?

Greetings
Cromon
0

#2 User is offline   dfighter 

  • Titles are overrated
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Administrator
  • Posts: 5,189
  • Joined: 14-June 08
  • IRC:dfighter
  • Gender:Male
  • Server OS:Linux

Posted 11 April 2010 - 05:40 AM

http://www.arcemu.in...tle=.Net_Addons
"The demand for free goods is infinite."
0

#3 User is offline   Cromon 

  • Occasional Poster
  • Group: Contributor
  • Posts: 118
  • Joined: 07-June 08
  • Gender:Male
  • Location:Switzerland

Posted 11 April 2010 - 05:47 AM

Interesting, but as i can see its not longer being developed ;)

/Edit:
And is kinda limited
0

#4 User is offline   dfighter 

  • Titles are overrated
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Administrator
  • Posts: 5,189
  • Joined: 14-June 08
  • IRC:dfighter
  • Gender:Male
  • Server OS:Linux

Posted 11 April 2010 - 05:52 AM

View PostCromon, on 11 April 2010 - 05:47 AM, said:

Interesting, but as i can see its not longer being developed ;)

Well it was for Ascent, and the guy who did it is now the leader and lead developer of WCell.
I just thought you might find it useful ( meaning you don't have to start from scratch )
"The demand for free goods is infinite."
0

#5 User is offline   Cromon 

  • Occasional Poster
  • Group: Contributor
  • Posts: 118
  • Joined: 07-June 08
  • Gender:Male
  • Location:Switzerland

Posted 11 April 2010 - 06:26 AM

Ye, basically i think i already made more possible (atm i have GossipScripts, CreatureScripts and Hooks). And the downloadlink seems to be broken on the wiki.
0

#6 User is offline   Kirth 

  • Member
  • Pip
  • Group: Members
  • Posts: 72
  • Joined: 13-April 09
  • Gender:Male
  • Location:Candy Mountain
  • Interests:Chaaarlieeee!

Posted 11 April 2010 - 06:57 AM

Is there any source available so far? Please, pretty please continue this project <3. (I'd try to help to any extent, if you desire so).

Ps: Domii's coding example is horrible in that article D: .
0

#7 User is offline   Cromon 

  • Occasional Poster
  • Group: Contributor
  • Posts: 118
  • Joined: 07-June 08
  • Gender:Male
  • Location:Switzerland

Posted 11 April 2010 - 08:27 AM

I make the basic features then i make a SVN with the source. Its kinda easy to extend and i try to make it as clear as possible.

This one here shows the possibilities of GossipScripts and Item1Click shows some of the current features of the Player class
    public class TestGossip : IGossipScript
    {
        public override bool OnConstructMenu(Unit sender, Player target, GossipMenu menu)
        {
            if (!target.HasGMPermission())
                return false;

            ItemClickDlg Item3Click = delegate(Unit send, Player tar)
            {
                Console.WriteLine("Player '" + tar.GetName() + "' has clicked the third item!");
                return true;
            };

            menu.AddItem(1, "Menu 1", Item1Click);
            menu.AddItem(2, "Menu 2", Item2Click);
            menu.AddItem(3, "Menu 3", Item3Click);

            menu.SetTextID(197);
            return true;
        }

        public bool Item2Click(Unit sender, Player target)
        {
            if (sender is Creature)
            {
                Creature cr = (Creature)sender;
                cr.SendChatMessage("You have clicked the second item!");
            }
            return true;
        }

        public bool Item1Click(Unit sender, Player target)
        {
            target.BroadcastMessage("Clicked the first item!");
            target.AddItem(39267, 1);
            target.AddSpell(28132);
            target.IncreaseAllSkills(400);
            if (!target.HasQuestFinished(10000))
                target.SendNotification("You have to finish the quest 10000 first!");
            else
                target.TeleportTo(609, 100.0f, 200.0f, 300.0f);
            return true;
        }

    }

0

#8 User is offline   Kirth 

  • Member
  • Pip
  • Group: Members
  • Posts: 72
  • Joined: 13-April 09
  • Gender:Male
  • Location:Candy Mountain
  • Interests:Chaaarlieeee!

Posted 11 April 2010 - 10:04 AM

Looks beautiful so far ;).
0

#9 User is offline   arshem 

  • Member
  • Pip
  • Group: Members
  • Posts: 16
  • Joined: 29-March 10
  • Gender:Male

Posted 11 April 2010 - 04:53 PM

Looking good! Good Luck and let me know when you have updates ;) [SUBSCRIBING]
0

#10 User is offline   alleycat 

  • Helps so much & is so mature & gay
  • PipPipPipPipPip
  • Group: Members
  • Posts: 835
  • Joined: 25-July 08
  • Gender:Male

Posted 11 April 2010 - 08:34 PM

Looking nice :-D
I can haz cookie?
0

#11 User is offline   Cromon 

  • Occasional Poster
  • Group: Contributor
  • Posts: 118
  • Joined: 07-June 08
  • Gender:Male
  • Location:Switzerland

Posted 12 April 2010 - 02:46 AM

I think a first release on an SVN can be done soon. At the moment i am rewriting things to often and that would be bad for people writing scripts when they get incompatible ;). CreatureAI works now as it should, registring using an instance of the object (mgr.RegisterCreatureAI(100, new Scripts.GnollAI())) is kinda stupid as every instance of the NPC 50000 needs to have its own instance of the AI. So this again is done using the very nice delegates .NET provides.

As another feature you can add an arbitrary amount of AIUpdate-events with different intervals. Every AIUpdate-event gets an id with which you can modify the interval or stop it. This was optimized a lot this morning as it is now reusing finished ids (basically this removes the limitation of maximum 4 billion calls to StartAIUpdate :P, you just cant have more than 4 billion events at once) and the lifetime of an internal parameter is now fully safe until the end of the event.

Here is a very basic code for an example CreatureAI:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WoW;

namespace Wrapper
{
    public class ScriptProvider : IScriptProvider
    {
        public void InitLib(ScriptMgr mgr)
        {
            CreatureAIDlg createDlg = delegate()
            {
                return new Scripts.FireWorkNPC();
            };
            mgr.RegisterCreatureAI(50000, createDlg);
        }
    }
}

namespace Scripts
{
    public class FireWorkNPC : ICreatureAI
    {
        Random m_random;

        internal FireWorkNPC()
        {
            m_random = new Random((int)DateTime.Now.ToFileTime());
        }

        public void Firework1(uint id)
        {
            ModAIUpdate(id, (uint)m_random.Next(1000, 2000));
            _unit.CastSpell(11352, _unit, true);
        }

        public void Firework2(uint id)
        {
            ModAIUpdate(id, (uint)m_random.Next(1000, 2000));
            _unit.CastSpell(11544, _unit, true);
        }

        public void Firework3(uint id)
        {
            ModAIUpdate(id, (uint)m_random.Next(1000, 2000));
            _unit.CastSpell(26516, _unit, true);          
        }

        public override void OnLoad()
        {
            _unit.AddFieldFlag(UnitFields.UNIT_FIELD_FLAGS, 0x02000002); // -> Not attackable, not selectable, will make enum later :P
            uint intrv = (uint)m_random.Next(1000, 2000);
            StartAIUpdate(intrv, Firework1);
            intrv = (uint)m_random.Next(1000, 2000);
            StartAIUpdate(intrv, Firework2);
            intrv = (uint)m_random.Next(1000, 2000);
            StartAIUpdate(intrv, Firework3);
        }
    }
}

4

#12 User is offline   arshem 

  • Member
  • Pip
  • Group: Members
  • Posts: 16
  • Joined: 29-March 10
  • Gender:Male

Posted 12 April 2010 - 06:33 AM

AWESOME +1
0

#13 User is offline   Cromon 

  • Occasional Poster
  • Group: Contributor
  • Posts: 118
  • Joined: 07-June 08
  • Gender:Male
  • Location:Switzerland

Posted 12 April 2010 - 07:25 AM

If someone wants to test (its really a test, not a release, only beta ;)) its possible to download the project from
http://code.google.com/p/netmulation/

it contains a readme with the basic installation inside. It would be cool if i get some feedback!
0

#14 User is offline   alleycat 

  • Helps so much & is so mature & gay
  • PipPipPipPipPip
  • Group: Members
  • Posts: 835
  • Joined: 25-July 08
  • Gender:Male

Posted 12 April 2010 - 10:45 AM

Looking decent so far. I will submit a few patches to help this along later :-D
I can haz cookie?
0

#15 User is offline   Steff 

  • Newbie
  • Group: Members
  • Posts: 1
  • Joined: 14-March 10
  • Gender:Male

Posted 28 April 2010 - 05:58 AM

Nice to find you hear too :)
0

#16 User is offline   Sanitra44 

  • Member
  • Pip
  • Group: Members
  • Posts: 20
  • Joined: 09-August 09

Posted 02 May 2010 - 06:51 PM

This concept and idea seems really nice.
I hope you get far with it as it would be a nice contribution ^^

0

#17 User is offline   Foereaper 

  • Enthusiast
  • PipPipPip
  • Group: Members
  • Posts: 184
  • Joined: 21-May 09

Posted 08 July 2010 - 02:17 AM

Been quite some time since something was posted here, is it still up and running properly? Looks great so far, hope you can get a few more people to work with ya, maybe it'll become a part of the public releases of Arc at one point! :wub: +1!
0

#18 User is offline   dfighter 

  • Titles are overrated
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Administrator
  • Posts: 5,189
  • Joined: 14-June 08
  • IRC:dfighter
  • Gender:Male
  • Server OS:Linux

Posted 08 July 2010 - 10:47 AM

View PostFoereaper, on 08 July 2010 - 02:17 AM, said:

Been quite some time since something was posted here, is it still up and running properly? Looks great so far, hope you can get a few more people to work with ya, maybe it'll become a part of the public releases of Arc at one point! :D +1!

Well I am afraid this little project is on hold atm, or at least seems so. I haven't seen the guy around for a while.
This might be at least partly my fault. We had an argument and I am known to be a very passionate debater, and it might have scared him off. :3
"The demand for free goods is infinite."
0

#19 User is offline   Foereaper 

  • Enthusiast
  • PipPipPip
  • Group: Members
  • Posts: 184
  • Joined: 21-May 09

Posted 08 July 2010 - 08:12 PM

View Postdfighter, on 08 July 2010 - 10:47 AM, said:

Well I am afraid this little project is on hold atm, or at least seems so. I haven't seen the guy around for a while.
This might be at least partly my fault. We had an argument and I am known to be a very passionate debater, and it might have scared him off. :3


Ah, thats too bad.. Was hoping to add another language to the list of those I need to learn properly B)
0

#20 User is offline   Cromon 

  • Occasional Poster
  • Group: Contributor
  • Posts: 118
  • Joined: 07-June 08
  • Gender:Male
  • Location:Switzerland

Posted 09 November 2010 - 03:19 AM

Oh, i should really continue working on that! It somehow disappeared out of my memory :lol:
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • 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