npc.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. local S = mobs_npc.S
  2. -- Npc by TenPlus1
  3. mobs_npc.npc_drops = {
  4. {"default:pick_steel", 2}, "mobs:meat", {"default:sword_steel", 2},
  5. {"default:shovel_steel", 2}, "farming:bread", "bucket:bucket_water",
  6. "default:sapling", "default:tree", "mobs:leather", "default:coral_orange",
  7. {"default:mese_crystal_fragment", 3}, "default:clay", {"default:sign_wall", 2},
  8. "default:ladder", "default:copper_lump", "default:blueberries",
  9. "default:aspen_sapling", "default:permafrost_with_moss"
  10. }
  11. mobs:register_mob("mobs_npc:npc", {
  12. type = "npc",
  13. passive = false,
  14. damage = 3,
  15. attack_type = "dogfight",
  16. attacks_monsters = true,
  17. attack_npcs = false,
  18. owner_loyal = true,
  19. pathfinding = true,
  20. hp_min = 10,
  21. hp_max = 20,
  22. armor = 100,
  23. collisionbox = {-0.35,-1.0,-0.35, 0.35,0.8,0.35},
  24. visual = "mesh",
  25. mesh = "mobs_character.b3d",
  26. drawtype = "front",
  27. textures = {
  28. {"mobs_npc.png"},
  29. {"mobs_npc2.png"}, -- female by nuttmeg20
  30. {"mobs_npc3.png"}, -- male by swagman181818
  31. {"mobs_npc4.png"}, -- female by Sapphire16
  32. {"mobs_npc5.png"}, -- male by Astrobe
  33. {"mobs_npc6.png"} -- female by Astrobe
  34. },
  35. child_texture = {
  36. {"mobs_npc_baby.png"} -- derpy baby by AmirDerAssassine
  37. },
  38. makes_footstep_sound = true,
  39. sounds = {},
  40. walk_velocity = 2,
  41. run_velocity = 3,
  42. jump = true,
  43. drops = {
  44. {name = "default:wood", chance = 1, min = 1, max = 3},
  45. {name = "default:apple", chance = 2, min = 1, max = 2},
  46. {name = "default:axe_stone", chance = 5, min = 1, max = 1}
  47. },
  48. water_damage = 0,
  49. lava_damage = 2,
  50. light_damage = 0,
  51. follow = {"farming:bread", "mobs:meat", "default:diamond"},
  52. view_range = 15,
  53. owner = "",
  54. order = "stand",
  55. fear_height = 3,
  56. animation = {
  57. speed_normal = 30,
  58. speed_run = 30,
  59. stand_start = 0,
  60. stand_end = 79,
  61. walk_start = 168,
  62. walk_end = 187,
  63. run_start = 168,
  64. run_end = 187,
  65. punch_start = 200,
  66. punch_end = 219
  67. },
  68. on_rightclick = function(self, clicker)
  69. -- feed to heal npc
  70. if mobs:feed_tame(self, clicker, 8, true, true) then return end
  71. -- capture npc with net or lasso
  72. if mobs:capture_mob(self, clicker, nil, 5, 80, false, nil) then return end
  73. -- protect npc with mobs:protector
  74. if mobs:protect(self, clicker) then return end
  75. local item = clicker:get_wielded_item()
  76. local name = clicker:get_player_name()
  77. -- right clicking with gold lump drops random item from list
  78. if mobs_npc.drop_trade(self, clicker, "default:gold_lump",
  79. self.npc_drops or mobs_npc.npc_drops) then
  80. return
  81. end
  82. -- owner can right-click with stick to show control formspec
  83. if item:get_name() == "default:stick"
  84. and self.owner == name then
  85. minetest.show_formspec(name, "mobs_npc:controls",
  86. mobs_npc.get_controls_formspec(name, self))
  87. return
  88. end
  89. -- show simple dialog if enabled or idle chatter
  90. if mobs_npc.useDialogs == "Y" then
  91. simple_dialogs.show_dialog_formspec(name, self)
  92. else
  93. if self.state == "attack" then
  94. mobs_npc.npc_talk(self, clicker, {"Grr!"})
  95. else
  96. mobs_npc.npc_talk(self, clicker, {
  97. "Hello", "Hi there", "What a lovely day"})
  98. end
  99. end
  100. end
  101. })
  102. -- register spawn egg
  103. mobs:register_egg("mobs_npc:npc", S("Npc"), "default_brick.png", 1)
  104. -- this is only needed for servers that used the old mobs mod
  105. mobs:alias_mob("mobs:npc", "mobs_npc:npc")
  106. -- spawn NPC in world
  107. if not mobs.custom_spawn_npc then
  108. mobs:spawn({
  109. name = "mobs_npc:npc",
  110. nodes = {"default:brick"},
  111. neighbors = {"default:grass_3"},
  112. min_light = 10,
  113. chance = 10000,
  114. active_object_count = 1,
  115. min_height = 0,
  116. day_toggle = true
  117. })
  118. end