From 0245f4c54ba52839208c9a460cd4473e89239dfe Mon Sep 17 00:00:00 2001 From: Jeija Date: Fri, 10 Feb 2012 21:02:36 +0100 Subject: [PATCH] Initial Upload --- init.lua | 111 +++++++++++++++++++++++++++++++ textures/throwing_arrow.png | Bin 0 -> 492 bytes textures/throwing_arrow_back.png | Bin 0 -> 246 bytes textures/throwing_bow.png | Bin 0 -> 484 bytes textures/throwing_string.png | Bin 0 -> 382 bytes 5 files changed, 111 insertions(+) create mode 100644 init.lua create mode 100644 textures/throwing_arrow.png create mode 100644 textures/throwing_arrow_back.png create mode 100644 textures/throwing_bow.png create mode 100644 textures/throwing_string.png diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..55b4102 --- /dev/null +++ b/init.lua @@ -0,0 +1,111 @@ +-- Bow and arrow mod +-- Topic on the forum: http://c55.me/minetest/forum/viewtopic.php?id=687 + +ARROW_DAMAGE=1 +ARROW_GRAVITY=9 +ARROW_VELOCITY=19 + +throwing_shoot_arrow=function (item, player, pointed_thing) + -- Check if arrows in Inventory and remove one of them + local i=1 + if player:get_inventory():contains_item("main", "throwing:arrow") then + player:get_inventory():remove_item("main", "throwing:arrow") + -- Shoot Arrow + local playerpos=player:getpos() + local obj=minetest.env:add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, "throwing:arrow_entity") + local dir=player:get_look_dir() + obj:setvelocity({x=dir.x*ARROW_VELOCITY, y=dir.y*ARROW_VELOCITY, z=dir.z*ARROW_VELOCITY}) + obj:setacceleration({x=dir.x*-3, y=-ARROW_GRAVITY, z=dir.z*-3}) + end + return +end + +minetest.register_craftitem("throwing:string", { + image = "throwing_string.png", + on_place_on_ground = minetest.craftitem_place_item, +}) + +minetest.register_craftitem("throwing:bow", { + image = "throwing_bow.png", + on_place_on_ground = minetest.craftitem_place_item, + on_use = throwing_shoot_arrow, +}) + +minetest.register_craftitem("throwing:arrow", { + image = "throwing_arrow.png", + on_place_on_ground = minetest.craftitem_place_item, +}) + +-- The Arrow Entity + +THROWING_ARROW_ENTITY={ + physical = false, + timer=0, + textures = {"throwing_arrow_back.png"}, + lastpos={}, + collisionbox = {0,0,0,0,0,0}, +} + + +-- Arrow_entity.on_step()--> called when arrow is moving +THROWING_ARROW_ENTITY.on_step = function(self, dtime) + self.timer=self.timer+dtime + local pos = self.object:getpos() + local node = minetest.env:get_node(pos) + + -- When arrow is away from player (after 0.2 seconds): Cause damage to mobs and players + if self.timer>0.2 then + local objs = minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2) + for k, obj in pairs(objs) do + obj:set_hp(obj:get_hp()-ARROW_DAMAGE) + if obj:get_entity_name() ~= "throwing:arrow_entity" then + if obj:get_hp()<=0 then + obj:remove() + end + self.object:remove() + end + end + end + + -- Become item when hitting a node + if self.lastpos.x~=nil then --If there is no lastpos for some reason + if node.name ~= "air" then + minetest.env:add_item(self.lastpos, 'craft "throwing:arrow" 1') + self.object:remove() + end + end + self.lastpos={x=pos.x, y=pos.y, z=pos.z} -- Set lastpos-->Item will be added at last pos outside the node +end + +minetest.register_entity("throwing:arrow_entity", THROWING_ARROW_ENTITY) + + + + + +--CRAFTS +minetest.register_craft({ + output = 'craft "throwing:string" 1', + recipe = { + {"default:junglegrass"}, + {"default:junglegrass"}, + } +}) + +minetest.register_craft({ + output = 'craft "throwing:bow" 1', + recipe = { + {"throwing:string", "default:wood", ''}, + {"throwing:string", '', "default:wood"}, + {"throwing:string", "default:wood", ''}, + } +}) + +minetest.register_craft({ + output = '"throwing:arrow" 16', + recipe = { + {"default:stick", "default:stick", "default:steel_ingot"}, + } +}) + +print ("[Throwing_mod] Loaded!") diff --git a/textures/throwing_arrow.png b/textures/throwing_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..7ea2c4b75aba82a5ab728183037323ac301132fe GIT binary patch literal 492 zcmVPx#1ZP1_K>z@;j|==^1poj5AY({UO#lFTCIA3{ga82g0001h=l}q9FaQARU;qF* zm;eA5aGbhPJOBUy8gxZibW?9;ba!ELWdKlNX>N2bPDNB8b~7$DE-^4L^m3s900Bfv zL_t(IPjyoXj)O1^46y7=_TKKF_CEfAPz6uoM&e!EcsoXpT-qWC*EI(gMZq}q zfx!SqQABYZ)9a0)?tkP19HktRX#H4c6V(69WG-G2comUKs7M+SzC{oH>NS%G}c0*}aI z1_mK8X6#Yg$qp2hDshb{3C>R|DNig)We7;j%q!9Ja}7}_GuAWJGc+*xQnV1Ls>svD zF~q_@Ibnf}K~NqGGjk}*EuwPftB67OIC7|sLp00i_>zopr0C^Bj!vFvP literal 0 HcmV?d00001 diff --git a/textures/throwing_bow.png b/textures/throwing_bow.png new file mode 100644 index 0000000000000000000000000000000000000000..07f303a5cc8818289caa5500224df992f1b32826 GIT binary patch literal 484 zcmVN2bPDNB8 zb~7$DE-^4L^m3s900Cf0L_t(IPkoYIPK7WKg$vOacj3Q2nQJt<8UOXs6&Q^odx8g8 z7lgl&Z(y2o?~P3k)6&kFGpCJ2#Qit=zIRa+xj2s9FborFei!FwyplN zwdHIi+s43fP?G!xsHXs4FY8zlb=tV-0eF( zL{)(7rfC#&dw$O=u%01!Id$@V6-n6d+T6FN6-+W!!RKlML`EDMIp#=JRZ9;zXy#Du z^(>O7V*5dtF6kI4(&CF$)v7Ki|AJRm}_Fp)OQZEMM{@bSpW`)W^N#UL;; zZ(?}ABpU($xfT3C(X2$WEK|a*1oj&38d>891osDey^`m-!aq~kLKCe=q?#H?XlXnv zWm&2kui*D)M*w3?&?>Xr8X4nFX@p?wOEd$i%G``XT~QQXwk0nVgg;5H>w4i2`}7>1 aWBv#3=%ksXVTCgQ0000-l7>)u;1@HO_XIBP@QRNz4353yx{S8yjkUaI$N|&ib_xj?)SuEvA}kp z&nNLNcrzj$O9I&5a=H8jpVq{iFg@1L&~HMUd2Ju4z2EOWBe`0w25tlHXK*|oGgek( z{3hfFu|5bJh3oZt=yr%zG0pxS5wDR61dSp%olYZ~V6)kb{XND;eFTMisw!B-5aB=g0w#M9e@Zch_{1VXm|<~H*v!;`!1;Wh`g^8R@RgGg!w`>xV@n%c zVCH}0928R=@i^coJ=N6UKgR2FxllZ>Lq3Yk^lfw&0^i`tKss6IjPz8U^hY2i#