Jump to content
Sign in to follow this  
Scotty123

Making variables on a client visible to other players problem

Recommended Posts

I have some values that are assigned to players as they spawn in, from a database. These numbers are used to determine players' titles. So when they spawn

player setVariable["title",dbNumber,true];

This generally works, but sometimes it doesn't, and I see the word "any" instead. For example, "any John", instead of "Sgt. John".

I thought maybe some clients were missing the variable being assigned (too far away for example). So I set up the setVariable command to happen every X minutes. Seems the problem still persists though. What am I missing? Thanks!

Share this post


Link to post
Share on other sites

The setVariable command is just declaring the variable; you need to post the function that uses that data. You can use a simple getVariable check to make sure the value exists (which it should, as your setVariable statement looks fine). You also need to clarify how 'dbNumber' is determined and what type it is.

The setVariable command is broadcasting the value. Is this because something is being done on the server and something else on the clients? Are other clients relying on this data? Also, check your database for missing values or inconsistencies.

I am not sure what you mean by 'title' or where that would be displayed. Do you you mean subtitles in a cutscene?

Finally, are you testing this in the editor or in multiplayer?

Share this post


Link to post
Share on other sites

dbNumber is just an integer, let's say 0. It exists on the database, and it's assigned to the player in say rankLevel (I used title before, but I think this demonstrates its purpose better). So

player setVariable["rankLevel", dbNumber, true];.

This number is then used to determine a player's prefix to their name (multiplayer here). So

_otherPlayerRankLevel = cursorTarget getVariable "rankLevel";

I then use this number to give them the appropriate prefix using drawIcon3D. As I said this initially worked fine (multiplayer test server with some friends). When we moved it to our live server, it seems to be fine initially but as time goes by, more and more people are without titles. Relogging and reconnecting doesn't fix it. Everytime you respawn, I use the above setVariable to ensure rankLevel is attached to the player object. The values in the database are not modified, they are set manually to certain integers and that's it. They never change throughout gameplay.

Share this post


Link to post
Share on other sites

This makes more sense now that you say drawIcon3d. I think the issue is not with the variable being stored. The cursorTarget command has some issues and drawbacks. See the notes here:

http://community.bistudio.com/wiki/cursorTarget

I would suggest checking the value returned by cursorTarget to make sure it is a player. Then, print out the value for rank to make sure it is defined. For example:

if (!(isNull cursorTarget) && {isPlayer cursorTarget}) then {
   _otherPlayerRankLevel = cursorTarget getVariable ["rankLevel", -1];
   diag_log _otherPlayerRankLevel; // debug
   if (_otherPlayerRankLevel != -1) then {
       // valid case to draw icon
   };
};

You could also print the value to in-game chat. I have set a default value for getVariable, so you can test for -1 value and handle this exception somehow.

To get around one limitation with cursorTarget, you could use 'reveal' to make sure players can target other players around them:

http://community.bistudio.com/wiki/reveal

Share this post


Link to post
Share on other sites

There has been no problem before when simply displaying a name. It's only when I start dealing with wanting to add the prefixes/titles.

Before that, I wasn't using cursor target. I was getting the positions of near entities of type man. Then using drawIcon3D for the names. That was working fine. Added the bit about the rankLevel. Some time after the server being up, no names would show on certain players. This wasn't universal. For example I could see player B's name, but player C would not see player B's name.

Share this post


Link to post
Share on other sites

The getVariable command should return the same value for every client. The database should be the same for every client also. I assume you are doing something like this every frame looping through all nearby units:

_rankNumber = _unit getVariable "rankLevel";
_rank = // accessor to database
_text = format ["%1 %2", _rank, (name _unit)];
// draw icon with _text

For one client to see something different means that different data is being stored locally on that machine. If the issue is not fixed by broadcasting the setVariable value again (as you said you tried), then I would add defensive code to check the rank value. At worst, you could display no rank or the unit's game rank.

http://community.bistudio.com/wiki/rank

Aside from posting all the code (which I sense you are reluctant to do), all you can try is adding a lot of debug statements to log what is going on. If you log enough data, there is probably a pattern to this.

I would start off by printing unit, name, getVariable value for each unit for every player on the server. Then run a function on the server that get the same data for every player (but doesn't draw any icons) and logs it. Ask the players to send you their log files and compare them to each other and to what the server logs for this info.

You could go further by logging the players' position, if they have respawned, how many icons they are drawing (of which how many they see correctly). Also, check if the text ever goes back to the correct value, or if the issue slowly increases as the game goes on.

You could also try not drawing the icon if the rank text is invalid. This would provide a visual reference for when it stopped working.

Sorry if this doesn't help, maybe someone with direct experience with this kind of system could help more.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×