+ Reply to Thread
Results 1 to 7 of 7

Thread: roomVaribles question

  1. #1
    Junior Member
    Join Date
    Mar 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    roomVaribles question

    I am wondering if using roomVariables to store each players x and y position is the right thing to use.

    I'm not sure if roomVariables are shared or set for each user.

    If someone joins and they set roomVariables x = 17 and y = 275

    then what happens if another person joins and they set x = 57 y = 35

    does that write over the x and y for the other user? or are the variables stored per each user...

    thanks in advance!

  2. #2
    Electrotank jobem's Avatar
    Join Date
    Apr 2004
    Posts
    996
    Thanks
    0
    Thanked 24 Times in 17 Posts
    Hi colfaxrev,

    To store the position of a user on the server I'd recommend you look into User Variables or plugins. If you use room variables, then you'd want to create a room variable called like 'steve_x = 23' and 'steve_y = 33'.
    ------
    Jobe Makar
    @jobemakar
    http://www.electrotank.com

    YouTube ElectroServer video tutorials
    http://www.youtube.com/user/ElectrotankInc

  3. #3
    Junior Member
    Join Date
    Mar 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ... i actually ended up just prefixing messages sent with things like

    c for chat
    u for position update
    w for win
    d for death
    b for dropping a bomb

    and that seems to work real good.

    I don't really understand how to go by programming plugins... Or what language to do them in. It all seems pretty over my head. This is the first multi-user app ive ever made! I was proud just to be able to move players around and have everyone get the updates.

    oh yeah, is there any hosting companies that have electro server 3 installed, so that you don't need ot have a dedicated machine?

  4. #4
    Junior Member
    Join Date
    Jan 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm developing a chat with lots of User Variables.. I'm a little bit scared of plugins too, so I've decided to do my first attempt with the "basics" hehe..
    It's not that difficult.. you set the initial values before connecting the user to a room, and then you can change them from anywhere and all clients receive an onUserVariablesUpdate-like event.. it's pretty interesting and simple.. to start with

    good luck!
    Fd.

  5. #5
    Senior Member
    Join Date
    Nov 2004
    Posts
    122
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey guys,

    I'm very new to this also so I'll share my thoughts on this.

    UserVariables are nice because everyone in the room is automatically aware when you update them. When you use a plugin each time you make a variable change you then have to broadcast a message to the people in the room. The clients have to have some code ready to react to this message also. That being said it's really not hard at all.

    I started with plugins because I want game security and game performance.
    If your game info is controlled by the clients it's very possible for someone to decompile your .swf and alter your code to allow them to cheat. If you are using a plugin it doesn't matter if they do this since you'll be periodically updating the clients with data from the server controlled plugin. So even if they make their client cheat, everyone else will see the real deal for the cheater. (That's a bit of a ramble...hope it makes sense)

    I believe there is also a bandwidth price to pay with room and user variables. (In comparison to using rawmessages with a plugin)
    So if you want a real-time game you want to minimize anything that might use up valuable communication space.

    Of course if you aren't making a real-time game you don't need to worry about the bandwidth stuff so much.

    I was a bit worried that plugins were going to be difficult but they are pretty easy to use. The only tricky part is making sure you only use AS 1.0

  6. #6
    Junior Member
    Join Date
    Mar 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i just thought you guys might be interested in this...

    Ivan talked about people decompiling your SWFs...

    here is a solution that will definently slow down it not altogether stop decompiling

    http://www.amayeta.com/software/swfencrypt/

    i tried it myself with different compilers, and i couldn't see any useful code!

    So.... Ivan... how do you make a plugin? you said you have to program it in AS1?


    is there a tutorial somewhere on this? or do we sort of have to pioneer it? Maybe you could give up sample code so we know what it looks like...

  7. #7
    Senior Member
    Join Date
    Nov 2004
    Posts
    122
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts