@@ -709,22 +709,24 @@ bool CElement::GetCustomDataBool(const CStringName& name, bool& bOut, bool bInhe
709709 return false ;
710710}
711711
712- void CElement::SetCustomData (const CStringName& name, const CLuaArgument& Variable, ESyncType syncType, CPlayer* pClient, bool bTriggerEvent)
712+ bool CElement::SetCustomData (const CStringName& name, const CLuaArgument& Variable, ESyncType syncType, CPlayer* pClient, bool bTriggerEvent)
713713{
714714 assert (name);
715715 if (name->length () > MAX_CUSTOMDATA_NAME_LENGTH)
716716 {
717717 // Don't allow it to be set if the name is too long
718718 CLogger::ErrorPrintf (" Custom data name too long (%s)\n " , *SStringX (name.ToCString ()).Left (MAX_CUSTOMDATA_NAME_LENGTH + 1 ));
719- return ;
719+ return false ;
720720 }
721721
722- // Grab the old variable
722+ // Grab the old variable and sync type
723723 CLuaArgument oldVariable;
724+ ESyncType oldSyncType = ESyncType::LOCAL;
724725 const SCustomData* pData = m_CustomData.Get (name);
725726 if (pData)
726727 {
727728 oldVariable = pData->Variable ;
729+ oldSyncType = pData->syncType ;
728730 }
729731
730732 // Set the new data
@@ -737,18 +739,27 @@ void CElement::SetCustomData(const CStringName& name, const CLuaArgument& Variab
737739 Arguments.PushString (name);
738740 Arguments.PushArgument (oldVariable);
739741 Arguments.PushArgument (Variable);
740- CallEvent (" onElementDataChange" , Arguments, pClient);
742+ if (!CallEvent (" onElementDataChange" , Arguments, pClient))
743+ {
744+ // Event was cancelled, restore previous value
745+ if (pData)
746+ m_CustomData.Set (name, oldVariable, oldSyncType);
747+ else
748+ m_CustomData.Delete (name);
749+ return false ;
750+ }
741751 }
752+ return true ;
742753}
743754
744- void CElement::DeleteCustomData (const CStringName& name)
755+ bool CElement::DeleteCustomData (const CStringName& name)
745756{
746757 // Grab the old variable
747758 SCustomData* pData = m_CustomData.Get (name);
748759 if (pData)
749760 {
750- CLuaArgument oldVariable;
751- oldVariable = pData->Variable ;
761+ CLuaArgument oldVariable = pData-> Variable ;
762+ ESyncType oldSyncType = pData->syncType ;
752763
753764 // Delete the custom data
754765 m_CustomData.Delete (name);
@@ -758,8 +769,15 @@ void CElement::DeleteCustomData(const CStringName& name)
758769 Arguments.PushString (name);
759770 Arguments.PushArgument (oldVariable);
760771 Arguments.PushArgument (CLuaArgument ()); // Use nil as the new value to indicate the data has been removed
761- CallEvent (" onElementDataChange" , Arguments);
772+ if (!CallEvent (" onElementDataChange" , Arguments))
773+ {
774+ // Event was cancelled, restore previous value
775+ m_CustomData.Set (name, oldVariable, oldSyncType);
776+ return false ;
777+ }
778+ return true ;
762779 }
780+ return false ;
763781}
764782
765783// Used to send the root element data when a player joins
0 commit comments