Hi G sry for the double post I'm kind of stuck on adding a 4th item to a survival cooking stove thingy script, its pretty much the same as the item crafting script just adapted for cooking. The issue i have is when adapted for the 4th item to be crafted gives the error "attempt to comapare nil with a number" at line 95. For the life of me i cannot see why :/. Ive tried numerous things to get it to work with no joy
Also this script is to make non real items to use later e.g pies and soups to give health.
Any chance you could look throough it please m8 and see if you can spot why
also any pointers as to how i can then use them from the inventory script to add health
Cheers m8
The Inventory Script so far:
-
- LUA Script - precede every function and global member with lowercase name of script + '_main'
displaymode=0
delay=0
g_berriescollected=0
g_grasscollected=0
g_woodcollected=0
g_flintcollected=0
g_featherscollected=0
g_fiberscollected=0
g_tuberscollected=0
g_rootscollected=0
g_watercollected=0
g_crafted_items=0
g_berry_pie=0
g_berry_soup=0
g_mushroom_pie=0
g_mushroom_soup=0
g_fdagger=0
g_faxe=0
g_fhammer=0
g_ibow=0
g_arrow=0
g_meatcollected=0
g_hidecollected=0
g_meat_pie=0
g_meat_soup=0
g_camp_fire=0
g_shelter=0
g_workbench=0
g_cooker=0
-- higher grade mats
g_ironcollected=0
g_coppercollected=0
g_tungstencollected=0
g_titanitecollected=0
function survival_inventory_init(e)
--Hide(e)
end
function survival_inventory_main(e)
if GetTimer(e)>250 then
delay=0
end
if GetInKey()=="i" then
--if g_KeyPress==1 then
StartTimer(e)
if displaymode==0 and delay==0 then
displaymode=1
delay=1
end
if displaymode==1 and delay==0 then
displaymode=0
delay=1
end
end
if displaymode==1 then
Panel(0,0,100,88)--background
Panel(37,0,61,10)--Top
Panel(1,13,17,68)-- left
Panel(81,13,99,68)-- right
Panel(18,13,38,68)-- Center left
Panel(39,13,59,68)-- Center center
Panel(60,13,80,68)-- Center right
TextColor(38,3,1,"Suvival Collecting & Crafting Menu",10,255,10)
Text(40,7,1,"Press (i) to toggle on and off ")
--collected Items
TextColor(2,17,1,"Items Collected level 1",10,255,10)
--Text(2,15,1,"Fletching items: ")
Text(5,25,1,"Berries "..math.floor(g_berriescollected))
Text(5,28,1,"Grasses "..math.floor(g_grasscollected))
Text(5,31,1,"Water "..math.floor(g_watercollected))
Text(5,34,1,"Fibers "..math.floor(g_fiberscollected))
Text(5,37,1,"Tubers "..math.floor(g_tuberscollected))
Text(5,40,1,"Wood "..math.floor(g_woodcollected))
Text(5,43,1,"Flint "..math.floor(g_flintcollected))
Text(5,46,1,"Meat "..math.floor(g_meatcollected))
Text(5,49,1,"Hides "..math.floor(g_hidecollected))
--Crafting lvl 1
TextColor(23,17,1,"Crafting Level 1",10,255,10)
--Text(28,17,1,"Merchant: ")
Text(23,25,1,"Berry Pie "..math.floor(g_berry_pie))
Text(23,28,1,"Berry Soup "..math.floor(g_berry_soup))
Text(23,31,1,"Mushroom Pie "..math.floor(g_mushroom_pie))
Text(23,34,1,"Mushroom Soup "..math.floor(g_mushroom_soup))
Text(23,37,1,"Meat Pie "..math.floor(g_meat_pie))
Text(23,40,1,"Meat Soup "..math.floor(g_meat_soup))
Text(23,43,1,"Flint Dagger "..g_fdagger)
Text(23,46,1,"Flint Axe "..math.floor(g_faxe))
Text(23,49,1,"Flint Hammer "..math.floor(g_fhammer))
Text(23,52,1,"Camp Fire "..math.floor(g_camp_fire))
Text(23,55,1,"Shelter "..math.floor(g_shelter))
Text(23,58,1,"Workbench "..math.floor(g_workbench))
Text(23,61,1,"Cooking Stove "..math.floor(g_cooker))
--crafting lvl 2
TextColor(43,17,1,"Items Collected level 2",10,255,10)
--Text(60,17,1,"Rogue: ")
Text(43,25,1,"Iron "..math.floor(g_ironcollected))
Text(43,28,1,"Copper "..math.floor(g_coppercollected))
Text(43,31,1,"Tungsten "..math.floor(g_tungstencollected))
Text(43,34,1,"Titanite "..math.floor(g_titanitecollected))
--Text(43,45,1,"Shelter "..math.floor(g_shelter))
--Text(43,50,1,"Workbench "..math.floor(g_workbench))
--crafting lvl 3
TextColor(65,17,1,"Crafting Level 3:",10,255,10)
--Text(86,15,1,"Weapon Smithing: ")
Text(86,18,1,"Iron Bow "..math.floor(g_ibow))
Text(86,21,1,"Arrows "..math.floor(g_arrow))
--Text(86,24,1,"Fibers "..math.floor(g_fiberscollected))
end
end
and the food crafting script: (adapted from the one you did for me for food) p.s i get the same error adding new ingredience to both scripts.
-- 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_berry_soup = 0 -- added these to see if they would add to the inventory
--g_berry_pie = 0
--g_meatcollected = 0
--g_meat_pie = 0
if g_berriescollected == nil then
g_berriescollected=0
end
if g_tuberscollected == nil then
g_tuberscollected=0
end
if g_watercollected == nil then
g_watercollected=0
end
if g_meatcollected == nil then
g_meatcollected=0
end
-- added the other material items here if needed
--don't change
local foodtomake = 1
foodname = {}
tubersneeded = {}
berriesneeded = {}
waterneeded = {}
meatneeded = {}
--add other materials here too
local havetubers = 0
local haveberries = 0
local havewater = 0
local havemeat = 0
--Food names for showing in shop menu
foodname[1] = "Berry Pie"
foodname[2] = "Berry soup"
foodname[3] = "Meat Pie"
--etc
--list out each item requirements here
tubersneeded[1] = 2
berriesneeded[1] = 2
waterneeded[1] = 2
tubersneeded[2] = 2
berriesneeded[2] = 2
waterneeded[2] = 2
tubersneeded[3] = 2
meatneeded[3] = 2
waterneeded[3] = 2
--etc
--number of items in your list (above)
local maxfood = 3
function cooking_tool_crafting_init(e)
end
function cooking_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 <= maxfood+1 then -- +1 to maxfood because scancodes start at 2 for number 1
foodtomake = g_Scancode-1
end
--show shop text
TextCenterOnX(50,59,1,"Press 1 ~ "..maxfood.." to select the food to craft")
TextCenterOnX(50,62,1,"Press E to Craft a "..foodname[foodtomake])
--show how much player has in inventory
TextCenterOnX(50,65,1,"No of Berries = " .. g_berriescollected .. " No of Tubers = " .. g_tuberscollected .. " No of Water = " .. g_watercollected .. " No of Meat = " .. g_meatcollected)
--find out if player has enough of each material seperately
if g_tuberscollected >= tubersneeded[foodtomake] then
havetubers = 1
else
havetubers = 0
end
if g_berriescollected >= berriesneeded[foodtomake] then
haveberries = 1
else
haveberries = 0
end
if g_watercollected >= waterneeded[foodtomake] then
havewater = 1
else
havewater = 0
end
if g_meatcollected >= meatneeded[foodtomake] then
havemeat = 1
else
havemeat = 0
end
--now we will show number in red if player doesn't have enough
if havetubers == 1 then
TextCenterOnX(50,68,1,tubersneeded[foodtomake])
else
TextCenterOnXColor(50,68,1,tubersneeded[foodtomake],255,0,0)
end
TextCenterOnX(50,71,1,"Tubers required")
if haveberries == 1 then
TextCenterOnX(50,74,1,berriesneeded[foodtomake])
else
TextCenterOnXColor(50,74,1,berriesneeded[foodtomake],255,0,0)
end
TextCenterOnX(50,77,1,"Berries required")
if havewater == 1 then
TextCenterOnX(50,80,1,waterneeded[foodtomake])
else
TextCenterOnXColor(50,80,1,waterneeded[foodtomake],255,0,0)
end
TextCenterOnX(50,83,1,"Water required")
if havemeat == 1 then
TextCenterOnX(50,80,1,meatneeded[foodtomake])
else
TextCenterOnXColor(50,86,1,meatneeded[foodtomake],255,0,0)
end
TextCenterOnX(50,89,1,"Meat required")
--if player presses E to craft
if g_KeyPressE == 1 and pressed == 0 then
pressed = 1
--not enough materials
if havetubers == 0 and haveberries == 0 and havewater == 0 then
PromptDuration("You do not have enough materials to craft a "..foodname[foodtomake],2000)
end
--crafting is successful
if havetubers == 1 and haveberries == 1 and havewater == 1 and havemeat == 1 then
PlaySound(e,1)
g_tuberscollected = g_tuberscollected-tubersneeded[foodtomake]
g_berriescollected = g_berriescollected-berriesneeded[foodtomake]
g_watercollected = g_watercollected-waterneeded[foodtomake]
g_meatcollected = g_meatcollected-meatneeded[foodtomake]
if foodname[foodtomake] == foodname[1] then
g_berry_pie = g_berry_pie + 1
PromptDuration("You Crafted a "..foodname[foodtomake],2000)
elseif foodname[foodtomake] == foodname[2] then
g_berry_soup = g_berry_soup + 1
PromptDuration("You Crafted a "..foodname[foodtomake],2000)
elseif foodname[foodtomake] == foodname[3] then
g_meat_pie = g_meat_pie + 1
PromptDuration("You Crafted a "..foodname[foodtomake],2000)
end
if g_KeyPressE == 0 then
pressed = 0
end
end
end
end
end
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
AMD Radeon 7570 1gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel
I only smile because i have absolutely no idea whats going on