-- LUA Script - precede every function and global member with lowercase name of script + '_main' g_foraged = g_foraged or {} local U = require "scriptbank\\utillib" local oretomake = 1 orenames = { "Iron Ingot", "Copper Ingot", "Lead Ingot", "Steel Ingot"} ironneeded = { 2, 0, 0, 0 } copperneeded = { 0, 2, 0, 0 } leadneeded = { 0, 0, 2, 2 } carbonneeded = { 0, 0, 0, 2 } local maxore = 4 function furnace_init(e) Include( "utillib.lua" ) end local pressed = false local function haveAmount( foraged, name ) if foraged[name] ~= nil then return foraged[name].amount else return 0 end end local function enough( foraged, name, amount ) if foraged[name] ~= nil then return foraged[name].amount >= amount else return false end end function furnace_main(e) --check player is near the funace if U.PlayerLookingNear( e, 100, 110 ) then local foraged = g_foraged --show shop text TextCenterOnX( 50, 59, 1, "Press 1 ~ " .. maxore .. " to select the Ingot to craft" ) TextCenterOnX( 50, 62, 1, "Press E to Craft a " .. orenames[oretomake] ) --show how much player has in inventory TextCenterOnX( 50, 65, 1, "No of Iron Ore = " .. haveAmount( foraged, 'Iron' ) .. " No of Copper Ore = " .. haveAmount( foraged, 'Copper' ) .. " No of Lead Ore = " .. haveAmount( foraged, 'Lead' ) .. " No of Carbon = " .. haveAmount( foraged, 'Carbon' ) ) --check player presses a number key and it corresponds to our items above if g_Scancode > 1 and g_Scancode <= maxore+1 then -- +1 to maxore because scancodes start at 2 for number 1 oretomake = g_Scancode-1 end --find out if player has enough of each material seperately local haveiron = enough( foraged, 'Iron', ironneeded[oretomake] ) local havecopper = enough( foraged, 'Copper', copperneeded[oretomake] ) local havelead = enough( foraged, 'Lead', leadneeded[oretomake] ) local havecarbon = enough( foraged, 'Carbon', carbonneeded[oretomake] ) --now we will show number in red if player doesn't have enough if haveiron then TextCenterOnX(50,68,1,ironneeded[oretomake]) else TextCenterOnXColor(50,68,1,ironneeded[oretomake],255,0,0) end TextCenterOnX(50,71,1,"Iron Ore required") if havecopper then TextCenterOnX(50,74,1,copperneeded[oretomake]) else TextCenterOnXColor(50,74,1,copperneeded[oretomake],255,0,0) end TextCenterOnX(50,77,1,"Copper Ore required") if havelead then TextCenterOnX(50,80,1,leadneeded[oretomake]) else TextCenterOnXColor(50,80,1,leadneeded[oretomake],255,0,0) end TextCenterOnX(50,83,1,"Lead Ore required") if havecarbon then TextCenterOnX(50,86,1,carbonneeded[oretomake]) else TextCenterOnXColor(50,86,1,carbonneeded[oretomake],255,0,0) end TextCenterOnX(50,89,1,"Carbon required") --if player presses E to craft if g_KeyPressE == 1 then if not pressed then pressed = true --not enough materials if haveiron and havecopper and havelead and havecarbon then local function changeAmount( name, by ) if foraged[name] == nil then foraged[name] = {amount = 1} else foraged[name].amount = foraged[name].amount + by end end PlaySound(e,1) changeAmount( 'Iron', -ironneeded[oretomake] changeAmount( 'Copper', -copperneeded[oretomake] changeAmount( 'Lead', -leadneeded[oretomake] changeAmount( 'Carbon', -carbonneeded[oretomake] local oreName = orenames[oretomake] PromptDuration( "You Crafted a " .. oreName, 2000 ) if oreName == "Iron Ingot" then changeAmount( 'iIngot', 1 ) changeAmount( 'Carbon', 1 ) elseif oreName == "Copper Ingot" then changeAmount( 'cIngot', 1 ) changeAmount( 'Carbon', 1 ) elseif oreName == "Lead Ingot" then changeAmount( 'lIngot', 1 ) changeAmount( 'Carbon', 1 ) elseif oreName == "Steel Ingot" then changeAmount( 'sIngot', 1 ) end else PromptDuration("You do not have enough Ore to craft an " .. orenames[oretomake], 2000) end end else pressed = false end end end