#Scale of Items

1 messages · Page 1 of 1 (latest)

winged tangle
#

Just making a basic dropsize command and I got the command and the spawning of the item with the custom scale and everything, I got all that, but what I don't have is, when picking up and dropping the item again, it does not maintain the scale, the scale resets, I've been looking at like other plugins and stuff but it's been a while and I can't seem to find anything on it

This is what I have for the spawning:```csharp
public static Pickup CreateAndSpawn(ItemType itemType, Vector3 position, Quaternion rotation = default, Vector3 scale = default, Player lastOwner = null)
{
if (rotation == default)
rotation = new Quaternion(1f, 1f, 1f, 1f);

if (scale == default)
    scale = new Vector3(1f, 1f, 1f);

Pickup pickupItem = Pickup.Create(itemType, position, rotation, scale);

pickupItem.Base.PreviousOwner = lastOwner is null ? new Footprint(Server.Host.ReferenceHub) : new Footprint(lastOwner.ReferenceHub);

pickupItem.Spawn();

return pickupItem;

}```

severe bobcat
#

Store the scaled item serial, hook onto player dropped item event and rescale the dropped pickup based on the serial number.

winged tangle
#

See that's what I thought, and I did that but I must of did it wrong

#

Lemme get it back and post the code

winged tangle
#

I'm assuming the pickup serial

severe bobcat
#

They are the same

#

Its unique id stored across all items and pickups instances

winged tangle
#

Ah, alright

#

well in that case what i have still don't work :/

severe bobcat
#

show

winged tangle
#

Wait, when do I store the scaled item serial?

severe bobcat
#

I guess in a dictionary?

#

Easiest solution

winged tangle
#

Not where, when

#

When I spawn it? or have an event for Player pickedup

severe bobcat
#

Oh my bad

#

store it when you spawn it I guess

#

Apply when dropped item event

winged tangle
#

Well then I just have```csharp
public static Pickup CreateAndSpawn(ItemType itemType, Vector3 position, Quaternion rotation = default, Vector3 scale = default, Player lastOwner = null)
{
if (rotation == default)
rotation = new Quaternion(1f, 1f, 1f, 1f);

if (scale == default)
    scale = new Vector3(1f, 1f, 1f);

Pickup pickupItem = Pickup.Create(itemType, position, rotation, scale);

pickupItem.Base.PreviousOwner = lastOwner is null ? new Footprint(Server.Host.ReferenceHub) : new Footprint(lastOwner.ReferenceHub);

if (!ItemScales.ContainsKey(pickupItem.Serial))
    ItemScales.Add(pickupItem.Serial, pickupItem.Base.transform.localScale);

pickupItem.Spawn();

return pickupItem;

}``````csharp
private static void OnPlayerDroppedItem(PlayerDroppedItemEventArgs ev)
{
if (ItemScales.TryGetValue(ev.Pickup.Serial, out Vector3 scale))
ev.Pickup.Transform.localScale = scale;
}```

severe bobcat
#

Hold up let me check something

#
private static void OnPlayerDroppedItem(PlayerDroppedItemEventArgs ev)
{
    if (ItemScales.TryGetValue(ev.Pickup.Serial, out Vector3 scale))
    {
        ev.Pickup.Transform.localScale = scale;
        NetworkServer.UnSpawn(ev.Pickup.GameObject);
        NetworkServer.Spawn(ev.Pickup.GameObject);
    }
}
#

@winged tangle try this

#

I think you need to respawn the gameobject for it to apply the scale

winged tangle
#

Oh yeah, that would make sense actually, I remember seeing something like that when I was going through other plugins

severe bobcat
#

Ill probably add a scale property

winged tangle
#

Alright, let's give this a crack

#

Yup, that's what I needed

#

It works now, thank you :]

#

I was 2 lines off from getting it right lol, well, I had those two lines in my code but in the wrong spot :/

severe bobcat
#

Yay

winged tangle
#

Thank you :]

full musk
#

Cant wait for a 16 meter tall locker

severe bobcat
#

You can do that now im pretty sure..

#

just set the scale

#

despawn and spawn

#

100% sure it works for workstation

#

so why not for else