-- 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 if g_woodcollected == nil then g_woodcollected=0 end if g_flintcollected == nil then g_flintcollected=0 end if g_fiberscollected == nil then g_fiberscollected=0 end -- added the other material items here if needed --don't change local itemtomake = 1 itemname = {} flintneeded = {} woodneeded = {} fiberneeded = {} --add other materials here too local haveflint = 0 local havewood = 0 local havefibers = 0 --item names for showing in shop menu itemname[1] = "Dagger" itemname[2] = "Axe" --itemname[3] = "Long Sword" --etc --list out each item requirements here flintneeded[1] = 5 woodneeded[1] = 2 fiberneeded[1] = 1 flintneeded[2] = 10 woodneeded[2] = 4 fiberneeded[2] = 2 --metalneeded[3] = 20 --woodneeded[3] = 8 --fiberneeded[3] = 4 --etc --number of items in your list (above) local maxitems = 2 function workbench_tool_crafting_init(e) end function workbench_tool_crafting_main(e) --check player is near shop if GetPlayerDistance(e) < 80 then --check player presses a number key and it corresponds to our items above if g_Scancode > 1 and g_Scancode <= maxitems+1 then -- +1 to maxitems because scancodes start at 2 for number 1 itemtomake = g_Scancode-1 end --show shop text TextCenterOnX(50,59,1,"Press 1 ~ "..maxitems.." to select an item to craft") TextCenterOnX(50,62,1,"Press E to Craft a "..itemname[itemtomake]) --show how much player has in inventory TextCenterOnX(50,65,1,"No of Wood Items = " .. g_woodcollected .. " No of Flint shards = " .. g_flintcollected .. " No of Fibers = " .. g_fiberscollected) --find out if player has enough of each material seperately if g_flintcollected >= flintneeded[itemtomake] then haveflint = 1 else haveflint = 0 end if g_woodcollected >= woodneeded[itemtomake] then havewood = 1 else havewood = 0 end if g_fiberscollected >= fiberneeded[itemtomake] then havefiber = 1 else havefiber = 0 end --now we will show number in red if player doesn't have enough if haveflint == 1 then TextCenterOnX(50,68,1,flintneeded[itemtomake]) else TextCenterOnXColor(50,68,1,flintneeded[itemtomake],255,0,0) end TextCenterOnX(50,71,1,"Flint required") if havewood == 1 then TextCenterOnX(50,74,1,woodneeded[itemtomake]) else TextCenterOnXColor(50,74,1,woodneeded[itemtomake],255,0,0) end TextCenterOnX(50,77,1,"Wood required") if havefiber == 1 then TextCenterOnX(50,80,1,fiberneeded[itemtomake]) else TextCenterOnXColor(50,80,1,fiberneeded[itemtomake],255,0,0) end TextCenterOnX(50,83,1,"Fibers required") --if player presses E to craft if g_KeyPressE == 1 and pressed == 0 then pressed = 1 --not enough materials if haveflint == 0 and havewood == 0 and havefiber == 0 then PromptDuration("You do not have enough materials to craft a "..itemname[itemtomake],2000) end --crafting is successful if haveflint == 1 and havewood == 1 and havefiber == 1 then PlaySound(e,1) g_flintcollected = g_flintcollected-flintneeded[itemtomake] g_woodcollected = g_woodcollected-woodneeded[itemtomake] g_fiberscollected = g_fiberscollected-fiberneeded[itemtomake] if itemname[itemtomake] == itemname[1] then AddPlayerWeapon(37) -- Change this number to corrispond with the hidden Dagger weapon PromptDuration("You Crafted a "..itemname[itemtomake],2000) elseif itemname[itemtomake] == itemname[2] then AddPlayerWeapon(38) -- Change this number to corrispond with the hidden Axe weapon PromptDuration("You Crafted a "..itemname[itemtomake],2000) end if g_KeyPressE == 0 then pressed = 0 end end end end end