colorize, isadmin fix. robots now have rom variable
This commit is contained in:
parent
a2a14cca15
commit
d9a90160a7
@ -327,6 +327,7 @@ basic_robot.commands.grab = function(name,target)
|
|||||||
|
|
||||||
if tplayer:get_attach() then
|
if tplayer:get_attach() then
|
||||||
tplayer:set_detach()
|
tplayer:set_detach()
|
||||||
|
return false
|
||||||
else
|
else
|
||||||
tplayer:set_attach(obj, "", {x=0,y=5,z=0}, {x=0,y=0,z=0})
|
tplayer:set_attach(obj, "", {x=0,y=5,z=0}, {x=0,y=0,z=0})
|
||||||
end
|
end
|
||||||
|
44
init.lua
44
init.lua
@ -95,8 +95,8 @@ function getSandboxEnv (name)
|
|||||||
right = function(itemname, inventory) return commands.check_inventory(name,itemname, inventory,2) end,
|
right = function(itemname, inventory) return commands.check_inventory(name,itemname, inventory,2) end,
|
||||||
forward = function(itemname, inventory) return commands.check_inventory(name,itemname, inventory,3) end,
|
forward = function(itemname, inventory) return commands.check_inventory(name,itemname, inventory,3) end,
|
||||||
backward = function(itemname, inventory) return commands.check_inventory(name,itemname, inventory,4) end,
|
backward = function(itemname, inventory) return commands.check_inventory(name,itemname, inventory,4) end,
|
||||||
down = function(itemname, inventory) return commands.check_inventory(name,itemname, inventory,5) end,
|
down = function(itemname, inventory) return commands.check_inventory(name,itemname, inventory,6) end,
|
||||||
up = function(itemname, inventory) return commands.check_inventory(name,itemname, inventory,6) end,
|
up = function(itemname, inventory) return commands.check_inventory(name,itemname, inventory,5) end,
|
||||||
self = function(itemname, inventory) return commands.check_inventory(name,itemname, inventory,0) end,
|
self = function(itemname, inventory) return commands.check_inventory(name,itemname, inventory,0) end,
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -194,6 +194,7 @@ function getSandboxEnv (name)
|
|||||||
local obj = basic_robot.data[name].obj;
|
local obj = basic_robot.data[name].obj;
|
||||||
obj:set_properties({nametag = "[" .. name .. "] " .. text});
|
obj:set_properties({nametag = "[" .. name .. "] " .. text});
|
||||||
end,
|
end,
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
find_nodes =
|
find_nodes =
|
||||||
@ -318,6 +319,8 @@ function getSandboxEnv (name)
|
|||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
|
||||||
|
rom = basic_robot.data[name].rom,
|
||||||
|
|
||||||
string = {
|
string = {
|
||||||
byte = string.byte, char = string.char,
|
byte = string.byte, char = string.char,
|
||||||
find = string.find,
|
find = string.find,
|
||||||
@ -355,9 +358,10 @@ function getSandboxEnv (name)
|
|||||||
clock = os.clock,
|
clock = os.clock,
|
||||||
difftime = os.difftime,
|
difftime = os.difftime,
|
||||||
time = os.time,
|
time = os.time,
|
||||||
|
date = os.date,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
colorize = core.colorize,
|
||||||
tonumber = tonumber,
|
tonumber = tonumber,
|
||||||
pairs = pairs,
|
pairs = pairs,
|
||||||
ipairs = ipairs,
|
ipairs = ipairs,
|
||||||
@ -379,7 +383,7 @@ function getSandboxEnv (name)
|
|||||||
--special sandbox for admin
|
--special sandbox for admin
|
||||||
local isadmin=basic_robot.data[name].isadmin
|
local isadmin=basic_robot.data[name].isadmin
|
||||||
|
|
||||||
if not isadmin then
|
if isadmin~=1 then
|
||||||
env._G = env;
|
env._G = env;
|
||||||
else
|
else
|
||||||
env._G=_G;
|
env._G=_G;
|
||||||
@ -434,8 +438,7 @@ end
|
|||||||
|
|
||||||
-- COMPILATION
|
-- COMPILATION
|
||||||
|
|
||||||
local function CompileCode ( script )
|
local function preprocess_code(script)
|
||||||
|
|
||||||
--[[ idea: in each local a = function (args) ... end insert counter like:
|
--[[ idea: in each local a = function (args) ... end insert counter like:
|
||||||
local a = function (args) counter() ... end
|
local a = function (args) counter() ... end
|
||||||
when counter exceeds limit exit with error
|
when counter exceeds limit exit with error
|
||||||
@ -508,6 +511,13 @@ local function CompileCode ( script )
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return script
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function CompileCode ( script )
|
||||||
|
|
||||||
|
|
||||||
--minetest.chat_send_all(script)
|
--minetest.chat_send_all(script)
|
||||||
--if true then return nil, "" end
|
--if true then return nil, "" end
|
||||||
|
|
||||||
@ -525,11 +535,12 @@ end
|
|||||||
local function setCode( name, script ) -- to run script: 1. initSandbox 2. setCode 3. runSandbox
|
local function setCode( name, script ) -- to run script: 1. initSandbox 2. setCode 3. runSandbox
|
||||||
|
|
||||||
local err;
|
local err;
|
||||||
if not basic_robot.data[name].isadmin then
|
if basic_robot.data[name].isadmin~=1 then
|
||||||
err = check_code(script);
|
err = check_code(script);
|
||||||
|
script = preprocess_code(script);
|
||||||
end
|
end
|
||||||
if err then return err end
|
if err then return err end
|
||||||
|
|
||||||
local bytecode, err = CompileCode ( script );
|
local bytecode, err = CompileCode ( script );
|
||||||
if err then return err end
|
if err then return err end
|
||||||
basic_robot.data[name].bytecode = bytecode;
|
basic_robot.data[name].bytecode = bytecode;
|
||||||
@ -798,9 +809,10 @@ local spawn_robot = function(pos,node,ttl)
|
|||||||
|
|
||||||
|
|
||||||
local data = basic_robot.data[name];
|
local data = basic_robot.data[name];
|
||||||
if not data then
|
if data == nil then
|
||||||
basic_robot.data[name] = {};
|
basic_robot.data[name] = {};
|
||||||
data = basic_robot.data[name];
|
data = basic_robot.data[name];
|
||||||
|
data.rom = {};
|
||||||
end
|
end
|
||||||
|
|
||||||
data.owner = owner;
|
data.owner = owner;
|
||||||
@ -893,7 +905,10 @@ local on_receive_robot_form = function(pos, formname, fields, sender)
|
|||||||
local id = math.floor(tonumber(fields.id) or 1);
|
local id = math.floor(tonumber(fields.id) or 1);
|
||||||
local owner = meta:get_string("owner")
|
local owner = meta:get_string("owner")
|
||||||
if not basic_robot.ids[owner] then setupid(owner) end
|
if not basic_robot.ids[owner] then setupid(owner) end
|
||||||
if id<1 or id>basic_robot.ids[owner].maxid then return end
|
if id<1 or id>basic_robot.ids[owner].maxid then
|
||||||
|
local privs = minetest.get_player_privs(name);
|
||||||
|
if not privs.privs then return end
|
||||||
|
end
|
||||||
meta:set_int("id",id) -- set active id for spawner
|
meta:set_int("id",id) -- set active id for spawner
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -940,8 +955,9 @@ local on_receive_robot_form = function(pos, formname, fields, sender)
|
|||||||
"self.spawnpos() returns position of spawner block\n"..
|
"self.spawnpos() returns position of spawner block\n"..
|
||||||
"self.viewdir() returns vector of view for robot\n"..
|
"self.viewdir() returns vector of view for robot\n"..
|
||||||
"self.fire(speed, pitch,gravity) fires a projectile from robot\n"..
|
"self.fire(speed, pitch,gravity) fires a projectile from robot\n"..
|
||||||
"self.fire_pos() returns last hit position\n "..
|
"self.fire_pos() returns last hit position\n"..
|
||||||
"self.label(text) changes robot label";
|
"self.label(text) changes robot label\n"..
|
||||||
|
"rom is aditional table that can store persistent data, like rom.x=1\n";
|
||||||
|
|
||||||
text = minetest.formspec_escape(text);
|
text = minetest.formspec_escape(text);
|
||||||
|
|
||||||
@ -1166,7 +1182,7 @@ end
|
|||||||
minetest.register_node("basic_robot:spawner", {
|
minetest.register_node("basic_robot:spawner", {
|
||||||
description = "Spawns robot",
|
description = "Spawns robot",
|
||||||
tiles = {"cpu.png"},
|
tiles = {"cpu.png"},
|
||||||
groups = {oddly_breakable_by_hand=2,mesecon_effector_on = 1},
|
groups = {cracky=3, mesecon_effector_on = 1},
|
||||||
drawtype = "allfaces",
|
drawtype = "allfaces",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
param1=1,
|
param1=1,
|
||||||
@ -1298,7 +1314,7 @@ minetest.register_craftitem("basic_robot:control", {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
script = itemstack:get_metadata();
|
local script = itemstack:get_metadata();
|
||||||
if script == "" then
|
if script == "" then
|
||||||
--display control form
|
--display control form
|
||||||
minetest.show_formspec(owner, "robot_manual_control_" .. name, get_manual_control_form(name));
|
minetest.show_formspec(owner, "robot_manual_control_" .. name, get_manual_control_form(name));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user