It works really well in a cemeteryDrakkan wrote:advanced digging, impressive. thanks a lotninjanerdbgm wrote:Hey Drakkan, I modified the dig random script a bit for use in my own mod. Here's the code I ended up going with:
By adding the target (c) to the function, the script no longer needs to be on top of the floor_trigger, and
multiple floor_triggers can point to the same function.
Code: Select all
items = {"baked_maggot","boiled_beetle","blooddrop_cap","falconskyre","mudwort","skull","potion_energy","potion_cure_poison","potion_cure_disease","potion_greater_energy","potion_greater_healing","potion_healing","potion_shield","potion_resurrection","bread","cheese","borra","mole_jerky","warg_meat"} -- Give the player a small chance to dig up more than one item, or no item at all -- itemchance = {"0","1","1","1","1","1","1","1","1","1","1","1","1","1","2","2","2","2","3"} function digRandomStuff(c) local itemamt = itemchance[math.random(1,#items)] if itemamt == "0" then hudPrint("You found nothing...") end for i=1,itemamt do local item = math.random(1,#items) item = items[item] local j = c.go:spawn(item) playSound("secret") -- You can add the code to add text to notes/letter or whatever other component necessity here -- hudPrint("You found "..getArticle(j.item:getUiName())..j.item:getUiName().."!") end -- You can add code to give xp here -- end --[[ I got really sick of seeing "You got a Energy Potion!" or "You got a Cheese!", so I decided to generate the articles. The following code finds out what item was dug up and returns the proper article, or no article at all. --]] function getArticle(name) local fletter = name:sub(1,1) -- Get the first letter of the item's UI name fletter = string.byte(fletter,1) -- Convert it to ASCII if fletter < 97 then fletter = fletter + 32 end -- Convert it to lowercase. if string.char(fletter) == "a" or string.char(fletter) == "e" or string.char(fletter) == "i" or string.char(fletter) == "o" or string.char(fletter) == "u" then return "an " elseif name:sub(1,3) == "Fal" or name:sub(1,3) == "Mud" or name:sub(1,3) == "Bre" or name:sub(1,3) == "Che" or name:sub(1,3) == "Bor" or name:sub(1,3) == "Mol" or name:sub(1,3) == "War" then return "" else return "a " end end
