Server Scripting

I have created a Scripting "Engine" for use with Photon. It uses IronPython for scripts. I was wondering if any one would be interested in me releasing it? Let me know! So far I am able to script Quests with it. I will be adding in items shortly and NPCs at some point!

Comments

  • I would be very interested myself. That would be a great tool.

    GJ mate!
  • This should be interesting for a lot of developers here. Including us.
    It's always interesting to see how someone else solves these tasks!
  • Ok it's short enough I am going to just paste it right in here. Right now this is all I have but it's easy to extend:
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Photon.MmoDemo.Server.Quests.Quest_Types;
    using IronPython.Hosting;
    using Microsoft.Scripting.Hosting;
    using System.Runtime.Remoting;
    using Photon.MmoDemo.Server.Quests;
    using System.IO;
    
    namespace Photon.MmoDemo.Server.Scripting
    {
        public class ScriptingEngine
        {
            ScriptEngine engine;
            ScriptScope scope;
            private static ScriptingEngine instance = null;
            private string _directory;
    
            private ScriptingEngine()
            {
                engine = Python.CreateEngine();
                scope = engine.CreateScope();
                engine.Runtime.LoadAssembly(typeof(string).Assembly);
                engine.Runtime.LoadAssembly(typeof(Kill).Assembly);
                engine.Runtime.LoadAssembly(typeof(ClearArea).Assembly);
                engine.Runtime.LoadAssembly(typeof(Timed).Assembly);
                engine.Runtime.LoadAssembly(typeof(Escort).Assembly);
                engine.Runtime.LoadAssembly(typeof(QuestManager).Assembly);
    
                setScriptDirectory("C:/Users/Empire Games/Desktop/Server/deploy/MmoDemo/Scripts/");
            }
    
            public static ScriptingEngine getInstance()
            {
                if (instance == null)
                {
                    instance = new ScriptingEngine();
                }
    
                return instance;
            }
    
            public void setScriptDirectory(string directory)
            {
                this._directory = directory;
            }
    
            public void runScripts()
            {
                string[] filePaths = Directory.GetFiles(_directory, "*.py", SearchOption.AllDirectories);
    
                for (int i = 0; i < filePaths.Length; i++)
                {
                    engine.ExecuteFile((string)filePaths.GetValue(i), scope);
                }
            }
        }
    }
    
    

    Classes you want exposed to Python define with:
    engine.Runtime.LoadAssembly(typeof(Kill).Assembly);
    Kill being the name of the class.

    runScripts() takes and loads all scripts with a .py extension in the directory set with setScriptDirectory. It also search the sub-directories and loads those scripts as well.

    Here is my test Quest Script:
    from Photon.MmoDemo.Server.Quests.Quest_Types import *
    from Photon.MmoDemo.Server.Quests import QuestManager
    
    quest = Kill("Starter Quest")
    quest.Description = "Welcome young Adventurer to this mighty land! This Quest is where your adventure begins!"
    quest.AddReward("Small Sword",1)
    quest.cashReward = 50;
    QuestManager.getInstance().addKillQuest(quest)
    
    quest = Kill("Save the Princess")
    quest.Description = "No great Adventure would be complete with out saving a princess!"
    quest.AddReward("Small Sword",1)
    quest.cashReward = 50;
    QuestManager.getInstance().addKillQuest(quest)
    
    quest = Kill("Slay the King")
    quest.Description = "Now slay the king to rule the Kingdom!"
    quest.AddReward("Small Sword",1)
    quest.cashReward = 50;
    QuestManager.getInstance().addKillQuest(quest)
    
    quest = Kill("Slay the protesters")
    quest.Description = "You must now slay the protesters who are trying to take over!"
    quest.AddReward("Small Sword",1)
    quest.cashReward = 50;
    QuestManager.getInstance().addKillQuest(quest)
    
    quest = Kill("Silly Quest")
    quest.Description = "This is just another silly quest you must complete!"
    quest.AddReward("Small Sword",1)
    quest.cashReward = 50;
    QuestManager.getInstance().addKillQuest(quest)
    
    quest = Kill("Death to the Kingdom")
    quest.Description = "A uprising is taking place and in order to save your Kingdom you must put a end to it!"
    quest.AddReward("Small Sword",1)
    quest.cashReward = 50;
    QuestManager.getInstance().addKillQuest(quest)
    
    quest = Kill("Final Task")
    quest.Description = "The Final task in order to save your Kingdom is to kill the leader of the uprising!"
    quest.AddReward("Small Sword",1)
    quest.cashReward = 50;
    QuestManager.getInstance().addKillQuest(quest)
    
    quest = Escort("Escort the King");
    quest.Description = "Sir Knight, the King would like you to escort him to the next city. I have heard that if you are successful the King will grant your guild those Expansion papers your after!";
    quest.cashReward = 1000;
    quest.AddReward("Expansion Papers", 1);
    QuestManager.getInstance().addEscortQuest(quest)
    
  • BorisBoris ✭✭
    Interesting, thanks for sharing.
  • Thank you very much for your code. I knew that ironscripting exists, but it can be used for mmorps for quest, npcs, items, spells etc. I guess you could change scripts and reload it into server without restarting it.

    It is huge time saver.

    Thanks.
Sign In or Register to comment.