Пример #1
0
        private void PickupItem_Implementation(long entityId, MyFixedPoint amount)
        {
            MyFloatingObject obj;
            if (MyEntities.TryGetEntityById<MyFloatingObject>(entityId, out obj) && obj != null && obj.MarkedForClose == false && obj.WasRemovedFromWorld == false)
            {
                amount = MyFixedPoint.Min(amount, obj.Item.Amount); // Limit by amount in floating object
                amount = MyFixedPoint.Min(amount, ComputeAmountThatFits(obj.Item.Content.GetObjectId())); // Limit by inventory available space

                if (AddItems(amount, obj.Item.Content))
                {
                    if (amount >= obj.Item.Amount)
                    {
                        MyFloatingObjects.RemoveFloatingObject(obj, true);

                        // Visual Scripting event Implementation
                        if(MyVisualScriptLogicProvider.PlayerPickedUp != null)
                        {
                            var character = Owner as MyCharacter;
                            if(character != null)
                            {
                                var playerId = character.ControllerInfo.ControllingIdentityId;
                                MyVisualScriptLogicProvider.PlayerPickedUp(obj.ItemDefinition.Id.TypeId.ToString(), obj.ItemDefinition.Id.SubtypeName, obj.Name, playerId, amount.ToIntSafe());
                            }
                        }
                    }
                    else
                    {
                        MyFloatingObjects.AddFloatingObjectAmount(obj, -amount);
                    }
                }
            }
        }
Пример #2
0
 private void DropItem_Implementation(MyFixedPoint amount, uint itemIndex)
 {
     if (MyVisualScriptLogicProvider.PlayerDropped != null)
     {
         var character = Owner as MyCharacter;
         if (character != null)
         {
             var item = GetItemByID(itemIndex);
             var playerId = character.ControllerInfo.ControllingIdentityId;
             MyVisualScriptLogicProvider.PlayerDropped(item.Value.Content.TypeId.ToString(), item.Value.Content.SubtypeName, playerId, amount.ToIntSafe());
         }
     }
     RemoveItems(itemIndex, amount, true, true);
 }