documentation.txt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. bweapons api provides two public functions: bweapons.register_weapon() and bweapons.register_ammo().
  2. bweapons.register_ammo() is not required (actual required ammo is specified in weapon definition), however it was defined for simplicity of registering ammo.
  3. Automatic weapons are currently not implemented.
  4. All fields can be omited (except for mandatory ones), in that case they will either default to some value or a specific feature will be disabled
  5. Many features will only be enabled if a corresponding field was specified (for example if you omit a "flare" field, a muzzle flash wont be shown,
  6. same for all other visuals and sounds). All features are supposed to work together, so there's a big room for experimentation.
  7. The following example contains all possible fields. Many fields are not required or used together
  8. (for example there's no point in defining projectile options if your weapon is hitscan).
  9. Main weapon registration function, with definition supplied in form of table:
  10. bweapons.register_weapon({
  11. --Mandatory fields
  12. name = "my_weapons_pack:rifle", --Tool ID
  13. description = "Rifle", --Name shown in inventory
  14. texture = "my_weapons_pack_rifle.png", --Texture
  15. --Ammo or energy
  16. has_durability = true, --Master switch for tool durability. If false, it will not deplete its durability and can only use mana or ammo
  17. uses = 128, --Amount of uses until the tool breaks/needs to be recharged by technic or repaired
  18. requires_technic = false, --If true, weapon durability is expressed as technic charge. Requires "technic"
  19. technic_charge = 350000, --Maximum charge that the weapon holds, in technic EU
  20. custom_charge = false, --Item doesn't break when its durability is depleted, and cannot be used until charged/repaired. Has no effect
  21. --if technic_powered is true (since this is default behavior in technic mod anyway). Also prevents items from being
  22. --Repaired with technic workshop
  23. mana_per_use = 50, --If defined, the tool requires this much mana per use. Requires "mana"
  24. ammo_type = "my_weapons_pack:rifle_round", --If defined, the tool requires this type of ammo to function
  25. ammo_per_shot = 1, --How much ammo should be used per shot
  26. return_item = "my_weapons_pack:round_case", --Adds an item to the user inventory, if defined. If no space is left, the item is dropped on the ground instead
  27. --Repair
  28. repair_with = "default:wood", --Combine the tool with this item on crafting grid (shapeless) to repair it by amount of uses specified below
  29. repair_uses = 8, --Amount of uses to repair with "repair with" option
  30. tool_repair = false, --Allows to repair two items of the same type by combining them on the crafting grid
  31. --Drop on hit
  32. drop = "default:stone", --Drop something on successful hit. If penetration is enabled, drops at the last trace stop
  33. drop_chance = 0.8, --Chance of drop in range from 0 to 1 (1 is always drop, 0 is never)
  34. --Hitscan configuration
  35. hitscan = true, --Instantly trace shots to the target, use in weapons like firearms, lasers, etc
  36. distance = 100, --Distance in nodes in which hitscan traces will connect to the target
  37. penetration = 2, --How many nodes/objects hitscan trace will go through before stopping (damaging each one and triggering on_hit())
  38. --Weapon stats
  39. liquids_stop = false, --Should hitscan traces or projectiles travel through liquid nodes
  40. damage = 15, --Damage per projectile/hitscan trace
  41. shot_amount = 1, --Total amount of projectiles or hitscan traces per shot (multiple can be used for shotguns, salvos, etc)
  42. spread = 0.02, --Random deviation of direction of every particle or hitscan trace from center of the screen
  43. cooldown = 2, --Period of time in seconds after which you can fire the weapon again
  44. spawn_distance = 1, --Distance in direction of player view at which projectile spawns or hitscan traces start
  45. aoe = false, --Enable Area Of Effect Damage
  46. aoe_radius = 5, --Radius at which damage is inflicted, damage is calculated linearly, with highest at the center
  47. --and lowest at the edge of radius
  48. --Visuals
  49. flare = "tnt_boom.png", --Texture briefly displayed when player fires a weapon
  50. flare_size = 10, --Size of fire flare
  51. flare_glow = true, --Should fire flare glow
  52. hit_flare = "tnt_boom.png", --Texture of a big particle spawned upon hit
  53. hit_flare_size = 20, --Size of hit flare
  54. hit_flare_glow = true, --Should hit flare glow
  55. hit_particle = "tnt_smoke.png", --Texture of particles to emit when hit something
  56. hit_particle_glow = false, --Should hit particles glow
  57. hit_particle_amount = 32, --Amount of hit particles to spawn
  58. hit_particle_size = 2, --Maximum visual size of hit particles. Minimum size is lowest integer of maximum size divided by two.
  59. hit_particle_velocity = 2, --Starting velocity of hit particles
  60. hit_particle_gravity = -10, --Acceleration on vertical axis of hit particles
  61. trail_particle = "my_weapons_pack_projectile_trail.png", --Texture of projectile trail particles
  62. trail_particle_distance = 0.5, --Distance between each trail particle with hitscan mode. No effect in projectile mode.
  63. trail_particle_velocity = 1, --Random velocity of each particle in trail
  64. trail_particle_gravity = 0, --Vertical acceleration of each particle in trail
  65. trail_particle_size = 1, --Maximum size of each trail particle. Minimum size is trail_particle_size/2
  66. trail_particle_amount = 4, --Amount of particles to emit each server step (with projectile) or hitscan trail particle distance
  67. trail_particle_displacement = 0, --Random displacement of each particle from trail center
  68. trail_particle_glow = true, --Should trail particles glow
  69. --Sounds
  70. fire_sound = "my_weapons_pack_fire_sound", --Sound when firing a weapon
  71. fire_sound_gain = 1, --How loud the fire sound should be
  72. reload_sound = "my_weapons_pack_reload_sound", --Sound when weapon is cooling down/not enough ammo or charge
  73. reload_sound_gain = 0.25, --How loud the reload sound should be
  74. hit_sound = "my_weapons_pack_hit_sound", --Sound, emitted at every place where projectile/hitscan trace hits something
  75. hit_sound_gain = 0.25, --How loud the hit sound should be
  76. --Projectile configuration
  77. projectile_speed = 15, --Starting velocity of projectile
  78. projectile_gravity = -10, --Acceleration on vertical axis of projectile
  79. projectile_timeout = 35, --Timeout in server ticks after which projectile dissapears, calling on_timeout()
  80. --Projectile visuals
  81. projectile_texture = "my_weapons_pack_projectile.png", --Texture of projectiile
  82. projectile_glow = true, --Should projectile visual glow
  83. projectile_visual_size = 1, --Size of projectile visual
  84. --Custom functions
  85. on_fire = function(itemstack, user, pointed_thing)
  86. print("Fired weapon")
  87. end, --Custom function called on weapon fire
  88. on_hit = function (self, target)
  89. print("Hit something")
  90. end, --Custom function called on hitscan/projectile hit. With hitscan, self provides a user entity,
  91. --with projectile self provides a projectile entity. Depending on occasion, target may reference a node or an object
  92. on_timeout = function (self)
  93. print("Projectile timeout")
  94. end, --Custom function called on a projectile timeout. Self refers to the projectile
  95. --Recipes
  96. shapeless_recipe = false, --Should the recipe be shapeless
  97. recipe={
  98. {
  99. {'moreores:tin_ingot', 'technic:diamond_drill_head', 'moreores:tin_ingot'},
  100. {'technic:stainless_steel_ingot', 'technic:motor', 'technic:stainless_steel_ingot'},
  101. {'', 'technic:red_energy_crystal', 'default:copper_ingot'}
  102. },
  103. {
  104. {'moreores:tin_ingot', 'technic:diamond_drill_head', 'moreores:tin_ingot'},
  105. {'technic:stainless_steel_ingot', 'technic:tin_ingot', 'technic:stainless_steel_ingot'},
  106. {'', 'technic:red_energy_crystal', 'default:copper_ingot'}
  107. }
  108. }, --Recipes to be registered for this weapon. Table may contain multiple recipes
  109. replacements = {{"mesecraft_bucket:bucket_water", "mesecraft_bucket:bucket_empty"}}, --Replacements for recipe items
  110. })
  111. Ammo registration function, with definition supplied in form of table:
  112. bweapons.register_ammo({
  113. --Mandatory
  114. name = "my_weapons_pack:rifle_round", --Ammo ID
  115. description = "Pistol Round", --Inventory name
  116. texture = "bweapons_firearms_pack_pistol_round.png", --Inventory texture
  117. --Optional
  118. recipe={
  119. {
  120. {'moreores:tin_ingot', 'technic:diamond_drill_head', 'moreores:tin_ingot'},
  121. {'technic:stainless_steel_ingot', 'technic:motor', 'technic:stainless_steel_ingot'},
  122. {'', 'technic:red_energy_crystal', 'default:copper_ingot'}
  123. },
  124. {
  125. {'moreores:tin_ingot', 'technic:diamond_drill_head', 'moreores:tin_ingot'},
  126. {'technic:stainless_steel_ingot', 'technic:tin_ingot', 'technic:stainless_steel_ingot'},
  127. {'', 'technic:red_energy_crystal', 'default:copper_ingot'}
  128. }
  129. }, --Recipes to be registered for this ammo. Table may contain multiple recipes
  130. amount = 1, --Amount of ammo to be given after crafting
  131. })
  132. Copy of functions above without comments and whitespace, for easy copy-pasting:
  133. bweapons.register_weapon({
  134. name = "my_weapons_pack:rifle",
  135. description = "Rifle",
  136. texture = "my_weapons_pack_rifle.png",
  137. has_durability = true,
  138. uses = 128,
  139. requires_technic = false,
  140. technic_charge = 350000,
  141. custom_charge = false,
  142. mana_per_use = 50,
  143. ammo_type = "my_weapons_pack:rifle_round",
  144. ammo_per_shot = 1,
  145. return_item = "my_weapons_pack:round_case",
  146. repair_with = "default:wood",
  147. repair_uses = 8,
  148. tool_repair = false,
  149. drop = "default:stone",
  150. drop_chance = 0.8,
  151. hitscan = true,
  152. distance = 100,
  153. penetration = 2,
  154. liquids_stop = false,
  155. damage = 15,
  156. shot_amount = 1,
  157. spread = 0.02,
  158. cooldown = 2,
  159. spawn_distance = 1,
  160. aoe = false,
  161. aoe_radius = 5,
  162. flare = "tnt_boom.png",
  163. flare_size = 10,
  164. flare_glow = true,
  165. hit_flare = "tnt_boom.png",
  166. hit_flare_size = 20,
  167. hit_flare_glow = true,
  168. hit_particle = "tnt_smoke.png",
  169. hit_particle_glow = false,
  170. hit_particle_amount = 32,
  171. hit_particle_size = 2,
  172. hit_particle_velocity = 2,
  173. hit_particle_gravity = -10,
  174. trail_particle = "my_weapons_pack_projectile_trail.png",
  175. trail_particle_distance = 0.5,
  176. trail_particle_velocity = 1,
  177. trail_particle_gravity = 0,
  178. trail_particle_size = 1,
  179. trail_particle_amount = 4,
  180. trail_particle_displacement = 0,
  181. trail_particle_glow = true,
  182. fire_sound = "my_weapons_pack_fire_sound",
  183. fire_sound_gain = 1,
  184. reload_sound = "my_weapons_pack_reload_sound",
  185. reload_sound_gain = 0.25,
  186. hit_sound = "my_weapons_pack_hit_sound",
  187. hit_sound_gain = 0.25,
  188. projectile_speed = 15,
  189. projectile_gravity = -10,
  190. projectile_timeout = 35,
  191. projectile_texture = "my_weapons_pack_projectile.png",
  192. projectile_glow = true,
  193. projectile_visual_size = 1,
  194. on_fire = function(itemstack, user, pointed_thing)
  195. print("Fired weapon")
  196. end,
  197. on_hit = function (self, target)
  198. print("Hit something")
  199. end,
  200. on_timeout = function (self)
  201. print("Projectile timeout")
  202. end,
  203. recipe={
  204. {
  205. {'moreores:tin_ingot', 'technic:diamond_drill_head', 'moreores:tin_ingot'},
  206. {'technic:stainless_steel_ingot', 'technic:motor', 'technic:stainless_steel_ingot'},
  207. {'', 'technic:red_energy_crystal', 'default:copper_ingot'}
  208. },
  209. {
  210. {'moreores:tin_ingot', 'technic:diamond_drill_head', 'moreores:tin_ingot'},
  211. {'technic:stainless_steel_ingot', 'technic:tin_ingot', 'technic:stainless_steel_ingot'},
  212. {'', 'technic:red_energy_crystal', 'default:copper_ingot'}
  213. }
  214. },
  215. })
  216. bweapons.register_ammo({
  217. name = "my_weapons_pack:rifle_round",
  218. description = "Rifle Round",
  219. texture = "bweapons_firearms_pack_pistol_round.png",
  220. recipe={
  221. {
  222. {'moreores:tin_ingot', 'technic:diamond_drill_head', 'moreores:tin_ingot'},
  223. {'technic:stainless_steel_ingot', 'technic:motor', 'technic:stainless_steel_ingot'},
  224. {'', 'technic:red_energy_crystal', 'default:copper_ingot'}
  225. },
  226. {
  227. {'moreores:tin_ingot', 'technic:diamond_drill_head', 'moreores:tin_ingot'},
  228. {'technic:stainless_steel_ingot', 'technic:tin_ingot', 'technic:stainless_steel_ingot'},
  229. {'', 'technic:red_energy_crystal', 'default:copper_ingot'}
  230. }
  231. },
  232. amount = 1,
  233. })