From 80aeca256dc60c1b5248f42e444bdf5b544b642c Mon Sep 17 00:00:00 2001 From: rnd1 Date: Sat, 4 Mar 2017 22:03:01 +0100 Subject: [PATCH] - additional interactive buttons - with numbers - perfect to make games with - form display and handling for robots --- commands.lua | 57 ++++++++++++++++++++++++++++++++----- init.lua | 12 ++++++++ textures/robot_button0.png | Bin 0 -> 167 bytes textures/robot_button1.png | Bin 0 -> 153 bytes textures/robot_button2.png | Bin 0 -> 173 bytes textures/robot_button3.png | Bin 0 -> 226 bytes textures/robot_button4.png | Bin 0 -> 219 bytes textures/robot_button5.png | Bin 0 -> 166 bytes textures/robot_button6.png | Bin 0 -> 218 bytes textures/robot_button7.png | Bin 0 -> 169 bytes textures/robot_button8.png | Bin 0 -> 164 bytes textures/robot_button9.png | Bin 0 -> 225 bytes 12 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 textures/robot_button0.png create mode 100644 textures/robot_button1.png create mode 100644 textures/robot_button2.png create mode 100644 textures/robot_button3.png create mode 100644 textures/robot_button4.png create mode 100644 textures/robot_button5.png create mode 100644 textures/robot_button6.png create mode 100644 textures/robot_button7.png create mode 100644 textures/robot_button8.png create mode 100644 textures/robot_button9.png diff --git a/commands.lua b/commands.lua index 96a0fa6..18c17f2 100644 --- a/commands.lua +++ b/commands.lua @@ -81,12 +81,9 @@ basic_robot.commands.dig = function(name,dir) local energy = 0; if basic_robot.maxenergy~=0 then - energy = basic_robot.data[name].energy; - if energy > 0 then - basic_robot.data[name].energy = energy-1; - else - return false - end + local data = basic_robot.data[name]; + energy = data.energy; + if energy > 0 then data.energy = energy-1 else return false end end local obj = basic_robot.data[name].obj; @@ -326,6 +323,13 @@ end basic_robot.commands.attack = function(name, target) -- attack range 4, damage 5 + local energy = 0; + if basic_robot.maxenergy~=0 then + local data = basic_robot.data[name]; + energy = data.energy; + if energy > 0 then data.energy = energy-1 else return false end + end + local reach = 4; local damage = 5; @@ -516,6 +520,26 @@ minetest.register_node("basic_robot:button"..R..G..B, }) end +local register_robot_button_number = function(number,type) +minetest.register_node("basic_robot:button"..number, + { + description = "robot button", + tiles = {"robot_button".. number .. ".png"}, + is_ground_content = false, + groups = {cracky=3}, + on_punch = function(pos, node, player) + local name = player:get_player_name(); if name==nil then return end + local round = math.floor; + local r = 20; local ry = 2*r; + local ppos = {x=round(pos.x/r+0.5)*r,y=round(pos.y/ry+0.5)*ry+1,z=round(pos.z/r+0.5)*r}; + local meta = minetest.get_meta(ppos); + local name = meta:get_string("name"); + local data = basic_robot.data[name]; + if data then data.keyboard = {x=pos.x,y=pos.y,z=pos.z, puncher = player:get_player_name(), type = type} end + end + }) +end + register_robot_button("FF","FF","FF",1); register_robot_button("80","80","80",2); register_robot_button("FF","80","80",3); @@ -523,6 +547,8 @@ register_robot_button("80","FF","80",4); register_robot_button("80","80","FF",5); register_robot_button("FF","FF","80",6); +for i = 0,9 do register_robot_button_number(i,i+7) end + -- interactive button for robot: place robot on top of protector to intercept events @@ -559,6 +585,8 @@ basic_robot.commands.keyboard = { nodename = "basic_robot:button8080FF"; elseif type == 6 then nodename = "basic_robot:buttonFFFF80"; + elseif type>=7 then + nodename = "basic_robot:button"..(type-7); end minetest.swap_node(pos, {name = nodename}) @@ -610,4 +638,19 @@ basic_robot.commands.craft = function(item, name) inv:add_item("main",ItemStack(item)) return true -end \ No newline at end of file +end + +--FORMS +basic_robot.commands.show_form = function(name, playername, form) + minetest.show_formspec(playername, "robot_form".. name, form) +end + + +-- handle robots receiving fields +minetest.register_on_player_receive_fields(function(player, formname, fields) + if not string.sub(formname,1,10) == "robot_form" then return end + local name = string.sub(formname,11); -- robot name + if not basic_robot.data[name] then return end + basic_robot.data[name].read_form = fields; + basic_robot.data[name].form_sender = player:get_player_name() or ""; +end) \ No newline at end of file diff --git a/init.lua b/init.lua index 6bd4724..8f57e50 100644 --- a/init.lua +++ b/init.lua @@ -148,6 +148,18 @@ function getSandboxEnv (name) return sender,mail end, + read_form = function() + local fields = basic_robot.data[name].read_form; + local sender = basic_robot.data[name].form_sender; + basic_robot.data[name].read_form = nil; + basic_robot.data[name].form_sender = nil; + return sender,fields + end, + + show_form = function(playername, form) + commands.show_form(name, playername, form) + end, + send_mail = function(target,mail) if not basic_robot.data[target] then return false end basic_robot.data[target].listen_mail = mail; diff --git a/textures/robot_button0.png b/textures/robot_button0.png new file mode 100644 index 0000000000000000000000000000000000000000..de86a70d84ae71e284c7350ab6ae2a070d46b52c GIT binary patch literal 167 zcmeAS@N?(olHy`uVBq!ia0vp^0wBx?BpA#)4xIr~OiAAEE({E-dX-L1P>`6JSE84fTB2a0XP{?ju$GJK08o*dr;B4q z#jWHY|K~F{{kvlPXG8jrg!3OF=RN#fW58r|K*|1-L1P>`6JSE84fTB2a0XP{?ju$GJK08o*Hr;B4q t#jWHY|K~II{kvlPhhcHO1jjNqhUurJy;j~|_8O>$!PC{xWt~$(697LzDn0-J literal 0 HcmV?d00001 diff --git a/textures/robot_button2.png b/textures/robot_button2.png new file mode 100644 index 0000000000000000000000000000000000000000..21dea12b909fec5a38c8c5fc9772b4ac4db91c41 GIT binary patch literal 173 zcmeAS@N?(olHy`uVBq!ia0vp^0wBx?BpA#)4xIr~OiAAEE({E-dX-L1P>`6JSE84fTB2a0XP{?ju$GJK08o*Rr;B4q z#jWHY|K~F{{kv)WXJYz~i|0RVp8v4k{;+*zoBcN)`+vrN90#LT=By}Z;C1rt33 zJwt=FTwDi$ih?{{978PpkDfos#h}RHdhy@?<+`8t8cbHvuv%TRr(3h=MR)+mX2G>- zH!c}XuI6`a2%paG^FVdQ&MBb@0Q(0>Pyhe` literal 0 HcmV?d00001 diff --git a/textures/robot_button4.png b/textures/robot_button4.png new file mode 100644 index 0000000000000000000000000000000000000000..cad5c1004b2453148caa508386394f5fb0f81d7b GIT binary patch literal 219 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucLCF%=h?3y^w370~qEv>0#LT=By}Z;C1rt33 zJwt=FTwDi$io88t978PpkDiU@Vo=~h@bCL2O7)Z>FVdQ I&MBb@0E^*6Bme*a literal 0 HcmV?d00001 diff --git a/textures/robot_button5.png b/textures/robot_button5.png new file mode 100644 index 0000000000000000000000000000000000000000..d4c3454aa029d7cfcd3787e335c5606861834a31 GIT binary patch literal 166 zcmeAS@N?(olHy`uVBq!ia0vp^0wBx?BpA#)4xIr~OiAAEE({E-dX-L1P>`6JSE84fTB2a0XP{?ju$GJK08o*tr;B4q z#jWHY|K~F{{X1d&XF~dqpYknr4LAS)maO~MEa9Lz!-yfbQ?hqq)c0#LT=By}Z;C1rt33 zJwt=FTwDi$io85s978PpkDd+WVo=~-L1P>`6JSE84fTB2a0XP{?ju$GJK08o*Jr;B4q z#jWHY|K~F{)txZ@^C11l{qrB{?GD#hw$*>*`Tt7t-vI$1Nrt#@k{u2q;jTbE44$rj JF6*2UngF+jGoAnd literal 0 HcmV?d00001 diff --git a/textures/robot_button8.png b/textures/robot_button8.png new file mode 100644 index 0000000000000000000000000000000000000000..ebfcdaa06aea4371d30651860bbdea4f8f829fba GIT binary patch literal 164 zcmeAS@N?(olHy`uVBq!ia0vp^0wBx?BpA#)4xIr~OiAAEE({E-dX-L1P>`6JSE84fTB2a0XP{?ju$GJK08o*#r;B4q z#jWHY|K~F{{kv)WXJYz~i|0RlwmHmSsbXf|!5hrRkSr)^AJrYn22{@A>FVdQ&MBb@ E0ALp`1poj5 literal 0 HcmV?d00001 diff --git a/textures/robot_button9.png b/textures/robot_button9.png new file mode 100644 index 0000000000000000000000000000000000000000..660c6874a60ad7ac0ac66b706dbc6993425a402a GIT binary patch literal 225 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucLCF%=h?3y^w370~qEv>0#LT=By}Z;C1rt33 zJwt=FTwDi$iUK`d978PpkDk5AbwGi~Iq?7g<<_0sFQld#1eDG5x&5G{|DP6*;+>x* zbHj8lEn|8pxZIcZu-~2y1v6%NeP&)Cr0gARpfl-tr*mS6$>Q?m+=AkpZ|AOmB(ci{ PXgGtXtDnm{r-UW|NkvK0 literal 0 HcmV?d00001