-- 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 = { "Planks", "Logs", "Nails", "Steel Plate", "Water Flask"} local woodneeded = { 4, 6, 0, 0, 1 } -- ingredience 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 } local maxbench = 5 function workbench_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 amount == 0 then return true elseif foraged[name] ~= nil then return foraged[name].amount >= amount else return false end end function workbench_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 ~ " .. maxbench .. " to select the Equiptment to craft" ) TextCenterOnX( 50, 62, 1, "Press E to Craft a " .. benchnames[benchtomake] ) --show how much player has in inventory TextCenterOnX( 50, 65, 1, "No of Wood = " .. haveAmount( foraged, 'Wood' ) .. " No of Iron Ingots = " .. haveAmount( foraged, 'iIngot' ) .. " No of Steel plating = " .. haveAmount( foraged, 'sIngot' ) .. " No of Carbon = " .. haveAmount( foraged, 'Carbon' ) .. " No of Hides = " .. haveAmount( foraged, 'Hides' ) ) --check player presses a number key and it corresponds to our items above if g_Scancode > 1 and g_Scancode <= maxbench+1 then -- +1 because scancodes start at 2 for number 1 benchtomake = g_Scancode-1 end --find out if player has enough of each material seperately local havewood = enough( foraged, 'Wood', woodneeded[benchtomake] ) local haveiingot = enough( foraged, 'iIngot', iingotneeded[benchtomake] ) local havesingot = enough( foraged, 'sIngot', singotneeded[benchtomake] ) local havecarbon = enough( foraged, 'Carbon', carbonneeded[benchtomake] ) local havehide = enough( foraged, '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 local function changeAmount( name, by ) if foraged[name] == nil then foraged[name] = {amount = by} else foraged[name].amount = foraged[name].amount + by end end PlaySound(e, 1) changeAmount( 'Wood', -woodneeded[benchtomake] ) changeAmount( 'iIngot', -iingotneeded[benchtomake] ) changeAmount( 'sIngot', -singotneeded[benchtomake] ) changeAmount( 'Carbon', -carbonneeded[benchtomake] ) changeAmount( 'Hides', -hideneeded[benchtomake] ) local benchName = benchnames[benchtomake] PromptDuration( "You Crafted a " .. benchName, 2000 ) if benchName == "Nails" then changeAmount( benchName, 10 ) elseif benchName == "Water Flask" then changeAmount( 'Flask', 1 ) elseif benchName == "Steel Plate" then changeAmount( 'S Plate', 1 ) else changeAmount( benchName, 1 ) end else PromptDuration("You do not have enough Items to craft " .. benchnames[benchtomake], 2000) end end else pressed = false end end end