|
| 07 Sep 2012 05:47 PM |
wait(3)
local TOOL = script.Parent
local SCREEN_GUI = TOOL.ScreenGui local FRAME = SCREEN_GUI.Frame
--BUTTONS local CLEAR_BUTTON = FRAME.ClearButton local ITEM_BUTTON = FRAME.ItemButton local PROCESS_BUTTON = FRAME.ProcessButton local TOOL_BUTTON = FRAME.ToolButton
--LABELS local ALERT_LABEL = FRAME.AlertLabel local LIST_LABEL = FRAME.ListLabel local TARGET_LABEL = FRAME.TargetLabel
--OTHER local RANGE = 15 local SERVICES = game.Workspace.Services
--MAIN STUFF local SELECTED = {} local CHOOSING = false
--INGREDIENT TABLES local TOOL_TABLE = {
{ {"Stone", "Stone"}, "Sword" },
{ {"Stone", "Stone", "Stone", ""}, "Tower" },
{ {"Med Rock", "Med Rock", "Med Wood", ""}, "Well" },
{ {"Wall", "Wall", "Large Foliage", ""}, {"Large Hut Center", "Large Hut Edge", "Large Hut Door", "Large Hut Corner"} },
{ {"Med Rock", "Med Rock", "Med Wood", "Med Wood", ""}, {"M. Home Center", "M. Home Corner", "M. Home Edge", "M. Home Door", "M. Home Stairs", "Mine"} },
{ {"Med Rock", "Large Wood", "Large Wood", ""}, "Medieval Granary" },
{ {"Small Rock", "Small Rock", ""}, "Flint" },
{ {"Hull", ""}, "Raft" },
{ {"Small Wood", "Rope", ""}, "Crude Bucket" },
{ {"Wall", "Wall", "Med Rock", ""}, "Crude Granary" },
{ {"Small Handle", "Copper", "Copper", ""}, {"Copper Axe", "Copper Pickaxe"} },
{ {"Small Handle", "Iron", "Iron", ""}, {"Iron Axe", "Iron Pickaxe"} }
} --TOOL TABLE END
local ITEM_TABLE = {
{ {"Stone", "Stone"}, "Sword" },
{ {"Med Wood", "Med Wood", ""}, {"Wall", "Hull"} },
{ {"Large Wood", ""}, {"Wall", "Hull"} },
{ {"Hemp Stalk", "Hemp Stalk", ""}, "Fresh Hemp" },
{ {"Hemp", ""}, "Rope" },
{ {"Dough", ""}, "Bread Dough" }
} --ITEM TABLE END
local PROCESS_TABLE = {
{ {"Fresh Hemp", ""}, "Began drying...", function() processTimedNameChange(SELECTED[1], "Drying Hemp", "Dark green", 30, "Hemp", "Brown") end },
{ {"Small Foliage", ""}, "Began composting...", function() processTimedCompost(SELECTED[1], "Rotting Leaves", "Small Compost", 30) end },
{ {"Med Foliage", ""}, "Began composting...", function() processTimedCompost(SELECTED[1], "Rotting Leaves", "Med Compost", 30) end },
{ {"Large Foliage", ""}, "Began composting...", function() processTimedCompost(SELECTED[1], "Rotting Leaves", "Fertile Compost", 30) end },
{ {"Berry", "Small Compost", ""}, "Planted berry...", function() processTimedFarming(SELECTED[1], SELECTED[2], 30) end },
{ {"Wheat", "Med Compost", ""}, "Planted wheat...", function() processTimedFarming(SELECTED[1], SELECTED[2], 50) end },
{ {"Hemp Stalk", "Med Compost", ""}, "Planted hemp...", function() processTimedFarming(SELECTED[1], SELECTED[2], 40) end },
{ {"Apple", "Fertile Compost", ""}, "Planted apple...", function() processTimedFarming(SELECTED[1], SELECTED[2], 60) end }
} --PROCESS TABLE END
--PROCESSING FUNCTIONS
function processTimedNameChange(part, nameA, colorA, time, nameB, colorB) local partVal = createValue("Object", part.Name, part)
local nameAVal = createValue("String", "NameA", nameA) local nameBVal = createValue("String", "NameB", nameB) local colorAVal = createValue("BrickColor", "ColorA", getBC(colorA)) local colorBVal = createValue("BrickColor", "ColorB", getBC(colorB)) local timeVal = createValue("Number", "Time", time)
nameAVal.Parent = partVal nameBVal.Parent = partVal colorAVal.Parent = partVal colorBVal.Parent = partVal timeVal.Parent = partVal
partVal.Parent = SERVICES.TimedNameChange end
function processTimedCompost(part, rotName, finName, time) local partVal = createValue("Object", part.Name, part)
local rotNameVal = createValue("String", "RotName", rotName) local nameVal = createValue("String", "FinName", finName) local timeVal = createValue("Number", "Time", time)
rotNameVal.Parent = partVal nameVal.Parent = partVal timeVal.Parent = partVal
partVal.Parent = SERVICES.TimedCompost end
function processTimedFarming(part, compost, time) local partVal = createValue("Object", part.Name, part)
local compostVal = createValue("Object", "Compost", compost) local timeVal = createValue("Number", "Time", time)
compostVal.Parent = partVal timeVal.Parent = partVal
partVal.Parent = SERVICES.TimedFarming end
function createValue(type, name, value) local newVal = Instance.new(type.."Value") newVal.Name = name newVal.Value = value
return newVal end
function getBC(string) return BrickColor.new(string) end
--MAIN FUNCTIONS function updateList() local string = ""
for index, child in pairs(SELECTED) do if index ~= 1 then string = string..", " end
string = string..child.Name end
LIST_LABEL.Text = string end
function getIngName(index) local part = SELECTED[index]
if part == nil then return "" else return part.Name end end
function runIngredients(tab, process) if process == nil then process = false end
local required = tab[1] local made = tab[2] local func = tab[3]
if #SELECTED < 1 then return nil end
for index, child in pairs(required) do if getIngName(index) ~= child then return nil end end
if process then return made, func else return made end end
function alert(text) ALERT_LABEL.Text = "" wait(0.1) ALERT_LABEL.Text = text end
function getPC() local player = TOOL.Parent.Parent local char = player.Character
return player, char end
function lockCheck(part) return not part.Locked end
function distanceCheck(part) local player, char = getPC() local head = char.Head local dist = (head.Position - part.Position).magnitude
return (dist < RANGE) end
function haveCheck(part) for index, child in pairs(SELECTED) do if child == part then return true end end
return false end
function canUse(part) if part == nil then return false end
local bool = false
bool = (bool or lockCheck(part)) bool = (bool and distanceCheck(part))
return bool end
function clearList() SELECTED = {}
updateList() end
function deleteList() for index, child in pairs(SELECTED) do child:remove() end
clearList() end
function creationChoice(tab) CHOOSING = true
local chosen = nil
local x = 0 local y = 0
for index, child in pairs(tab) do local newButton = Instance.new("TextButton") newButton.Name = "ChoiceButton" newButton.Size = UDim2.new(0, 100, 0, 25) newButton.Position = UDim2.new(0, (400 + x), 1, (-301 + y)) newButton.Text = child
newButton.MouseButton1Down:connect(function() chosen = child end)
newButton.Parent = SCREEN_GUI
y = y + 25
if y > 100 then y = 0 x = x + 100 end end
while chosen == nil do wait() end
stopCreationChoice()
return chosen end
function stopCreationChoice() local buttons = SCREEN_GUI:GetChildren()
for index, child in pairs(buttons) do if child.Name == "ChoiceButton" then child:remove() end end
CHOOSING = false end
--BUTTON FUNCTIONS function clearSelected() if CHOOSING then return end
clearList()
alert("Ingredients cleared") end
function createTool() if CHOOSING then return end
local made = nil
for index, child in pairs(TOOL_TABLE) do made = runIngredients(child)
if made ~= nil then break end end
if type(made) == "table" then made = creationChoice(made) end
if made == nil then alert("Nothing created") clearList() else alert(made.." created!")
giveTool(made)
deleteList() end end
function giveTool(name) local player, char = getPC() local backpack = player.Backpack local tools = game.Lighting.Tools
local made = tools:findFirstChild(name)
if made ~= nil then made:clone().Parent = backpack else alert("Davidii messed up") end end
function createItem() if CHOOSING then return end
local made = nil
for index, child in pairs(ITEM_TABLE) do made = runIngredients(child)
if made ~= nil then break end end
if type(made) == "table" then made = creationChoice(made) end
if made == nil then alert("Nothing created") clearList() else alert(made.." created!")
giveItem(made)
deleteList() end end
function processItem() if CHOOSING then return end
local processMessage = nil local processFunction = nil
for index, child in pairs(PROCESS_TABLE) do processMessage, processFunction = runIngredients(child, true)
if processMessage ~= nil then break end end
if processMessage == nil and processFunction == nil then alert("Nothing happened")
clearList() else alert(processMessage)
processFunction()
clearList() end end
function giveItem(name) local player, char = getPC() local pack = player.Pack local items = game.Lighting.Items
local real = items:findFirstChild(name)
if real ~= nil then local new = real:clone() new.Parent = pack else alert("Davidii messed up") end end
--MOUSE FUNCTIONS function onMouseMove(mouse) if CHOOSING then return end
local targ = mouse.Target
TARGET_LABEL.Text = ""
if canUse(targ) then TARGET_LABEL.Text = targ.Name end end
function onButton1Down(mouse) if CHOOSING then return end
local targ = mouse.Target
if canUse(targ) then if not haveCheck(targ) then selectTarget(targ) else alert("You already have that!") end end end
function selectTarget(part) alert(part.Name.." selected")
table.insert(SELECTED, part)
updateList() end
--SELECTION FUNCTIONS function onSelected(mouse) local player, char = getPC() local pg = player.PlayerGui
SCREEN_GUI.Parent = pg
mouse.Move:connect(function() onMouseMove(mouse) end)
mouse.Button1Down:connect(function() onButton1Down(mouse) end) end
function onDeselected(mouse) SCREEN_GUI.Parent = TOOL
stopCreationChoice() end
--CONNECTIONS TOOL.Selected:connect(onSelected) TOOL.Deselected:connect(onDeselected)
CLEAR_BUTTON.MouseButton1Down:connect(clearSelected) ITEM_BUTTON.MouseButton1Down:connect(createItem) TOOL_BUTTON.MouseButton1Down:connect(createTool) PROCESS_BUTTON.MouseButton1Down:connect(processItem)
|
|
|
| Report Abuse |
|