Separated code blocks into smaller files

master
Austin Shenk 2013-01-21 19:50:46 -05:00
parent 843b8193d6
commit 1b20eb33b3
7 changed files with 221 additions and 0 deletions

1
creativeGeneral.lua Normal file

File diff suppressed because one or more lines are too long

17
creativeInitialStuff.lua Normal file
View File

@ -0,0 +1,17 @@
minetest.register_node("adventures:initial_stuff", {
description = "Initial Stuff",
walkable = false,
groups = {crumbly=3},
tiles = {"adventures_initialStuff.png"},
on_construct = function(pos)
adventures.sources[adventures.positionToString(pos)] = {name="adventures:initial_stuff",pos=pos}
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", "size[8,9]"..
"list[detached:initialstuff;main;0,0;8,4;]"..
"list[current_player;main;0,5;8,4;]")
meta:get_inventory():set_size("main", 32)
end,
on_destruct = function(pos)
adventures.sources[adventures.positionToString(pos)] = nil
end,
})

69
creativeQuest.lua Normal file
View File

@ -0,0 +1,69 @@
local function updateQuest(meta)
return "size[8,9]"..
"field[0.25,0.25;5,1;name;Quest Name;"..meta:get_string("name").."]"..
"field[0.25,1.25;5,1;objective;Objective;"..meta:get_string("objective").."]"..
"field[0.25,2.25;5,1;description;Description;"..meta:get_string("description").."]button[5.5,0;2,0.75;save;Save]"..
"label[0,2.5;Quest Items]list[context;items;0,3;2,2;]"..
"label[6,2.5;Quest Reward]list[context;reward;6,3;2,2;]"..
"button[2.325,4;.75,.5;idminusten;<<]button[2.925,4;.75,.5;idminusone;<]label[3.75,3.875;"..meta:get_int("id").."]button[4.325,4;.75,.5;idplusone;>]button[4.925,4;.75,.5;idplusten;>>]"..
"list[current_player;main;0,5;8,4]"
end
minetest.register_node("adventures:quest", {
description = "Quest",
walkable = false,
groups = {crumbly=3},
tiles = {"adventures_quest.png"},
on_construct = function(pos)
adventures.sources[adventures.positionToString(pos)] = {name="adventures:quest",pos=pos}
local meta = minetest.env:get_meta(pos)
local data = adventures.sourceData[adventures.positionToString(pos)]
if data ~= nil then
meta:set_string("name", data[5])
meta:set_string("objective", data[6])
meta:set_string("description", data[7])
meta:set_int("id", data[8])
else
meta:set_string("name", "")
meta:set_string("objective", "")
meta:set_string("description", "")
meta:set_int("id", 0)
end
meta:set_string("formspec", updateQuest(meta))
local inv = meta:get_inventory()
inv:set_size("items", 4)
inv:set_size("reward", 4)
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.env:get_meta(pos)
if fields.save then
meta:set_string("name", fields.name)
meta:set_string("objective", fields.objective)
meta:set_string("description", fields.description)
end
if fields.idminusten then meta:set_int("id", meta:get_int("id")-10) end
if fields.idminusone then meta:set_int("id", meta:get_int("id")-1) end
if fields.idplusone then meta:set_int("id", meta:get_int("id")+1) end
if fields.idplusten then meta:set_int("id", meta:get_int("id")+10) end
meta:set_string("formspec", updateQuest(meta))
end,
on_destruct = function(pos)
adventures.sources[adventures.positionToString(pos)] = nil
end,
})
minetest.register_node("adventures:quest_destination", {
description = "Quest Destination",
walkable = false,
groups = {crumbly=3},
tiles = {"adventures_questDestination.png"},
on_construct = function(pos)
adventures.sources[adventures.positionToString(pos)] = {name="adventures:quest",pos=pos}
local meta = minetest.env:get_meta(pos)
end,
on_receive_fields = function(pos, formname, fields, sender)
end,
on_destruct = function(pos)
adventures.sources[adventures.positionToString(pos)] = nil
end,
})

3
standardInitialStuff.lua Normal file
View File

@ -0,0 +1,3 @@
function adventures.giveInitialStuff(player)
player:get_inventory():set_list("main", minetest.get_inventory({type="detached",name="initialstuff"}):get_list("main"))
end

33
standardProtect.lua Normal file
View File

@ -0,0 +1,33 @@
function adventures.storeUnbreakableNodes(data)
local start = adventures.getStartNode(data)
for y=0,data[10]-1,1 do
for z=0,data[8]-1,1 do
for x=0,data[8]-1,1 do
adventures.unbreakable[adventures.positionToString({x=start.x+x,y=start.y+y,z=start.z+z})] = true
end
end
end
end
function adventures.storeUnbuildableNodes(data)
local start = adventures.getStartNode(data)
for y=0,data[10]-1,1 do
for z=0,data[8]-1,1 do
for x=0,data[8]-1,1 do
adventures.unbuildable[adventures.positionToString({x=start.x+x,y=start.y+y,z=start.z+z})] = true
end
end
end
end
function adventures.storeFullyProtectedNodes(data)
local start = adventures.getStartNode(data)
for y=0,data[10]-1,1 do
for z=0,data[8]-1,1 do
for x=0,data[8]-1,1 do
adventures.unbuildable[adventures.positionToString({x=start.x+x,y=start.y+y,z=start.z+z})] = true
adventures.unbreakable[adventures.positionToString({x=start.x+x,y=start.y+y,z=start.z+z})] = true
end
end
end
end

62
standardQuest.lua Normal file
View File

@ -0,0 +1,62 @@
local function subdivideObjective(str, desc)
local subdata = str:split(" ")
if subdata[1] == "Return" then
return {type=subdata[1], description=desc, count=subdata[2],content=subdata[3]}
elseif subdata[1] == "Collect" then
return {type=subdata[1], description=desc, count=subdata[2],content=subdata[3]}
elseif subdata[1] == "Kill" then
return {type=subdata[1], description=desc, count=subdata[2],content=subdata[3]}
end
end
local function convertObjectiveString(str, desc)
local objs = {}
if str:find("|") == nil then
objs[1] = subdivideObjective(str, desc)
else
local data = str:split("|")
local descdata = desc:split("|")
for i,o in ipairs(data) do
if o ~= nil then
objs[i] = subdivideObjective(o, descdata[i])
end
end
end
return objs
end
function adventures.storeQuestData(data)
local pos = {x=data[2],y=data[3],z=data[4]}
local meta = minetest.env:get_meta(pos)
local objs = convertObjectiveString(meta:get_string("objective"), meta:get_string("description"))
local y = 3+table.getn(objs)
local str = "label[0,0;"..meta:get_string("name").."]"..
"list[context;reward;4,"..(y-3)..";2,2;]"..
"list[context;items;0,"..(y-3)..";2,2;]"..
"button[1.5,"..(y-1)..";1.5,0.75;accept;Accept]"..
"button_exit[3,"..(y-1)..";1.5,0.75;decline;Decline]"
for i,obj in pairs(objs) do
str = str.."label[0.125,"..(i/2)..";"..obj.description.."]"
end
str = "size[6,"..y.."]"..str
meta:set_string("formspec", str)
adventures.quests[meta:get_string("name")] = {objectives = objs, id = meta:get_int("id")}
end
minetest.register_node("adventures:quest", {
description = "Quest",
walkable = true,
groups = {immortal=1},
tiles = {"adventures_quest.png"},
on_receive_fields = function(pos, formname, fields, sender)
if fields.accept then
local meta = minetest.env:get_meta(pos)
local quests = adventures.playerQuests[sender]
quests[meta:get_string("name")] = adventures.quests[meta:get_string("name")]
end
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
return 0 end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
return 0 end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
return 0 end
})

36
standardSpawning.lua Normal file
View File

@ -0,0 +1,36 @@
function adventures.storeSpawnPositions(data)
local start = adventures.getStartNode(data)
for y=0,data[10]-1,1 do
for z=0,data[8]-1,1 do
for x=0,data[8]-1,1 do
table.insert(adventures.spawnPoints, {x=start.x+x,y=start.y+y,z=start.z+z})
adventures.unbuildable[adventures.positionToString({x=start.x+x,y=start.y+y,z=start.z+z})] = true
end
end
end
end
function adventures.storeRespawnPositions(data)
local start = adventures.getStartNode(data)
local points = {}
for y=0,data[10]-1,1 do
for z=0,data[8]-1,1 do
for x=0,data[8]-1,1 do
table.insert(points, {x=start.x+x,y=start.y+y,z=start.z+z})
adventures.unbuildable[adventures.positionToString({x=start.x+x,y=start.y+y,z=start.z+z})] = true
end
end
end
adventures.respawnPoints[data[11]] = points
end
function adventures.storeCheckpointPositions(data)
local start = adventures.getStartNode(data)
for y=0,data[10]-1,1 do
for z=0,data[8]-1,1 do
for x=0,data[8]-1,1 do
adventures.checkPoints[adventures.positionToString({x=start.x+x,y=start.y+y,z=start.z+z})] = data[11]
end
end
end
end