Jump to content

setElementData question


3aGl3

Recommended Posts

So I have a quick question regarding the setElementData function.
While the wiki states that it can cause quite a bit of load on the net and server CPU I assume that this is only the case for server elements...

What happens if I use setElementData on something that exists only on a client? Say a gui element or any kind of element that has been created on a client.
Is the data still synced with the other clients or is it kept to the client the element exists on?

3aGl3

Link to comment

When using setElementData, the last argument is whether you want it to sync with the server or not. If it's set to false, the scope of that data is the local client only. It's perfectly fine to setElementData's on GUI elements like the tooltip of an exitbox etc, as long as it's not synced with the server. 

  • Like 1
Link to comment
  • Moderators

By giving a quick look at the source code, I can tell you that setElementData won't send your data through the network even if you set the synchronize parameter to true (line 6)

bool CStaticFunctionDefinitions::SetElementData ( CClientEntity& Entity, const char* szName, CLuaArgument& Variable, bool bSynchronize )
{
    CLuaArgument * pCurrentVariable = Entity.GetCustomData ( szName, false );
    if ( !pCurrentVariable || Variable != *pCurrentVariable )
    {
        if ( bSynchronize && !Entity.IsLocalEntity () )
        {
            // Allocate a bitstream
            NetBitStreamInterface* pBitStream = g_pNet->AllocateNetBitStream ();
            if ( pBitStream )
            {
                // Send data to sync it with the server [code redacted to keep it short]
              
                // Set its custom data
                Entity.SetCustomData ( szName, Variable );
                return true;
            }
        }
        else
        {
            // Set its custom data
            Entity.SetCustomData ( szName, Variable );
            return true;
        }
    }
    return false;
}

Source

Edited by Citizen
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...