username2764 Posted March 7, 2022 Share Posted March 7, 2022 Does anyone know how to make a mod which spawns a item on a tile? I can make mods which spawn items in containers but can't spawn any items on the ground. Any advice would be appreciated. Link to comment Share on other sites More sharing options...
ProjectSky Posted March 7, 2022 Share Posted March 7, 2022 AddWorldInventoryItem Link to comment Share on other sites More sharing options...
username2764 Posted March 7, 2022 Author Share Posted March 7, 2022 Thank you for your advice.I wrote a few lines of code but they didn't work at all.Could you tell me what the problem is? local function spawnSpoon(square) square:AddWorldInventoryItem("Base.Spoon", 171, 204, 0); end Events.OnNewGame.Add(spawnSpoon) Link to comment Share on other sites More sharing options...
ProjectSky Posted March 8, 2022 Share Posted March 8, 2022 (edited) local function SpawnInventoryItem(sq) local x, y, z = sq:getX(), sq:getY(), sq:getZ() if x == 6142 and y == 5399 and z == 0 then sq:AddWorldInventoryItem("Base.Axe", 0, 0, 0) Events.LoadGridsquare.Remove(SpawnInventoryItem) --once end end Events.LoadGridsquare.Add(SpawnInventoryItem) Edited March 8, 2022 by ProjectSky Link to comment Share on other sites More sharing options...
username2764 Posted March 8, 2022 Author Share Posted March 8, 2022 It works!I appreciate your help.Thank you Link to comment Share on other sites More sharing options...
username2764 Posted March 8, 2022 Author Share Posted March 8, 2022 The code seems to spawn an axe every time the map is loaded.As you might suspect,I don't want too many axes.I can manually disable a mod to prevent spawning axes but it's not a sophisticated method.You've already helped me a lot but please let me know if you have any good ideas. Link to comment Share on other sites More sharing options...
username2764 Posted March 9, 2022 Author Share Posted March 9, 2022 I edited the code and the problem has been solved.Thank you! Link to comment Share on other sites More sharing options...
Hugo Qwerty Posted March 9, 2022 Share Posted March 9, 2022 FWIW: that code will be running potentially thousands of if statement until the right square is loaded. You could do something like: local sq = getCell():getGridSquare(6142, 5399, 0) if (sq ~= nil) then sq:AddWorldInventoryItem("Base.Axe", 0, 0, 0) end sq will be nil if isn't currently loaded, e.g. if it's not near the player. The code will need to be put in an event of some sort, e.g. EveryHours. Link to comment Share on other sites More sharing options...
username2764 Posted March 10, 2022 Author Share Posted March 10, 2022 Wow!You must be a professional programmer,mustn't you?Thank you for your advice.I'll definitely try it. Link to comment Share on other sites More sharing options...
Signoftheraven Posted December 9, 2023 Share Posted December 9, 2023 (edited) On 3/7/2022 at 11:24 PM, ProjectSky said: local function SpawnInventoryItem(sq) local x, y, z = sq:getX(), sq:getY(), sq:getZ() if x == 6142 and y == 5399 and z == 0 then sq:AddWorldInventoryItem("Base.Axe", 0, 0, 0) Events.LoadGridsquare.Remove(SpawnInventoryItem) --once end end Events.LoadGridsquare.Add(SpawnInventoryItem) Hello ProjectSky. Your code works really well. I'm able to add my custom items into the world where I need them to be. Is it possible to only have this done once? I don't want the items to spawn every time I load up the game, until there is 1000 items. Username2764 mentioned that they fixed this issue, but didn't say how they did it. I'm new to coding, and I have no idea how to add a flag or whatever, that will make the item only spawn one time. Any help would be appreciated. Edit* I've gotten my answer already. Thanks again, ProjectSky. Edited January 8 by Signoftheraven Question answered 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