More Entity Callbacks

User avatar
Kalabasa
Member
 
Posts: 34
Joined: Tue Jan 06, 2015 17:36
GitHub: Kalabasa
IRC: Kalabasa
In-game: Kalabasa

More Entity Callbacks

by Kalabasa » Thu Jan 22, 2015 15:25

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.
Last edited by Kalabasa on Mon Jan 26, 2015 01:49, edited 2 times in total.
insert signature here
 

Sokomine
Member
 
Posts: 2980
Joined: Sun Sep 09, 2012 17:31

Re: More Entity Callbacks

by Sokomine » Fri Jan 23, 2015 02:14

Sounds very useful. on_collide_node could be used for all those pressure plates out there.
A list of my mods can be found here.
 

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

Re: More Entity Callbacks

by burli » Sat Jun 18, 2016 05:56

I had this idea too
 

User avatar
Ferk
Member
 
Posts: 330
Joined: Tue Aug 18, 2015 17:18
GitHub: Ferk

Re: More Entity Callbacks

by Ferk » Sat Jun 18, 2016 07:09

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.
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }
 

User avatar
azekill_DIABLO
Member
 
Posts: 3458
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: More Entity Callbacks

by azekill_DIABLO » Sat Jun 18, 2016 11:31

+1
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)

azekill_DIABLO said: Mineyoshi+ABJ+Baggins= TOPIC HIJACKED.
My Mods and Stuff | Voxellar | VoxBox on GITHUB | M.I.L.A Monster engine
WEIRD MODDING CONTEST !!!
 

User avatar
toby109tt
Member
 
Posts: 296
Joined: Sun May 29, 2016 23:42
GitHub: tobyplowy
In-game: Toby109tt

Re: More Entity Callbacks

by toby109tt » Sat Jun 18, 2016 23:44

+1
( ͡° ͜ʖ ͡°) i love pixels and voxels ( ͡° ͜ʖ ͡°)
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: More Entity Callbacks

by orwell » Wed Aug 03, 2016 07:14

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.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
maikerumine
Member
 
Posts: 946
Joined: Mon Aug 04, 2014 14:27
GitHub: maikerumine
In-game: maikerumine

Re: More Entity Callbacks

by maikerumine » Wed Aug 03, 2016 13:32

YES!!
 

User avatar
D00Med
Member
 
Posts: 712
Joined: Sat Feb 07, 2015 22:49
GitHub: D00Med

Re: More Entity Callbacks

by D00Med » Mon Oct 31, 2016 06:20

Found this whilst looking for collision detection, this would be really good!
Look! I have a signature :]
My subgame: https://forum.minetest.net/viewtopic.php?f=15&t=14051#p207242
dmobs2 is coming...
 


Return to Minetest Features

Who is online

Users browsing this forum: Google [Bot] and 8 guests

cron