Cancelling the on_picked_up_item event

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
Vudjun
Burner Inserter
Burner Inserter
Posts: 12
Joined: Fri Mar 04, 2016 8:12 pm
Contact:

Cancelling the on_picked_up_item event

Post by Vudjun »

As the event system is now, I cannot prevent a player from picking up an item that they aren't meant to.
If an event handler could cancel the "on_picked_up_item" event, then this would be possible.
This could work as a .setCancelled() method on the event. So the handler would run "event.setCancelled(true)" to cancel the event

The event might be fired after the item has already been picked up, so perhaps a cancellable on_prepicked_up_item event is needed?

This would also be useful for (but less important for my mod):
- on_preplayer_mined_item
- on_built_entity
- on_robot_pre_mined
- on_robot_built_entity
- Probably the on_built_tile and on_mined_tile events mentioned in the 0.13 post (when they're available)

I need this for a protection mod for public servers that I'm working on (A "Plots" server, players can claim plots of land which only they and trusted friends can build on). Without this, the best I can do is remove the items from the inventory of whoever picked it up and maybe return them to the inventory of the owner.

Thanks for reading.

User avatar
DedlySpyder
Filter Inserter
Filter Inserter
Posts: 253
Joined: Fri Jun 20, 2014 11:42 am
Contact:

Re: Cancelling the on_picked_up_item event

Post by DedlySpyder »

Couldn't you just remove the item from their inventory and throw it back on the ground?


Also, I was thinking recently if there was a need for a plots type mod (like in the Minecraft days), but the problem is solved by the fact that Factorio has automated turrets, IMO.

Vudjun
Burner Inserter
Burner Inserter
Posts: 12
Joined: Fri Mar 04, 2016 8:12 pm
Contact:

Re: Cancelling the on_picked_up_item event

Post by Vudjun »

DedlySpyder wrote:Couldn't you just remove the item from their inventory and throw it back on the ground?
Possibly, but the event parameters for on_picked_up_item don't specify where the item was picked up from (so the mod won't know where to put the item and it would end up putting items on the wrong belts, bringing production to a halt). Also trying to reverse the action manually seems like it could cause minor problems (for example you might be able to confuse an inserter by constantly standing next to it trying to pick up the item that it wants to pick up).
DedlySpyder wrote:Also, I was thinking recently if there was a need for a plots type mod (like in the Minecraft days), but the problem is solved by the fact that Factorio has automated turrets, IMO.
An "anarchy" server could be really fun, where you have to defend your own land from other players with turrets, but that's not guaranteed protection as the attacker might be able to break in if they have more resources than you.

Personally I'd like to be able to play on a server where I know my stuff won't have been raided while I was offline, which is why I'm making the mod.

Post Reply

Return to “Modding interface requests”