User Tools

Site Tools


addingscripts

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
addingscripts [2015/09/18 21:41]
mrbenjammin
addingscripts [2015/09/18 21:55] (current)
mrbenjammin
Line 100: Line 100:
   * Broken - Called when the block itself is destroyed by an explosion, player or anything that can reduce a blocks health to zero.   * Broken - Called when the block itself is destroyed by an explosion, player or anything that can reduce a blocks health to zero.
   * Destroy - Called when the block is unloaded or broken(see above). ​   * Destroy - Called when the block is unloaded or broken(see above). ​
 +
 +Block scripts need to be assigned to the blocks that use them similarly to the Items. In your mod's Tiles.xml([[addingblocks|a guide to setting up Tiles.xml]]) you must assign a script via namespace and class with the tag <​SpecialBlockClass>​. Like so:
 +<​code>​
 + <​SpecialBlockClass>​ScriptsExample.TestBlock</​SpecialBlockClass>​
 +</​code>​
 +====Chat Commmands====
 +Chat commands are a type of script that allows you to assign new chat commands easily. The server will automatically detect them through reflection when it compiles them and as such they'​ll be available without any configuration except writing the actual script.
 +
 +Chat commands derive from the GameCommand class. You must override all of the abstract properties and methods to use a chat command. One instance of this class is created, multiple instances are not created for every command use or player so be aware of this. 
 +
 +Here's an example of a chat command:
 +<​code>​
 +   class TestCommand : GameCommand
 +    {
 +        public override string[] Aliases
 +        {
 +            get { return new string[] { "/​test"​ }; }
 +        }
 +
 +        public override string CommandDescription
 +        {
 +            get
 +            {
 +                return "A test command in ScriptsExample.";​
 +            }
 +        }
 +
 +        public override Priviledges Priviledge
 +        {
 +            get { return Priviledges.Player;​ }
 +        }
 +        ​
 +        public TestCommand(IGameServer server)
 +            : base(server)
 +        {
 +        }
 +
 +        public override bool Use(IActor actor, string message, string[] parameters)
 +        {
 +            Server.ChatManager.SendActorMessage("​Hello world!",​ actor);
 +
 +            return true;
 +        }
 +    }
 +</​code>​
 +  * Aliases as essentially what calls the command. Multiple aliases can be used such as /who and /playerlist to grab a list of players in-game. They must however begin with a '/'​.
 +  * CommandDescription is a string that describes what the command does. This appears in the /help menu if the player has access to the given command.
 +  * Priviledge is the priviledge level(player,​ moderator, admin) that the player has to be have access to the command.
 +  * Use - Is called when the player uses the command, their actor and original message is passed through. As well as an array of the original message separated by ' '. Returning true or false determines on whether game assumes the command was successful or not.
 +
 +The vast majority of the default game commands are actually scripts. Which you can check out in the main scripts folder available at GameData/​Scripts/​. These make a good references when writing new scripts.
 ====Example==== ====Example====
 Example scripts are available performing simple tasks for each type of script. They are also made in a Visual Studio 2015 project that references the correct DLLs for the mod API. So if you have trouble use this project as your base. Example scripts are available performing simple tasks for each type of script. They are also made in a Visual Studio 2015 project that references the correct DLLs for the mod API. So if you have trouble use this project as your base.
addingscripts.txt ยท Last modified: 2015/09/18 21:55 by mrbenjammin