View Full Version : UserVariableUpdateEventHandler HELP
01-19-2009, 01:38 PM
I have a game with two levels. When a user joins LEVEL 1 I create a new game and any new player will be added to the game (upto a max of 3).
The same process is followed for LEVEL 2. But the problem here is that I get UserVariableUpdateEvent calls from users in LEVEL 2 even if the current user belongs to LEVEL 1.
How to resolve this? Am I doing something wrong?
01-19-2009, 04:21 PM
Are you using GameManager for this? You may want to have two different game names, one for level 1, and the other for level 2.
If users are in the same room, they will get user variable updates for each other, so somehow your users are ending up in the same room.
01-19-2009, 05:06 PM
Yes I make use of a GameManager which does a registerGameConfiguration with a name "RED". And then I do createGameForUsers using this name everytime I need a new game with N users.
I am able to get the number of users in each room and different room ids everytime I create a new game using createGameForUsers. But I am not sure how and why the user variable updates arrive from other rooms??
01-19-2009, 05:11 PM
In ES4, users can be in multiple rooms. After your user joins the game room, are you having the user leave the previous room? If all the users are in the same "lobby" room (or whatever you call it) before they join a game, and that room is set so that users get updates on user variables, then if the users don't ever leave that room they will still get updates from everybody's user vars.
01-19-2009, 05:27 PM
You are right. I have a lobby (LOBBY ROOM) which keeps monitoring the min number of players required to start a game. Once reached, a new game is created which creates a new GAME ROOM with N users.
The getApi().createOrUpdateUserVariable is called from within GAME plugin once a game is created. But as you said, the users in the LOBBY plugin still remain active.
I shall try this out. Thanks.
01-19-2009, 06:26 PM
This is not helping my purpose. I have a array list in lobby which keeps monitoring the number of users entering the room. This is how I need a game to be created.
when user count = 1, getApi().createGameForUsers
when user count = 2, getApi().addUsersToRoom
when user count = 3, getApi().addUsersToRoom
So, if a player leaves the lobby, the Init of lobby plugin is called, thereby resetting the array list. :sad:
01-19-2009, 06:34 PM
If a player leaves lobby, the init shouldn't be called. The userExit method would be called.
Question: do the players in the lobby room need to see each other's user vars at all? If they don't need that until they are in the game, then just disable the user vars.
01-19-2009, 06:46 PM
The init is not called for the user (its user exit that is called) who leaves the lobby on entering the game. But it is called for the next player who enters the lobby.
As soon as the user enters the game, I made a request for the user to leave the lobby from the client side. However if I dont place this request, the init is not called for the next player.
I use user vars in lobby to figure out the state of the user. As having entered the lobby, chosen a car color, his/her ready state etc. I can work around by not using user vars but using plugin messages instead.
01-19-2009, 06:52 PM
The init method is only called when the plugin is created. Users entering should trigger a userEnter method.
Plugin messages are a better choice than user vars for information that only the user and the plugin needs to see. Another option in this situation is to switch to user server vars or extension bound user vars. These can be read by the user and by the plugin but not by other users (or at least other users don't get update messages about them changing).
01-19-2009, 06:58 PM
Thanks. Not sure why the init is being called again. But I shall try to fix it.
01-19-2009, 06:59 PM
If everybody leaves the room, and it's a room level plugin, then when the next user joins the room the init is called.
01-20-2009, 12:53 PM
I disabled the user vars in the lobby and enabled them only inside the game room. But it does not work still. Now I am getting the user var events of A and B in A but not in B.
I am trying to broadcast the car color information of A and B to both A and B and found users vars to be the easiest way to achieve this since A receives events of both itself and B and so with B. But I am lost at the moment. :confused:
01-20-2009, 02:04 PM
I normally work with plugin messages. Hmmm.... if B enters the room after A has already changed car color info, then B would not get an event on the user var for A. What I usually do is collect the info on everybody who is already in the room, and in the userEnter method I send a plugin message to B with the full set. Clients have to be set to listen for plugin message events before entering room, or else the plugin has to queue the message and send it later.
Another option is that after a user joins the room, his client asks for the user vars of each player in the room. This would require no coding on the plugin, and works well if there are few people in the room.
Powered by vBulletin® Version 4.1.6 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.