@@ -313,32 +313,90 @@ void CElementRPCs::SetElementDimension(CClientEntity* pSource, NetBitStreamInter
313313void CElementRPCs::AttachElements (CClientEntity* pSource, NetBitStreamInterface& bitStream)
314314{
315315 ElementID usAttachedToID;
316- CVector vecPosition, vecRotation;
317- if (bitStream.Read (usAttachedToID) && bitStream.Read (vecPosition.fX ) && bitStream.Read (vecPosition.fY ) && bitStream.Read (vecPosition.fZ ) &&
318- bitStream.Read (vecRotation.fX ) && bitStream.Read (vecRotation.fY ) && bitStream.Read (vecRotation.fZ ))
316+
317+ CVector vecPosition;
318+ CVector vecRotation;
319+
320+ if (!(bitStream.Read (usAttachedToID) && bitStream.Read (vecPosition.fX ) && bitStream.Read (vecPosition.fY ) && bitStream.Read (vecPosition.fZ ) &&
321+ bitStream.Read (vecRotation.fX ) && bitStream.Read (vecRotation.fY ) && bitStream.Read (vecRotation.fZ )))
319322 {
320- CClientEntity* pAttachedToEntity = CElementIDs::GetElement (usAttachedToID);
321- if (pAttachedToEntity)
322- {
323- pSource->SetAttachedOffsets (vecPosition, vecRotation);
324- pSource->AttachTo (pAttachedToEntity);
325- }
323+ return ;
324+ }
325+
326+ CClientEntity* pAttachedToEntity = CElementIDs::GetElement (usAttachedToID);
327+ if (!pAttachedToEntity)
328+ {
329+ return ;
326330 }
331+
332+ ConvertRadiansToDegrees (vecRotation);
333+
334+ CLuaArguments Arguments;
335+ Arguments.PushElement (pAttachedToEntity);
336+ Arguments.PushNumber (vecPosition.fX );
337+ Arguments.PushNumber (vecPosition.fY );
338+ Arguments.PushNumber (vecPosition.fZ );
339+ Arguments.PushNumber (vecRotation.fX );
340+ Arguments.PushNumber (vecRotation.fY );
341+ Arguments.PushNumber (vecRotation.fZ );
342+
343+ if (!pSource->CallEvent (" onClientElementAttach" , Arguments, true ))
344+ {
345+ return ;
346+ }
347+
348+ ConvertDegreesToRadians (vecRotation);
349+
350+ pSource->SetAttachedOffsets (vecPosition, vecRotation);
351+ pSource->AttachTo (pAttachedToEntity);
327352}
328353
329354void CElementRPCs::DetachElements (CClientEntity* pSource, NetBitStreamInterface& bitStream)
330355{
331356 unsigned char ucTimeContext;
332- if (bitStream.Read (ucTimeContext))
357+ if (! bitStream.Read (ucTimeContext))
333358 {
334- pSource-> SetSyncTimeContext (ucTimeContext) ;
335- pSource-> AttachTo ( NULL );
359+ return ;
360+ }
336361
337- CVector vecPosition;
338- if (bitStream.Read (vecPosition.fX ) && bitStream.Read (vecPosition.fY ) && bitStream.Read (vecPosition.fZ ))
339- {
340- pSource->SetPosition (vecPosition);
341- }
362+ ElementID usAttachedToID;
363+ CClientEntity* pAttachedToEntity = CElementIDs::GetElement (usAttachedToID);
364+
365+ CVector vecPosition;
366+ CVector vecRotation;
367+
368+ bitStream.Read (vecPosition.fX );
369+ bitStream.Read (vecPosition.fY );
370+ bitStream.Read (vecPosition.fZ );
371+ bitStream.Read (vecRotation.fX );
372+ bitStream.Read (vecRotation.fY );
373+ bitStream.Read (vecRotation.fZ );
374+
375+ CLuaArguments Arguments;
376+ Arguments.PushElement (pAttachedToEntity);
377+ Arguments.PushNumber (vecPosition.fX );
378+ Arguments.PushNumber (vecPosition.fY );
379+ Arguments.PushNumber (vecPosition.fZ );
380+ Arguments.PushNumber (vecRotation.fX );
381+ Arguments.PushNumber (vecRotation.fY );
382+ Arguments.PushNumber (vecRotation.fZ );
383+
384+ if (!pSource->CallEvent (" onClientElementDetach" , Arguments, true ))
385+ {
386+ return ;
387+ }
388+
389+ pSource->SetSyncTimeContext (ucTimeContext);
390+ pSource->AttachTo (NULL );
391+
392+ if (vecPosition.fX != 0 .0f || vecPosition.fY != 0 .0f || vecPosition.fZ != 0 .0f )
393+ {
394+ pSource->SetPosition (vecPosition);
395+ }
396+
397+ if (vecRotation.fX != 0 .0f || vecRotation.fY != 0 .0f || vecRotation.fZ != 0 .0f )
398+ {
399+ pSource->SetRotationDegrees (vecRotation);
342400 }
343401}
344402
0 commit comments