@@ -1247,47 +1247,44 @@ bool CStaticFunctionDefinitions::SetElementAngularVelocity(CClientEntity& Entity
12471247
12481248bool CStaticFunctionDefinitions::SetElementParent (CClientEntity& Entity, CClientEntity& Parent, CLuaMain* pLuaMain)
12491249{
1250- if (&Entity != &Parent && !Entity.IsMyChild (&Parent, true ))
1250+ if (&Entity == &Parent || Entity.IsMyChild (&Parent, true ))
1251+ return false ;
1252+
1253+ if (Entity.GetType () == CCLIENTCAMERA || Parent.GetType () == CCLIENTCAMERA)
1254+ return false ;
1255+
1256+ if (Entity.GetType () == CCLIENTGUI)
12511257 {
1252- if (Entity.GetType () == CCLIENTCAMERA || Parent.GetType () == CCLIENTCAMERA)
1253- {
1258+ if (Parent.GetType () != CCLIENTGUI && &Parent != pLuaMain->GetResource ()->GetResourceGUIEntity ())
12541259 return false ;
1255- }
1256- else if (Entity.GetType () == CCLIENTGUI)
1257- {
1258- if (Parent.GetType () == CCLIENTGUI || &Parent == pLuaMain->GetResource ()->GetResourceGUIEntity ())
1259- {
1260- CClientGUIElement& GUIElement = static_cast <CClientGUIElement&>(Entity);
12611260
1262- GUIElement.SetParent (&Parent);
1263- return true ;
1264- }
1265- }
1266- else
1267- {
1268- CClientEntity* pTemp = &Parent;
1269- CClientEntity* pRoot = m_pRootEntity;
1270- bool bValidParent = false ;
1271- while (pTemp != pRoot && pTemp != NULL )
1272- {
1273- const char * szTypeName = pTemp->GetTypeName ();
1274- if (szTypeName && strcmp (szTypeName, " map" ) == 0 )
1275- {
1276- bValidParent = true ; // parents must be a map
1277- break ;
1278- }
1261+ CClientGUIElement& GUIElement = static_cast <CClientGUIElement&>(Entity);
12791262
1280- pTemp = pTemp->GetParent ();
1281- }
1263+ GUIElement.SetParent (&Parent);
1264+ return true ;
1265+ }
12821266
1283- // Make sure the entity we move is a client entity or we get a problem
1284- if (bValidParent && Entity.IsLocalEntity ())
1285- {
1286- // Set the new parent
1287- Entity.SetParent (&Parent);
1288- return true ;
1289- }
1267+ CClientEntity* pTemp = &Parent;
1268+ CClientEntity* pRoot = m_pRootEntity;
1269+ bool bValidParent = false ;
1270+ while (pTemp != pRoot && pTemp != NULL )
1271+ {
1272+ const char * szTypeName = pTemp->GetTypeName ();
1273+ if (szTypeName && strcmp (szTypeName, " map" ) == 0 )
1274+ {
1275+ bValidParent = true ; // parents must be a map
1276+ break ;
12901277 }
1278+
1279+ pTemp = pTemp->GetParent ();
1280+ }
1281+
1282+ // Make sure the entity we move is a client entity or we get a problem
1283+ if (bValidParent && Entity.IsLocalEntity ())
1284+ {
1285+ // Set the new parent
1286+ Entity.SetParent (&Parent);
1287+ return true ;
12911288 }
12921289
12931290 return false ;
0 commit comments