-- 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 = { "an Iron Ingot", "a Copper Ingot", "a Lead Ingot", "a Steel Ingot"} ironneeded = { 2, 0, 0, 0 } copperneeded = { 0, 2, 0, 0 } leadneeded = { 0, 0, 2, 2 } carbonneeded = { 0, 0, 0, 2 } function furnace_init(e) Include( "utillib.lua" ) end local pressed = false function furnace_main(e) --check player is near the funace if U.PlayerLookingNear( e, 100, 110 ) then U.SetList( g_foraged ) --show shop text TextCenterOnX( 50, 59, 1, "Press 1 ~ " .. #orenames .. " to select the Ingot to craft" ) TextCenterOnX( 50, 62, 1, "Press E to Craft " .. orenames[oretomake] ) --show how much player has in inventory TextCenterOnX( 50, 65, 1, "No of Iron Ore = " .. U.HaveAmount( 'Iron' ) .. " No of Copper Ore = " .. U.HaveAmount( 'Copper' ) .. " No of Lead Ore = " .. U.HaveAmount( 'Lead' ) .. " No of Carbon = " .. U.HaveAmount( 'Carbon' ) ) --check player presses a number key and it corresponds to our items above local key = g_Scancode - 1 -- scancode for key '1' is 2 -- handle number pad, note this probably doesn't work on all keyboards if key > 77 then key = key - 77 elseif key > 73 then key = key - 73 + 4 elseif key > 69 then key = key - 69 + 7 end if key > 0 and key <= #orenames then oretomake = key end --find out if player has enough of each material seperately local haveiron = U.HaveEnough( 'Iron', ironneeded[oretomake] ) local havecopper = U.HaveEnough( 'Copper', copperneeded[oretomake] ) local havelead = U.HaveEnough( 'Lead', leadneeded[oretomake] ) local havecarbon = U.HaveEnough( '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 PlaySound( e, 1) U.ChangeAmount( 'Iron', -ironneeded[oretomake] ) U.ChangeAmount( 'Copper', -copperneeded[oretomake] ) U.ChangeAmount( 'Lead', -leadneeded[oretomake] ) U.ChangeAmount( 'Carbon', -carbonneeded[oretomake] ) local oreName = orenames[oretomake] PromptDuration( "You have Crafted " .. oreName, 2000 ) if oreName == "Iron Ingot" then U.ChangeAmount( 'iIngot', 1 ) U.ChangeAmount( 'Carbon', 1 ) elseif oreName == "Copper Ingot" then U.ChangeAmount( 'cIngot', 1 ) U.ChangeAmount( 'Carbon', 1 ) elseif oreName == "Lead Ingot" then U.ChangeAmount( 'lIngot', 1 ) U.ChangeAmount( 'Carbon', 1 ) elseif oreName == "Steel Ingot" then U.ChangeAmount( 'sIngot', 1 ) end else PromptDuration("You do not have enough Ore to craft " .. orenames[oretomake], 2000) end end else pressed = false end end end