Skip to content

Commit

Permalink
- additional interactive buttons - with numbers - perfect to make gam…
Browse files Browse the repository at this point in the history
…es with

- form display and handling for robots
  • Loading branch information
rnd1 committed Mar 4, 2017
1 parent 4c169bb commit 80aeca2
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 7 deletions.
57 changes: 50 additions & 7 deletions commands.lua
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -516,13 +520,35 @@ 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);
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
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -610,4 +638,19 @@ basic_robot.commands.craft = function(item, name)

inv:add_item("main",ItemStack(item))
return true
end
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)
12 changes: 12 additions & 0 deletions init.lua
Expand Up @@ -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;
Expand Down
Binary file added textures/robot_button0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added textures/robot_button1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added textures/robot_button2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added textures/robot_button3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added textures/robot_button4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added textures/robot_button5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added textures/robot_button6.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added textures/robot_button7.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added textures/robot_button8.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added textures/robot_button9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 80aeca2

Please sign in to comment.