3aGl3 Posted March 3, 2017 Share Posted March 3, 2017 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
marty000123 Posted March 3, 2017 Share Posted March 3, 2017 It's set to your element. Meaning that it's not only stuck to the script the function is written in. Link to comment
pa3ck Posted March 3, 2017 Share Posted March 3, 2017 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. 1 Link to comment
3aGl3 Posted March 3, 2017 Author Share Posted March 3, 2017 Thanks for the info, I somehow didn't think about the synced flag... Also I do know how variable scope, or in this case element data scope works, still, thanks. Link to comment
Moderators Citizen Posted March 3, 2017 Moderators Share Posted March 3, 2017 (edited) 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 March 5, 2017 by Citizen 1 Link to comment
3aGl3 Posted March 4, 2017 Author Share Posted March 4, 2017 I see, on local entities the sync variable is overwritten anyway. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now