private void AttachObject(RAGE.Elements.Entity entity, uint key) { var entityObjects = entity.GetData <Dictionary <uint, MapObject> >("Objects"); if (AttachmentDictionary.ContainsKey(key) && !entityObjects.ContainsKey(key)) { var entityAttachment = AttachmentDictionary[key]; var mapObject = new MapObject(entityAttachment.Model, new Vector3(0, 0, 0), new Vector3(0, 0, 0)) { Dimension = uint.MaxValue }; var gameEntity = entity.GetGameEntity(); Entity.AttachEntityToEntity(mapObject.Handle, gameEntity.Handle, RAGE.Game.Ped.GetPedBoneIndex(gameEntity.Handle, entityAttachment.BoneId), entityAttachment.Offset.X, entityAttachment.Offset.Y, entityAttachment.Offset.Z, entityAttachment.Rotation.X, entityAttachment.Rotation.Y, entityAttachment.Rotation.Z, false, false, false, false, 2, true); if (Entity.IsEntityAttachedToEntity(mapObject.Handle, gameEntity.Handle)) { OnEntityAttachedEvent?.Invoke(gameEntity, entityAttachment.AttachmentEvent); } entityObjects.Add(key, mapObject); entity.SetData("Objects", entityObjects); } }
private void DetachObject(RAGE.Elements.Entity entity, uint key) { var entityObjects = entity.GetData <Dictionary <uint, MapObject> >("Objects"); if (entityObjects.ContainsKey(key)) { var entityObject = entityObjects[key]; if (Entity.DoesEntityExist(entityObject.Handle)) { entityObject.Destroy(); OnEntityDetachedEvent?.Invoke(entity.GetGameEntity(), AttachmentDictionary[key].AttachmentEvent); } entityObjects.Remove(key); entity.SetData("Objects", entityObjects); } }