From ad55f5482959a9d6f779f8262e16ef29bbdbfd4b Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 7 Nov 2012 17:48:18 +0100 Subject: [PATCH] Start --- throwing/README | 5 + throwing/init.lua | 203 ++++++++++++++++++++++ throwing/textures/throwing_arrow.png | Bin 0 -> 488 bytes throwing/textures/throwing_arrow_back.png | Bin 0 -> 238 bytes throwing/textures/throwing_arrow_fire.png | Bin 0 -> 416 bytes throwing/textures/throwing_arrow_lava.png | Bin 0 -> 422 bytes throwing/textures/throwing_arrow_tnt.png | Bin 0 -> 412 bytes throwing/textures/throwing_bow.png | Bin 0 -> 484 bytes throwing/textures/throwing_string.png | Bin 0 -> 382 bytes 9 files changed, 208 insertions(+) create mode 100644 throwing/README create mode 100644 throwing/init.lua create mode 100644 throwing/textures/throwing_arrow.png create mode 100644 throwing/textures/throwing_arrow_back.png create mode 100644 throwing/textures/throwing_arrow_fire.png create mode 100644 throwing/textures/throwing_arrow_lava.png create mode 100644 throwing/textures/throwing_arrow_tnt.png create mode 100644 throwing/textures/throwing_bow.png create mode 100644 throwing/textures/throwing_string.png diff --git a/throwing/README b/throwing/README new file mode 100644 index 0000000..df6bf51 --- /dev/null +++ b/throwing/README @@ -0,0 +1,5 @@ +This is a mod for Minetest-c55 that adds Bow and arrow to the game. +Check out this thread on the forums to get more information about it: +http://c55.me/minetest/forum/viewtopic.php?id=687 + +Version: 0.14 DEV diff --git a/throwing/init.lua b/throwing/init.lua new file mode 100644 index 0000000..5e41ef5 --- /dev/null +++ b/throwing/init.lua @@ -0,0 +1,203 @@ +-- Bow and arrow mod +-- Topic on the forum: http://c55.me/minetest/forum/viewtopic.php?id=687 +-- Changed by Henry + +ARROW_DAMAGE=1 +ARROW_GRAVITY=0 --Original 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 + ----Henrys Mod START + 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}) + kind=1 + end + + if player:get_inventory():contains_item("main", "throwing:arrow_tnt") then + player:get_inventory():remove_item("main", "throwing:arrow_tnt") + -- 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}) + kind=2 + end + + if player:get_inventory():contains_item("main", "throwing:arrow_fire") then + player:get_inventory():remove_item("main", "throwing:arrow_fire") + -- 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}) + kind=3 + end + + if player:get_inventory():contains_item("main", "throwing:arrow_lava") then + player:get_inventory():remove_item("main", "throwing:arrow_lava") + -- 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}) + kind=4 + end + --Henrys Mod END + return +end + +throwing_shoot_arrow_continue=function(item, player, pointed_thing) + + return +end + +minetest.register_craftitem("throwing:string", { + inventory_image = "throwing_string.png", + description = "String", +}) + +minetest.register_craftitem("throwing:bow", { + inventory_image = "throwing_bow.png", + stack_max = 1, + on_use = throwing_shoot_arrow, + description = "Bow", +}) + +minetest.register_craftitem("throwing:arrow", { + inventory_image = "throwing_arrow.png", + description = "Arrow", +}) +--Henrys Mod START +minetest.register_craftitem("throwing:arrow_tnt",{ + inventory_image = "throwing_arrow_tnt.png", + description = "TNT arrow", +}) + +minetest.register_craftitem("throwing:arrow_fire",{ + inventory_image = "throwing_arrow_fire.png", + description = "Fire arrow", +}) + +minetest.register_craftitem("throwing:arrow_lava",{ + inventory_image = "throwing_arrow_lava.png", + description = "Lava arrow", +}) +--Henrys Mod END + +-- 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 + --Henrys Mod START + if kind==1 then + minetest.env:add_item(self.lastpos, 'throwing:arrow') + end + if kind==2 then + minetest.env:add_node(self.lastpos,{name="nuke:iron_tnt"}) + minetest.env:punch_node(self.lastpos) + end + if kind==3 then + minetest.env:add_node(self.lastpos,{name="fire:basic_flame"}) + end + if kind==4 then + minetest.env:add_node(self.lastpos,{name="default:lava_source"}) + end + --Henrys Mod END + 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 = 'throwing:string', + recipe = { + {'default:junglegrass'}, + {'default:junglegrass'}, + } +}) + +minetest.register_craft({ + output = 'throwing:bow', + 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'}, + } +}) +--Henrys Code START +minetest.register_craft({ + output = 'throwing:arrow_tnt 16', + recipe = { + {'default:stick', 'default:stick', 'nuke:iron_tnt'}, + } +}) + +minetest.register_craft({ + output = 'throwing:arrow_fire 16', + recipe = { + {'default:stick', 'default:stick', 'fire:basic_flame'}, + } +}) + +minetest.register_craft({ + output = 'throwing:arrow_lava 16', + recipe = { + {'default:stick', 'default:stick', 'default:lava_source'}, + } +}) +--Henrys Code END +print ("[Throwing_mod] Loaded!") diff --git a/throwing/textures/throwing_arrow.png b/throwing/textures/throwing_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..d9a42b5c6fc9cb7a6306bb5afda84023b780aab4 GIT binary patch literal 488 zcmVP)$*ys zris_$*yQJ9=V>*Mi|Wm){s-zGU{YORz~KFqvaE`B^7#|qv3 zy~Z$Zzs@jlTfbhf9^pEl&oXil``)kc?L{Ay_ZSS~F*DqqQVP9yL}YjrOd`sv`Y9p8 zvNhJsXsvNL95Azy$dD)ziv7;_hzl_=a+0=xU=)8scoXM>WlAa0S|g=2DE8g~cs`#$ eHjAOXcfJ8_qYH`ZkGQ1(0000-G2cowj^(N7l!{JxM1({$v_d#0*}aI z1_mK8X6#Yg$qp1`FY)wsWxvBE&&Q{Ewh3G6qJ5Jxq%Ze6iH6 z`1yjdJ2>t0v$Ow~pU+HOv2x{4{>PJLto`HSQlC#4?|;IazrVk4HZU;wqk4-cLL%qho}c>{FMeEa6L*k5L8_Buav~dBAX|!x;@txb cZaRz%hl&jf>$GFVdQ&MBb@0LAK8=l}o! literal 0 HcmV?d00001 diff --git a/throwing/textures/throwing_arrow_fire.png b/throwing/textures/throwing_arrow_fire.png new file mode 100644 index 0000000000000000000000000000000000000000..af578817595ad47509bf20ef5bc695b5e713bf72 GIT binary patch literal 416 zcmV;R0bl-!P)H zK~y-)m6Ka;12G6i57F5)lBnJFPVUM1+#NqpD;k zstSOaF~$HuMTE?x_l}6{;LHTrNzH73A7e1*yo%MsQbgeHyMmd~T6;-;s%IwEg@~Z4 zyVa7a;_iFA)32xFY`xgjcUtdBrknta!Dp4Pc{63sc`IP&aXcjR?$)`~7~+{CSZzqRcsW zw%@i<0adWBQ_nxJoIk0U)Vu0ZRTVQsRdGfwfF!vCIq55gXmfS0000< KMNUMnLSTXoBeP%t literal 0 HcmV?d00001 diff --git a/throwing/textures/throwing_arrow_lava.png b/throwing/textures/throwing_arrow_lava.png new file mode 100644 index 0000000000000000000000000000000000000000..8036d37854e357392c02535c28452dca614c63c7 GIT binary patch literal 422 zcmV;X0a^ZuP)wk05rMlmgPAeLxHNyp z%uGs!h@h%1wVrV9f53JxjlsA=EDpgf6GgP%D?!5uH-|ugm73toaPlwUx7ZU~( Q;{X5v07*qoM6N<$f|${-n*aa+ literal 0 HcmV?d00001 diff --git a/throwing/textures/throwing_arrow_tnt.png b/throwing/textures/throwing_arrow_tnt.png new file mode 100644 index 0000000000000000000000000000000000000000..d4a82d9c7fd7e011972f9a85aaa31430362ae44b GIT binary patch literal 412 zcmV;N0b~A&P)*lzQ6b08Do5tRbgSRMMP`{cc-=X*8IeknUo4inAw(E zFf$@zk9X$nOq|lon<{RtRivbplmOOR#)?hSmdvkW}*pFUV^z}>g=r~8@7 zoRjlW#Xh7n)>>pHx7&?5CzAFiN=cn^M7)nsH*ucuS_^mQe!sKU+8)%18e{Bk=gvP- z4~nqv#LhpklE0xmsk%~WW`?_CW?N#J_INygZC0dnPQCyJ74)qWNF7H20000N2bPDNB8 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#