Page 1 of 1

More Entity Callbacks

PostPosted: Thu Jan 22, 2015 15:25
by Kalabasa
See Clonk's callbacks for insipration

Currently, Minetest has on_activate, on_step, on_punch, and on_rightclick.

Additional callbacks that are useful are:
  • on_collide_node(dir) - When an entity hits a wall. Useful for projectiles (arrows, or bombs that explode on contact). dir = collision direction (bottom, north, top, ...)
  • on_collide_object(obj) - When an entity touches/hits another entity. Only for entities with physical = true. Useful for projectiles.
  • on_remove() - When an entity is removed. (by object:remove or by the engine (as in too many objects))
  • on_death() - When an entity dies. (by obj:punch or obj:set_hp)
  • on_deactivate() - Opposite of activate
  • on_create() - Maybe this is redundant

In the current state of the engine, these (except on_remove) can be done in Lua, by adding code into the on_step function (on_punch for on_death). But it is better (and faster) if these are called by the engine, because the calculations are already done by the engine.

PS
Another thing I wish to be added to the engine
  • get_standing() - Whether the entity is on the ground. Very useful for mobs code.

Re: More Entity Callbacks

PostPosted: Fri Jan 23, 2015 02:14
by Sokomine
Sounds very useful. on_collide_node could be used for all those pressure plates out there.

Re: More Entity Callbacks

PostPosted: Sat Jun 18, 2016 05:56
by burli
I had this idea too

Re: More Entity Callbacks

PostPosted: Sat Jun 18, 2016 07:09
by Ferk
You can probably use the function "get_staticdata" as if it was the opposite of "on_activate".
The string that on_activate receives as parameter is the same that get_staticdata returns. get_staticdata gets called when the entity deactivates (unloads) and the string is saved so that the state of the entity can be restored when its received by on_activate.

Collision callbacks have been requested in the past.. I also suggested it, but it's not simple to implement, specially without lag.

Re: More Entity Callbacks

PostPosted: Sat Jun 18, 2016 11:31
by azekill_DIABLO
+1

Re: More Entity Callbacks

PostPosted: Sat Jun 18, 2016 23:44
by toby109tt
+1

Re: More Entity Callbacks

PostPosted: Wed Aug 03, 2016 07:14
by orwell
Ferk wrote:You can probably use the function "get_staticdata" as if it was the opposite of "on_activate".
The string that on_activate receives as parameter is the same that get_staticdata returns. get_staticdata gets called when the entity deactivates (unloads) and the string is saved so that the state of the entity can be restored when its received by on_activate.

AFAIK get_staticdata gets called every time the map is saved. There is no distinction between map save and unloading.

Re: More Entity Callbacks

PostPosted: Wed Aug 03, 2016 13:32
by maikerumine
YES!!

Re: More Entity Callbacks

PostPosted: Mon Oct 31, 2016 06:20
by D00Med
Found this whilst looking for collision detection, this would be really good!

Re: More Entity Callbacks

PostPosted: Sat Jan 12, 2019 10:18
by sorcerykid
I'm thinking of trying my hand at coding these in C++. A few of them would be very useful, for the new mobs framework I'm developing (in fact, that's the reason I stumbled across this threat). I can certainly attest that detecting object-vs-object collisions is really hacky atm -- even though the engine collects this information :/