Loading
Implement onPlaced and onDropped for actors and players
Closes #9216 (closed)
Description
Provides two new global script engine handlers for the Lua API: onDropped and onPlaced.
The reason for the distinction is:
- onDropped happens when any actor (player or not) drops an item at their feet.
- onPlaced happens when a player places an item on a surface
The OpenMW engine handles them separately, and modders seem to want to handle "onPlaced" differently from "onDropped" - so I made the distinction with this MR.
The docs have also been updated.
Implicitly, this allows for many mods to now implement custom drop and place mechanics that have been sought after/requested without finnicky "hacks" to get around the lack of this implementation.
Checklist
- I have read the CONTRIBUTING guidelines
- My code builds and runs locally
- I have included steps to replicate/confirm the changes below
- I have attached necessary supporting files or assets
Steps to Test/Replicate
Add the below Lua code to any registered global script. Then, drop an item from your inventory either at your feet (when the cursor has a horizontal bar under it) or on a surface.
return {
engineHandlers = {
onDropped = function(obj, actor, pos, rotation)
print(obj)
print(actor)
print(pos.x, pos.y, pos.z)
print(rotation:getAnglesZYX())
end,
onPlaced = function(obj, actor, pos, rotation)
print(obj)
print(actor)
print(pos.x, pos.y, pos.z)
print(rotation:getAnglesZYX())
obj:remove()
end,
}
}Edited by Cole Green
