Jatta Pake Posted August 27, 2014 Share Posted August 27, 2014 I've spent eight hours this weekend reading through the forums and trying to reason through the lua that would allow my mod to spawn a random item as part of a recipe. I think the problem could be a limitation of the OnCreate: Additem code but I'm just not sure. Or I could be really close and just off with my code a tiny bit. Here is what I have so far. recipe.txtmodule MIBrecipe /* ========= Unwrap Gift Box ========= */ {imports{Base} recipe Unwrap Gift Box{Spiffo, Result:Rubbish,Time:50.0,OnCreate:AddVariant_OnCreate,}} AddVariant.luafunction AddVariant_OnCreate(items, result, player) local SpiffoNumber = ZombRand(3) +1; if SpiffoNumber = 1 then player:getInventory():AddItem("ListSpiffo.RubySpiffo");elseif SpiffoNumber = 2 thenplayer:getInventory():AddItem("ListSpiffo.SapphireSpiffo");elseif SpiffoNumber = 3 thenplayer:getInventory():AddItem("ListSpiffo.JetSpiffo");end end Link to comment Share on other sites More sharing options...
Jatta Pake Posted August 31, 2014 Author Share Posted August 31, 2014 In the above example, ListSpiffo is the item module listing all of my Spiffo variants. I only show three in the above code but the final code will have over a hundred. Link to comment Share on other sites More sharing options...
kerbholz Posted September 2, 2014 Share Posted September 2, 2014 (edited) Shouldn't it beif SpiffoNumber == 1 then...?? Double signs? Single equal sign assigns a value, use double equal signs in if loops. Also, print() your random number to see its value. Edit:Here's a little function that will spawn 5 Spiffos and print a random number to the console:local function AddSpiffo(_keyPressed) local key = _keyPressed; local numberOfItems = 5; if tostring(key) == tostring(Keyboard.KEY_M) then local player = getSpecificPlayer(0); local inventory = player:getInventory(); for loopCount = 1, numberOfItems do local SpiffoNumber = ZombRand(3) +1; print("*** Spiffo" .. SpiffoNumber); inventory:AddItem("Base.Spiffo"); end endend-- AnyKeyPressEvents.OnKeyPressed.Add(AddSpiffo);Press M ingame to spawn the Spiffos. Edited September 2, 2014 by kerbholz Jatta Pake 1 Link to comment Share on other sites More sharing options...
Jatta Pake Posted September 3, 2014 Author Share Posted September 3, 2014 Just to follow up on kerbholz answer, yes indeed I needed == instead of = for the if statements. Breakthrough!!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now