Yep there a tutorial on here. You can find it under
Documentation / ElectroServer Articles / Server-side Plug-ins
http://www.electro-server.com/docume...dePlugins.aspx
Also you'll find checking the Client-side and Server-side API Documentation very useful.
I'll try to make a summary based off a post I made before:
Here is an example of how I use one for keeping track of who enters and leaves.
1. First you have to make a reference to a plugin in your configuration.xml file.
Here is an example of one I made:
Code:
<Name>blarg</Name>
Script
<Scope>Room
<File>plugins\blarg.as</File>
<Variables/>
</Plugin>
Notice that it's a child node (is that the right XML thing to say?) of
Notice the path of the plugin. It needs to live in a plugins folder under your configuration.xml file on your server.
2. When you create your room you have to associate it with an instance of your plugin.
Here is a look at some of the client-side code in my fla file when I make the room:
Code:
function makeRoom() {
var roomObj:Object = new Object();
roomObj.zone = "Chat Area";
roomObj.roomName = roomName_inp.text;
roomObj.hidden = false;
roomObj.numbered = true;
roomObj.userVariablesEnabled = false;
roomObj.description = description_inp.text;
roomObj.password = "";
roomObj.capacity = -1;
roomObj.updatable = false;
// Begin Game Plugin
roomObj.plugins = new Array();
var obj:Object = new Object();
obj.name = "blarg";
roomObj.plugins.push(obj);
// End Game Plugin
_parent.es.createRoom(roomObj);
That loads your plugin when a room is created. Your plugin lives as long as the room does.
3. Now lets look at the plugin (blarg.as):
Code:
function pluginInit(hash) {
trace("----Plug-in Blarg Initialized----");
}
function pluginRequest(hash) {
var caller = hash.get("ExecutingUserName");
var method = hash.get("Method");
if (method == "Calculate") {
trace("Welcome to the Calculate method of the blarg plugin");
}
}
function pluginUserEnter(username) {
// The above updates the view of the player slots for the new person.
trace(username +" just entered the room!");
//destroyCharacterOnMap(username);//Just some function that could exist
}
function pluginUserExit(username) {
trace(username +" just left!");
//destroyCharacterOnMap(username);//Just some function that could exist
}
function pluginDestroy() {
trace("----Plug-in Blarg Destroyed----");
}
Now that your plugin is activated you will see these traces showup in your ES window. To track whenever people come or go put code into those functions that correspond to enter/leave.
For example on the game I'm working on now I keep track of all my players and stuff in my plugin. If someone is assigned to be a player and then they leave the room I know to remove them from that player spot and open it up for someone else to join in.
So now that your game logic is safely calculated in your plugin how do you get the results back to the client?
You can do it a few different ways. You could have the plugin set a roomvariable or uservariable.
But lets use the basic server.sendMessage (once you get used to this you can use sendRawMessage)
Let's make our simple example "Report back the location of a player".
Your plugin might look like something like:
[code]var player1name="Smith";
var player1x=10;
var player1y=30;
var player2name="Jones";
var player2x=24;
var player2y=17;
function pluginInit(hash) {
trace("----Plug-in Blarg Initialized----");
}
function pluginRequest(hash) {
var caller = hash.get("ExecutingUserName");
var method = hash.get("Method");
if (method == "WhereIsThisPlayer") {
trace("Welcome to the WhereIsThisPlayer method of the blarg plugin");
ReportPlayerLocation(caller); // Some function I created
}
}
function ReportPlayerLocation