-- 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 benchtomake = 1 local benchnames = { "a Plank", "a Log", "some Nails", "a Steel Plate", "a Water Flask"} local woodneeded = { 4, 6, 0, 0, 1 } -- ingredients used to craft each item listed downwards local iingotneeded = { 0, 0, 0, 4, 0 } local singotneeded = { 0, 0, 1, 0, 0 } local carbonneeded = { 0, 0, 0, 2, 0 } local hideneeded = { 0, 0, 0, 2, 1 } function workbench_init(e) Include( "utillib.lua" ) end local pressed = false function workbench_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 ~ " .. #benchnames .. " to select the Equiptment to craft" ) TextCenterOnX( 50, 62, 1, "Press E to Craft " .. benchnames[benchtomake] ) --show how much player has in inventory TextCenterOnX( 50, 65, 1, "No of Wood = " .. U.HaveAmount( 'Wood' ) .. " No of Iron Ingots = " .. U.HaveAmount( 'iIngot' ) .. " No of Steel plating = " .. U.HaveAmount( 'sIngot' ) .. " No of Carbon = " .. U.HaveAmount( 'Carbon' ) .. " No of Hides = " .. U.HaveAmount( 'Hides' ) ) --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 <= #benchnames then benchtomake = key end --find out if player has enough of each material seperately local havewood = U.HaveEnough( 'Wood', woodneeded[benchtomake] ) local haveiingot = U.HaveEnough( 'iIngot', iingotneeded[benchtomake] ) local havesingot = U.HaveEnough( 'sIngot', singotneeded[benchtomake] ) local havecarbon = U.HaveEnough( 'Carbon', carbonneeded[benchtomake] ) local havehide = U.HaveEnough( 'Hides', hideneeded[benchtomake] ) --now we will show number in red if player doesn't have enough if havewood then TextCenterOnX( 50, 68, 1, woodneeded[benchtomake]) else TextCenterOnXColor( 50, 68, 1, woodneeded[benchtomake], 255,0,0) end TextCenterOnX( 50, 71, 1, "Wood required" ) if haveiingot then TextCenterOnX( 50, 74, 1, iingotneeded[benchtomake] ) else TextCenterOnXColor( 50, 74, 1, iingotneeded[benchtomake], 255,0,0) end TextCenterOnX( 50, 77, 1, "Iron Ingots required" ) if havesingot then TextCenterOnX( 50, 80, 1, singotneeded[benchtomake] ) else TextCenterOnXColor( 50, 80, 1, singotneeded[benchtomake], 255,0,0) end TextCenterOnX( 50, 83, 1, "Steel Ingots required" ) if havecarbon then TextCenterOnX( 50, 86, 1, carbonneeded[benchtomake] ) else TextCenterOnXColor( 50, 86, 1, carbonneeded[benchtomake], 255,0,0) end TextCenterOnX( 50, 89, 1, "Carbon required" ) if havehide then TextCenterOnX( 50, 92, 1, hideneeded[benchtomake] ) else TextCenterOnXColor( 50, 92, 1, hideneeded[benchtomake], 255,0,0) end TextCenterOnX( 50, 95, 1, "Hide required" ) --if player presses E to craft if g_KeyPressE == 1 then if not pressed then pressed = true --not enough materials if havewood and haveiingot and havesingot and havecarbon and havehide then PlaySound(e, 1) U.ChangeAmount( 'Wood', -woodneeded[benchtomake] ) U.ChangeAmount( 'iIngot', -iingotneeded[benchtomake] ) U.ChangeAmount( 'sIngot', -singotneeded[benchtomake] ) U.ChangeAmount( 'Carbon', -carbonneeded[benchtomake] ) U.ChangeAmount( 'Hides', -hideneeded[benchtomake] ) local benchName = benchnames[benchtomake] if benchName == "some Nails" then U.ChangeAmount( 'Nails', 10 ) elseif benchName == "a Water Flask" then U.ChangeAmount( 'Flask', 1 ) elseif benchName == "a Steel Plate" then U.ChangeAmount( 'S Plate', 1 ) elseif benchName == "a Log" then U.ChangeAmount( 'Logs', 1 ) elseif benchname == "a Plank" then U.ChangeAmount( 'Planks', 1 ) end PromptDuration( "You Crafted " .. benchName, 2000 ) else PromptDuration("You do not have enough Items to craft " .. benchnames[benchtomake], 2000) end end else pressed = false end end end