-- LUA Script - precede every function and global member with lowercase name of script + '_main' -- check these are nil first so we can carry over from over levels or saves etc if needs be g_woodcollected = g_woodcollected or 0 g_iingot = g_iingot or 0 g_singot = g_singot or 0 g_carboncollected = g_carboncollected or 0 -- added the other material items here if needed local benchtomake = 1 local benchnames = { "Planks", "Logs", "Nails", "Steel Plate"} local woodneeded = { 4, 6, 0, 0 } -- ingredience used to craft each item listed downwards local iingotneeded = { 0, 0, 0, 4 } local singotneeded = { 0, 0, 1, 0 } local carbonneeded = { 0, 0, 0, 2 } local maxbench = 4 function workbench_init(e) end local pressed = false function workbench_main(e) --check player is near the funace if GetPlayerDistance(e) < 80 then --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 = " .. g_woodcollected .. " No of Iron Ingots = " .. g_iingot .. " No of Steel plating = " .. g_singot .. " No of Carbon = " .. g_carboncollected) --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 = g_woodcollected >= woodneeded[benchtomake] local haveiingot = g_iingot >= iingotneeded[benchtomake] local havesingot = g_singot >= singotneeded[benchtomake] local havecarbon = g_carboncollected >= carbonneeded[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 Plate 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 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 then PlaySound(e,1) g_woodcollected = g_woodcollected - woodneeded[benchtomake] g_iingot = g_iingot - iingotneeded[benchtomake] g_singot = g_singot - singotneeded[benchtomake] g_carboncollected = g_carboncollected - carbonneeded[benchtomake] local benchName = benchnames[benchtomake] PromptDuration( "You Crafted a " .. benchName, 2000 ) if benchName == "Planks" then g_planks = g_planks + 1 elseif benchName == "Logs" then g_logs = g_logs + 1 elseif benchName == "Nails" then g_nails = g_nails + 10 elseif benchName == "Steel Plate" then g_singot = g_singot + 1 end else PromptDuration("You do not have enough Items to craft " .. benchnames[benchtomake], 2000) end end else pressed = false end end end