-- LUA Script - precede every function and global member with lowercase name of script + '_main' g_foraged = g_foraged or {} g_exp = g_exp or 0 local U = require "scriptbank\\utillib" local equipttomake = 1 local equiptnames = { "a Pistol", "a Rifle", "some Pistol Ammo", "some Rifle Ammo"} local splateneeded = { 4, 6, 1, 1 } -- ingredients used to craft each item listed downwards local sulphurneeded = { 0, 0, 1, 1 } local saltpeterneeded = { 0, 0, 1, 1 } local carbonneeded = { 4, 4, 1, 1 } function lathe_init(e) Include( "utillib.lua" ) end local pressed = false function lathe_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 ~ " .. #equiptnames .. " to select the Equiptment to craft" ) TextCenterOnX( 50, 62, 1, "Press E to Craft " .. equiptnames[ equipttomake ] ) --show how much player has in inventory TextCenterOnX( 50, 65, 1, "No of Steel Plating = " .. U.HaveAmount( 'S Plate' ) .. " No of Sulphur = " .. U.HaveAmount( 'Sulphur' ) .. " No of Saltpeter = " .. U.HaveAmount( 'Saltpeter' ) .. " 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 <= #equiptnames then equipttomake = key end --find out if player has enough of each material seperately local havesplate = U.HaveEnough( 'S Plate', splateneeded[ equipttomake ] ) local havesulphur = U.HaveEnough( 'Sulphur', sulphurneeded[ equipttomake ] ) local havesaltpeter = U.HaveEnough( 'Saltpeter', saltpeterneeded[ equipttomake ] ) local havecarbon = U.HaveEnough( 'Carbon', carbonneeded[ equipttomake ] ) --now we will show number in red if player doesn't have enough if havesplate then TextCenterOnX( 50, 68, 1, splateneeded[ equipttomake ] ) else TextCenterOnXColor( 50, 68, 1, splateneeded[ equipttomake ], 255, 0, 0 ) end TextCenterOnX( 50, 71, 1, "Steel Plate required" ) if havesulphur then TextCenterOnX( 50, 74, 1, sulphurneeded[ equipttomake ] ) else TextCenterOnXColor( 50, 74, 1, sulphurneeded[ equipttomake ], 255, 0, 0 ) end TextCenterOnX( 50, 77, 1, "Sulphur required" ) if havesaltpeter then TextCenterOnX( 50, 80, 1, saltpeterneeded[ equipttomake ] ) else TextCenterOnXColor( 50, 80, 1, saltpeterneeded[ equipttomake ], 255, 0, 0 ) end TextCenterOnX( 50, 83, 1, "Saltpeter required" ) if havecarbon then TextCenterOnX( 50, 86, 1, carbonneeded[ equipttomake ] ) else TextCenterOnXColor( 50, 86, 1, carbonneeded[ equipttomake ], 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 havesplate and havesulphur and havesaltpeter and havecarbon then PlaySound( e, 1 ) U.ChangeAmount( 'S Plate', -splateneeded[ equipttomake ] ) U.ChangeAmount( 'Sulphur', -sulphurneeded[ equipttomake ] ) U.ChangeAmount( 'Saltpeter', -saltpeterneeded[ equipttomake ] ) U.ChangeAmount( 'Carbon', -carbonneeded[ equipttomake ] ) local equiptName = equiptnames[ equipttomake ] PromptDuration( "You have Crafted " .. equiptName, 2000 ) if equiptName == "a Pistol" then U.ChangeAmount( 'Pistols', 1 ) g_exp = g_exp + 300 elseif equiptName == "a Rifle" then U.ChangeAmount( 'Rifles', 1 ) g_exp = g_exp + 400 elseif equiptName == "some Pistol Ammo" then U.ChangeAmount( 'Pistol Ammo', 1 ) g_exp = g_exp + 200 elseif equiptName == "some Rifle Ammo" then U.ChangeAmount( 'Rifle Ammo', 1 ) g_exp = g_exp + 200 end else PromptDuration("You do not have enough Items to craft " .. equiptnames[equipttomake], 2000) end end else pressed = false end end end