-- LUA Script - precede every function and global member with lowercase name of script + '_main' g_splate = g_splate or 0 g_sulphurcollected = g_sulphurcollected or 0 g_saltpetercollected = g_saltpetercollected or 0 g_carboncollected = g_carboncollected or 0 -- added the other material items here if needed local equipttomake = 1 local equiptnames = { "Pistol", "Rifle", "Pistol Ammo", "Rifle Ammo"} local splateneeded = { 4, 6, 1, 1 } -- ingredience 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 } local maxequipt = 4 function lathe_init(e) end local pressed = false function lathe_main(e) --check player is near the funace if GetPlayerDistance(e) < 80 then --show shop text TextCenterOnX( 50, 59, 1, "Press 1 ~ " .. maxequipt .. " to select the Equiptment to craft" ) TextCenterOnX( 50, 62, 1, "Press E to Craft a " .. equiptnames[equipttomake] ) --show how much player has in inventory TextCenterOnX( 50, 65, 1, "No of Steel Plating = " .. g_splate .. " No of Sulphur = " .. g_sulphurcollected .. " No of Saltpeter = " .. g_saltpetercollected .. " 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 <= maxequipt+1 then -- +1 to maxore because scancodes start at 2 for number 1 equipttomake = g_Scancode-1 end --find out if player has enough of each material seperately local havesplate = g_splate >= splateneeded[equipttomake] local havesulphur = g_sulphurcollected >= sulphurneeded[equipttomake] local havesaltpeter = g_saltpetercollected >= saltpeterneeded[equipttomake] local havecarbon = g_carboncollected >= 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) g_splate = g_splate - splateneeded[equipttomake] g_sulphurcollected = g_sulphurcollected - sulphurneeded[equipttomake] g_saltpetercollected = g_saltpetercollected - saltpeterneeded[equipttomake] g_carboncollected = g_carboncollected - carbonneeded[equipttomake] local equiptName = equiptnames[equipttomake] PromptDuration( "You Crafted a " .. equiptName, 2000 ) if equiptName == "Pistol" then g_pistol = g_pistol + 1 elseif equiptName == "Rifle" then g_rifle = g_rifle + 1 elseif equiptName == "Pistol Ammo" then g_pistol_ammo = g_pistol_ammo + 1 elseif equiptName == "Rifle Ammo" then g_rifle_ammo = g_rifle_ammo + 1 end else PromptDuration("You do not have enough Items to craft " .. equiptnames[equipttomake], 2000) end end else pressed = false end end end