Jump to content

Recommended Posts

  • enisn changed the title to How to use AttachEntityToEntity at v1.1
Posted

Doesn't work.

 

Nothing happens when attached at client-side, It doesn't throw an exception too. 

Object stays first spawned position.

Posted
14 hours ago, enisn said:

Doesn't work.

 

Nothing happens when attached at client-side, It doesn't throw an exception too. 

Object stays first spawned position.

You need to wait for object to be streamed before attaching it.

Created objects have a property called 'notifyStreaming' that you can set to true, that way, the object will call the 'entityStreamIn' event when it's created.

  • Like 1
  • 2 weeks later...
Posted

@enisn  @Shourya90try to replace the AttachObject function in EntityAttachmentService.cs with this: 

 private async 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, RAGE.Elements.Player.LocalPlayer.Position, new Vector3(0, 0, 0));

                var gameEntity = entity.GetGameEntity();

                Events.OnEntityStreamInDelegate handler = null;
                handler = (entity) =>
                {
                    if (entity != mapObject)
                        return;

                    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);

                    Events.OnEntityStreamIn -= handler;
                };

                Events.OnEntityStreamIn += handler;
                mapObject.NotifyStreaming = true;

                if (Entity.IsEntityAttachedToEntity(mapObject.Handle, gameEntity.Handle))
                {
                    OnEntityAttachedEvent?.Invoke(gameEntity, entityAttachment.AttachmentEvent);
                }

                entityObjects.Add(key, mapObject);
                entity.SetData("Objects", entityObjects);
            }
        }

 

  • 9 months later...
Posted
On 1/11/2021 at 8:37 PM, Machiavelli said:

@enisn  @Shourya90try to replace the AttachObject function in EntityAttachmentService.cs with this: 

 private async 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, RAGE.Elements.Player.LocalPlayer.Position, new Vector3(0, 0, 0));

                var gameEntity = entity.GetGameEntity();

                Events.OnEntityStreamInDelegate handler = null;
                handler = (entity) =>
                {
                    if (entity != mapObject)
                        return;

                    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);

                    Events.OnEntityStreamIn -= handler;
                };

                Events.OnEntityStreamIn += handler;
                mapObject.NotifyStreaming = true;

                if (Entity.IsEntityAttachedToEntity(mapObject.Handle, gameEntity.Handle))
                {
                    OnEntityAttachedEvent?.Invoke(gameEntity, entityAttachment.AttachmentEvent);
                }

                entityObjects.Add(key, mapObject);
                entity.SetData("Objects", entityObjects);
            }
        }

 

Can you explain more detailed? 

 

I've tried, but server-side generated objects can't be moved, because they're scyning at same position always, so player can't drag them. 

 

Another way, client-side generated objects are not synced. They stays only created client. 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...