spawn_mg_villages_traders.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. -- interface function for mg_villages;
  2. -- the table "bed" contains all necessary information about the mob
  3. mobf_trader.spawn_one_trader = function( bed )
  4. local prefix = 'trader';
  5. -- does the mob exist already?
  6. if( bed.mob_id ) then
  7. -- search for it
  8. local self = mob_basics.find_mob_by_id( bed.mob_id, 'trader' );
  9. if( self and self.object ) then
  10. -- make sure he sleeps on his assigned bed
  11. mob_sitting.sleep_on_bed( self, bed );
  12. -- return the id of the mob
  13. return bed.mob_id;
  14. end
  15. end
  16. local trader_typ = bed.title;
  17. if( not( trader_typ ) or trader_typ=="" or not( mob_basics.mob_types[ prefix ][ trader_typ ])) then
  18. trader_typ = 'teacher'; -- TODO: FALLBACK
  19. end
  20. -- try to spawn the mob
  21. local self = mob_basics.spawn_mob( bed, trader_typ, nil, nil, nil, nil, true );
  22. if( not( self )) then
  23. print("ERROR: NO TRADER GENERATED FOR "..minetest.pos_to_string( bed ));
  24. return nil;
  25. end
  26. bed.mob_id = self[prefix..'_id'];
  27. -- select a texture depending on the mob's gender
  28. if( bed.gender == "f" ) then
  29. self[ prefix..'_texture' ] = "baeuerin.png";
  30. else
  31. self[ prefix..'_texture' ] = "wheat_farmer_by_addi.png";
  32. end
  33. self.object:set_properties( { textures = { self[ prefix..'_texture'] }});
  34. -- children are smaller
  35. if( bed.age < 19 ) then
  36. local factor = 0.2+bed.age/36;
  37. self[ prefix..'_vsize'] = {x=factor, y=factor, z=factor}; -- x,z:width; y: height
  38. mob_basics.update_visual_size( self, self[ prefix..'_vsize'], false, prefix );
  39. end
  40. -- position on bed and set sleeping animation
  41. mob_sitting.sleep_on_bed( self, bed );
  42. --print("SPAWNING TRADER "..trader_typ.." id: "..tostring( bed.mob_id ).." at bed "..minetest.pos_to_string( bed )); -- TODO
  43. return bed.mob_id;
  44. end