Drop generation||doc135609

September 20, 2022

Format

DropItemServer.Create(params)

Description

Create a drop object instance object on the server side, and automatically synchronize it to the client side where the surrounding field of view can track the object for display.


Precautions

Since the dropped object is composed of item, when picking it up, item are usually added to the picked up object, so when creating the dropped object, the parameters in the creation parameteritemfield required


Parameters

Variable name type Description
params table Create parameters


Create parameter composition

Field Name type Defaults Description
item Item none Items corresponding to dropped objects (required)
map Map default map Drop generation map
pos Vector3 none drop spawn coordinates
yaw number none The Y-axis of the falling object rotates (after adding, the falling object will not rotate)
pitch number none The Z axis of the falling object rotates (after adding, the falling object will not rotate)


Value Returned

type Description
DropItem Drop Instance Object


Code Samples

In the editor, create a new item and set its model

On the server side of the player entitymount script, add when the player logs into the gameCallback, spawns this drop directly in front of the player

Trigger.RegisterHandler(this:cfg(), "ENTITY_ENTER", function(context)
    local player = context.obj1
    local pos = player:getFrontPos(3, true, true) + Lib.v3(0, 0.2, 0)
    local params = {
      item = Item.CreateItem("myplugin/dropItem", 1),
      map = player.map,
      pos = pos
    }
    local dropItem = DropItemServer.Create(params)
end)