Mods/basic robot/RC

From Minetest Wiki
Jump to navigation Jump to search


Intro

Spawner and basic_robot, remotecontrol with colored buttons

This page is dedicated to using basic_robots with a remote.
A remotecontrol (rc for short) can be used to give orders to a robot.

The rc has 2 modes:

  • manual (leftclick) - without any programming, it shows a form with buttons for moving, turning and digging.
Each keypress causes the robot to do one action.
This mode is quite useful for mining, because the robot can dig faster then the player.
  • programming (rightclick) - shows a small textarea for entering a few lines of code, an id-field, and a SAVE-button.
Each click of the remote will cause the robot to execute
the code in the textarea once

The id-setting determines which remote controls which robot.
So, you can have several robots active at once, and control them with different remotes.

How to get

Chat-commands

Get a robot-spawner: "/giveme basic_robot:spawner"
Get a remote: "/giveme basic_robot:control"

This only works in singleplayer, in creative-mode, or for the server-admin.

Craft

Recipe for a spawner:

M M M
M M M
S I S

with M=mese_crystal, S=stone, I=steel_ingot.
Cost to build: 6 mese-crystals, 2 stone, 1 steel_ingot.

Recipe for a remotecontrol :

s
M

with M=mese_crystal, s=stick.
Cost to build: 1 mese-crystal, 1 stick.

Buy (at ROBOTS-Server)

On the robots-server at 46.150.38.198:30000, you can simply buy a robot and a remote, at the shop next to the spawn-building.
The current price is 2 gold-ingots for a spawner and 1 gold for a remote, so they are really cheap.

Demo

Report position 1

Place the spawner on the ground, and put the remote on the hotbar.

Rightclick the spawner, enter this program:

 -- Report position of spawner and robot:
 if not p0 then
   p0 = self.spawnpos()
   say("Spawner-position x="..p0.x.." y=".. p0.y.." z=".. p0.z)
 end
 
 -- Report position of robot: 
 p1 = self.pos()
 say("Robot-position x="..p1.x.." y=".. p1.y.." z=".. p1.z)
  • Press the SAVE-button.
  • Press the START-button.
  • Leftclick the remote, to bring up the manual control, and guide the robot around.

The robot should report the position of the spawner once, and its current position on every tick.

This works, but fills the chat with text from all those position-reports.

Running this on a server in multiplayer would require some changes.

Report position 2

  • Rightclick the spawner, enter this program:
 -- Report position of spawner:
 if not p0 then
   p0 = self.spawnpos()
   say("Spawner-position x="..p0.x.." y=".. p0.y.." z=".. p0.z)
 end
  • Press the SAVE-button.
  • Press the START-button.
  • Rightclick the remote, while pointing at nothing
as in, pointing at the sky, or at nodes out of range
  • enter this program:
 -- Report position of robot:
 p1 = self.pos()
 say("Robot-position x="..p1.x.." y=".. p1.y.." z=".. p1.z)
  • Press the SAVE-button.
  • Leftclick the remote.

Like above, the spawner-position is reported only once,
but now the robot-position is reported only once for each leftclick on the remote.

As that remote is in program-mode now,
we need another, 'empty' remote to steer the robot around.

So, for a good start, get 1 spawner, and 2-3 remotes.

Apps

This page has a focus on small, useful programs, and programs for the remote.

Report distance

The robot only works well if spawner, player and robot are close enough together.
The reason is, that in minetest actions only happen within a few blocks around the player(s),
and the server might unload 'unused' blocks from memory.
This distance depends on the server-setting, usually 3-5 blocks.

Where a block is 16x16x16 nodes.

Here, we calculate the distance between spawner and robot:
Spawner:

 -- Report position of spawner:
 if not p0 then
   p0 = self.spawnpos()
   say("Spawner-position x="..p0.x.." y=".. p0.y.." z=".. p0.z)
 end

Remote:

 -- Distance between spawner and robot:
 p0=self.spawnpos(); p1=self.pos()
 dx=math.abs(p0.x-p1.x); dy=math.abs(p0.y-p1.y); dz= math.abs(p0.z-p1.z)
 md=dx+dy+dz  -- Manhatten-distance
 msg="Robot-position x="..p1.x.." y=".. p1.y.." z=".. p1.z  --say(msg)
 self.label("Distance: "..md)

Here, we calculate the distance as the Manhatten-distance.

Build bridge

This 'paves' a walkable bridge, even over water or thru the air.
Robot needs the building material in its inventory when starting.

 dig.forward_down()
 place.forward_down("default:dirt")
 --place.forward_down("default:cobble")
 move.forward()

Todo

...