automatically start one robot at server start: setting 'local admin_bot_pos' defines its position

self.operations() displays remaining available operations for robot

tweaked operation costs for dig/move/..., total available operations per step is now 10
master
rnd 2018-07-20 13:06:06 +02:00
parent f110b93dc3
commit c3599643a9
2 changed files with 39 additions and 11 deletions

View File

@ -68,7 +68,7 @@ local check_operations = function(name, amount, quit)
data.operations = operations
else
if quit then
error("robot out of available operations in one step."); return false
error("Robot out of available operations in one step (1s). View available operations with self.operations() and check help to see how much operations each action requires."); return false
end
return false
end
@ -77,11 +77,11 @@ end
basic_robot.commands.move = function(name,dir)
check_operations(name,2,true)
local obj = basic_robot.data[name].obj;
local pos = pos_in_dir(obj, dir)
check_operations(name,0.25,true)
-- can move through walkable nodes
if minetest.registered_nodes[minetest.get_node(pos).name].walkable then return end
-- up; no levitation!
@ -122,7 +122,7 @@ basic_robot.digcosts = { -- 1 energy = 1 coal
basic_robot.commands.dig = function(name,dir)
local energy = 0;
check_operations(name,2,true)
check_operations(name,6,true)
local obj = basic_robot.data[name].obj;
local pos = pos_in_dir(obj, dir)
@ -171,7 +171,7 @@ end
basic_robot.commands.insert_item = function(name,item, inventory,dir)
check_operations(name,0.4,true)
check_operations(name,2,true)
local obj = basic_robot.data[name].obj;
local tpos = pos_in_dir(obj, dir); -- position of target block
local luaent = obj:get_luaentity();
@ -214,6 +214,8 @@ basic_robot.commands.insert_item = function(name,item, inventory,dir)
end
basic_robot.commands.take_item = function(name,item, inventory,dir)
check_operations(name,2,true)
local obj = basic_robot.data[name].obj;
local tpos = pos_in_dir(obj, dir); -- position of target block
local luaent = obj:get_luaentity();
@ -284,7 +286,8 @@ basic_robot.no_teleport_table = {
basic_robot.commands.pickup = function(r,name)
if r>8 then return false end
check_operations(name,4,true)
local pos = basic_robot.data[name].obj:getpos();
local spos = basic_robot.data[name].spawnpos; -- position of spawner block
local meta = minetest.get_meta(spos);
@ -342,7 +345,7 @@ end
basic_robot.commands.place = function(name,nodename, param2,dir)
check_operations(name,0.4,true)
check_operations(name,2,true)
local obj = basic_robot.data[name].obj;
local pos = pos_in_dir(obj, dir)
local luaent = obj:get_luaentity();
@ -386,7 +389,7 @@ end
basic_robot.commands.attack = function(name, target) -- attack range 4, damage 5
local energy = 0;
check_operations(name,2,true);
check_operations(name,4,true);
local reach = 4;
local damage = 5;

View File

@ -9,11 +9,14 @@ basic_robot.advanced_count = 16 -- how many robots player with robot privs can h
basic_robot.radius = 32; -- divide whole world into blocks of this size - used for managing events like keyboard punches
basic_robot.password = "raN___dOM_ p4S"; -- IMPORTANT: change it before running mod, password used for authentifications
local admin_bot_pos = {x=0,y=0,z=0} -- position of admin robot spawner that will be run automatically on server start
basic_robot.maxoperations = 10; -- how many operations (dig, generate energy,..) available per run, 0 = unlimited
basic_robot.dig_require_energy = true; -- does robot require energy to dig?
basic_robot.bad_inventory_blocks = { -- disallow taking from these nodes inventories to prevent player abuses
["craft_guide:sign_wall"] = true,
}
basic_robot.maxoperations = 2; -- how many operations (dig, generate energy,..) available per run, 0 = unlimited
basic_robot.dig_require_energy = true; -- does robot require energy to dig?
----------------------
basic_robot.http_api = minetest.request_http_api();
@ -88,6 +91,7 @@ function getSandboxEnv (name)
pos = function() return basic_robot.data[name].obj:getpos() end,
spawnpos = function() local pos = basic_robot.data[name].spawnpos; return {x=pos.x,y=pos.y,z=pos.z} end,
name = function() return name end,
operations = function() return basic_robot.data[name].operations end,
viewdir = function() local yaw = basic_robot.data[name].obj:getyaw(); return {x=math.cos(yaw), y = 0, z=math.sin(yaw)} end,
set_properties = function(properties)
@ -1135,6 +1139,15 @@ local spawn_robot = function(pos,node,ttl)
self.running = 1
end
--admin robot that starts automatically after server start
minetest.after(10, function()
minetest.forceload_block(admin_bot_pos,true) -- load map position
spawn_robot(admin_bot_pos,node,1)
print("[BASIC_ROBOT] admin bot started.")
end)
local despawn_robot = function(pos)
local meta = minetest.get_meta(pos);
@ -1388,6 +1401,7 @@ local on_receive_robot_form = function(pos, formname, fields, sender)
" sender,mail = self.read_mail() reads mail, if any\n" ..
" self.pos() returns table {x=pos.x,y=pos.y,z=pos.z}\n"..
" self.name() returns robot name\n"..
" self.operations() returns remaining robot operations\n"..
" self.set_properties({textures=.., visual=..,visual_size=.., , ) sets visual appearance\n"..
" set_animation(anim_start,anim_end,anim_speed,anim_stand_start) set mesh animation \n"..
" self.spam(0/1) (dis)enable message repeat to all\n"..
@ -1539,6 +1553,17 @@ local on_receive_robot_form = function(pos, formname, fields, sender)
end
-- handle form: when rightclicking robot entity, remote controller
-- minetest.register_on_player_receive_fields(
-- function(player, formname, fields)
-- local gui = robogui[formname];
-- if gui then gui.response(player,formname,fields) end
-- end
-- )
minetest.register_on_player_receive_fields(
function(player, formname, fields)