Give An Item To All Players (Plus Slowing Down Tree Growth)

User avatar
TheReaperKing
Member
 
Posts: 493
Joined: Sun Nov 22, 2015 21:36

Give An Item To All Players (Plus Slowing Down Tree Growth)

by TheReaperKing » Mon Feb 01, 2016 05:27

I have been trying to find a way to give my players an item every day. Quite simply I am trying to have my students create a modern city and they need to deal with their personal waste. The goal is eventually for them to create their own sewer system. Is there a way I can give them the item daily? I didn't see a way to do it with server commands except to manually give it to each one of them and I was looking through the minecraft methods and I didn't see anything that actually adds to their inventory though I am trying to test with set_wielded_item. I am a noob so I probably missed lots.

I'm sure this would be much harder but I'd like it to poison them too if they hold it for too long. I am using the exertion mod which does have poisoning so I might be able to use that (or figure out a way to even just give them the status manually)

Also if anyone knows off hand (I just haven't had a chance to mess with it yet), how do I slow down the growth rate of trees to make it seem more realistic?

Thank you so much!!!! Take care :)
-Mike

EDIT - Just found on Item eat!!! That could work though I am interested in other methods too since generally you do have to wait a bit after eating hehe.

EDIT #2 Not sure how good this code really is, I had trouble with replace_with_item but this seems to work:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_on_item_eat(
   function(hp_change, replace_with_item, itemstack, user, pointed_thing)
   itemstack:replace('mikesmod:waste')
   return itemstack
end
)


Looks like it replaces the ENTIRE stack with one Waste item, whoops. And it seems like it isn't adding any levels to the hunger bar for exertion, I'll check into the mod files there to see if I need to add this there.

Maybe I can add a delay too where it checks to see if that item is still there after a certain period and if it is then the status is changed to poisoned?
Project Lead of the Doom 3 Mod Last Man Standing - http://Doom3Coop.com

Project Lead of Platinum Arts Sandbox Free 3D Game Maker - http://SandboxGameMaker.com

Youtube Channel - https://www.youtube.com/user/PlatinumArtsKids
 

User avatar
maikerumine
Member
 
Posts: 946
Joined: Mon Aug 04, 2014 14:27
GitHub: maikerumine
In-game: maikerumine

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by maikerumine » Mon Feb 01, 2016 13:44

TheReaperKing wrote:I have been trying to find a way to give my players an item every day. Quite simply I am trying to have my students create a modern city and they need to deal with their personal waste. The goal is eventually for them to create their own sewer system. Is there a way I can give them the item daily? I didn't see a way to do it with server commands except to manually give it to each one of them and I was looking through the minecraft methods and I didn't see anything that actually adds to their inventory though I am trying to test with set_wielded_item. I am a noob so I probably missed lots.

I'm sure this would be much harder but I'd like it to poison them too if they hold it for too long. I am using the exertion mod which does have poisoning so I might be able to use that (or figure out a way to even just give them the status manually)

Also if anyone knows off hand (I just haven't had a chance to mess with it yet), how do I slow down the growth rate of trees to make it seem more realistic?

Thank you so much!!!! Take care :)
-Mike

EDIT - Just found on Item eat!!! That could work though I am interested in other methods too since generally you do have to wait a bit after eating hehe.

EDIT #2 Not sure how good this code really is, I had trouble with replace_with_item but this seems to work:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_on_item_eat(
   function(hp_change, replace_with_item, itemstack, user, pointed_thing)
   itemstack:replace('mikesmod:waste')
   return itemstack
end
)


Looks like it replaces the ENTIRE stack with one Waste item, whoops. And it seems like it isn't adding any levels to the hunger bar for exertion, I'll check into the mod files there to see if I need to add this there.

Maybe I can add a delay too where it checks to see if that item is still there after a certain period and if it is then the status is changed to poisoned?


tsm_gift_example.zip
(1.68 KiB) Downloaded 175 times


HI! This might be what you are looking for, it gives a random gift to player when join each time. Depends on treasurer and trm I believe.

Trees... dunno.

Hope this helps!
 

User avatar
everamzah
Member
 
Posts: 490
Joined: Thu Jan 29, 2015 00:47
GitHub: everamzah
IRC: everamzah
In-game: everamzah

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by everamzah » Mon Feb 01, 2016 16:22

To slow down tree growth, you might simply change the sapling ABM interval from 10 to some higher value.
https://github.com/minetest/minetest_ga ... es.lua#L29

Are you asking how to give a player an item one per in-game day, or once per IRL day?
 

User avatar
TheReaperKing
Member
 
Posts: 493
Joined: Sun Nov 22, 2015 21:36

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by TheReaperKing » Wed Feb 03, 2016 02:39

Thanks so much for the heads up on the tree! I changed it to 100 to test it out.

Regarding the item, one per game day would be preferred but if IRL day is easier that is okay too. I haven't had a chance to mess with it yet.

Thanks so much for the insight maikerumine I'll check it out! Also I am planning to use ESMOBs with them too once I can figure out how to make it so that they can't do damage to any of the creatures, which is unfortunately a requirement since there can't be any combat at the school. I've put it off for last since it seems to be the hardest but they are going to go so crazy when I put in NPC versions of themselves. Thanks for making that great mod :)

Take care!
-Mike
Project Lead of the Doom 3 Mod Last Man Standing - http://Doom3Coop.com

Project Lead of Platinum Arts Sandbox Free 3D Game Maker - http://SandboxGameMaker.com

Youtube Channel - https://www.youtube.com/user/PlatinumArtsKids
 

blert2112
Member
 
Posts: 244
Joined: Sat Apr 25, 2015 04:05
GitHub: blert2112

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by blert2112 » Fri Feb 05, 2016 04:23

The following code will give each player an item each day. If two days have passed then the player will get two of the items. Not saying it's perfect but it works for me. You may need to add some error checking. Since you may be dealing with a relatively large group of students that could be logging in all at the same, you may want to use a table to store the data and only write the file when you stop the server. Hope it helps.

edit: This now stores the data in a table and writes it to the file on server shutdown and every five minutes.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- initialize player last login time table
local players = {}

-- build path for data file
local fname = core.get_worldpath().."/dailyitems.txt"

-- function to write data back to file
local write_file = function()
   -- open file for write
   local f = io.open(fname, "w")
   -- convert player table to string
   local data_string = core.serialize(players)
   -- write data string to file
   f:write(data_string)
   -- close file
   io.close(f)
   -- set file variable to nil to avoid memory leak
   f = nil
end

-- check if file exists
local f = io.open(fname, "r")
if f then   -- file exists
   -- read file and store string
   local data_string = f:read("*all")
   -- convert string into table
   players = core.deserialize(data_string)
   io.close(f)
   f = nil
else      -- file does not exist
   write_file()
end

-- when player joins
core.register_on_joinplayer(function(player)
   -- get the player name
   local pname = player:get_player_name()

   --get seconds since epoch
   local t = os.time()

   -- check if player exists in data
   if not players[pname] then
      -- player is not in table, add player and login time to table
      players[pname] = {}
      players[pname].last = t
   end

   -- days since last log in/number of items to give
   -- (time_now - player_last_login_time) / seconds_in_a_day, rounded down
   local num_items = math.floor((t - players[pname].last) / 86400)

   -- give player items
   if num_items >= 1 then
      player:get_inventory():add_item("main", "default:cobble "..num_items)
   end

   -- change player last login time to now in table
   players[pname].last = t
end)

-- write data on server shutdown
core.register_on_shutdown(function()
    write_file()
end)

-- write data to file every five minutes
local timer = 0
core.register_globalstep(function(dtime)
   timer = timer + dtime;
   -- do every five minutes (300 seconds)
   if timer >= 300 then
      write_file()
      timer = 0
   end
end)
Last edited by blert2112 on Mon Feb 08, 2016 21:57, edited 2 times in total.
 

User avatar
TheReaperKing
Member
 
Posts: 493
Joined: Sun Nov 22, 2015 21:36

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by TheReaperKing » Sat Feb 06, 2016 20:07

Wow Blert you really went to town on that! Thank you so much! I am finding it so interesting trying to read and understand your code. I have to say I always considered myself a "non coder" but minetest has really sparked my interest to learn and even though I am horrible at it I figure if I keep trying I'll eventually get better haha. Take care!
-Mike

EDIT - Also what is the license for your code? I am thinking about putting it all together as a "Waste Mod", probably not standalone but in my subgame. I am releasing my subgame to public as well in case other schools or people in general find it interesting and useful.
Project Lead of the Doom 3 Mod Last Man Standing - http://Doom3Coop.com

Project Lead of Platinum Arts Sandbox Free 3D Game Maker - http://SandboxGameMaker.com

Youtube Channel - https://www.youtube.com/user/PlatinumArtsKids
 

blert2112
Member
 
Posts: 244
Joined: Sat Apr 25, 2015 04:05
GitHub: blert2112

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by blert2112 » Sat Feb 06, 2016 21:12

TheReaperKing wrote:Wow Blert you really went to town on that! Thank you so much! I am finding it so interesting trying to read and understand your code. I have to say I always considered myself a "non coder" but minetest has really sparked my interest to learn and even though I am horrible at it I figure if I keep trying I'll eventually get better haha. Take care!
-Mike

EDIT - Also what is the license for your code? I am thinking about putting it all together as a "Waste Mod", probably not standalone but in my subgame. I am releasing my subgame to public as well in case other schools or people in general find it interesting and useful.

You are welcome, t'was nothing. It's just a few basic things put together, and things like this give me an excuse to take a break from my larger projects.
As far as the license... Just like all of my code, do what you want with it. It would be nice to be mentioned in your credits but it's not required.
The write_file function needs checking if it can't open the file to write (it could be already open). I will see if I can work on that tonight.
 

User avatar
TheReaperKing
Member
 
Posts: 493
Joined: Sun Nov 22, 2015 21:36

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by TheReaperKing » Sun Feb 07, 2016 06:35

You are already mentioned in the code comment for your area and will be mentioned in the readme. For my own learning I definitely plan on playing around with it a bit but your original code snippet and the fact that you contributed will definitely be in it no matter what. Thanks again for taking that time, I'm so in awe of how you all can piece together code like this. Hopefully I'll be able to contribute as well someday and this is how it starts! Take care :)
-Mike
Project Lead of the Doom 3 Mod Last Man Standing - http://Doom3Coop.com

Project Lead of Platinum Arts Sandbox Free 3D Game Maker - http://SandboxGameMaker.com

Youtube Channel - https://www.youtube.com/user/PlatinumArtsKids
 

twoelk
Member
 
Posts: 1092
Joined: Fri Apr 19, 2013 16:19

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by twoelk » Sun Feb 07, 2016 09:28

hehe
replace the cobble with an apple
so
an apple a day.....
 

User avatar
TheReaperKing
Member
 
Posts: 493
Joined: Sun Nov 22, 2015 21:36

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by TheReaperKing » Mon Feb 08, 2016 04:36

twoelk I like it, I like it a lot :) I think the idea could even be used on servers to reward players for spending time in there like a tax or time reward whatever.

blert unfortunately I haven't been able get the code to work for me. I did find out as well that it must be on an already created world not a new one because "f:write()" has the error of f being nil. I'll be messing with it more but also I was wondering, is there supposed to be a space in here?
'default:cobble ' or is it 'default:cobble' ?

I did set the time of 300 to 10 for testing purposes and hopefully a mod isn't messing with it somehow though I am using the default gametype to test. Hopefully I'll get more time to test and I feel like it super close so thanks again. Take care!
-Mike
Project Lead of the Doom 3 Mod Last Man Standing - http://Doom3Coop.com

Project Lead of Platinum Arts Sandbox Free 3D Game Maker - http://SandboxGameMaker.com

Youtube Channel - https://www.youtube.com/user/PlatinumArtsKids
 

blert2112
Member
 
Posts: 244
Joined: Sat Apr 25, 2015 04:05
GitHub: blert2112

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by blert2112 » Mon Feb 08, 2016 17:46

Ok, sorry about that. I changed the code so you should not get the 'f is nil' error anymore. It wasn't a problem with a new world, that shouldn't matter to this. It was a problem closing the file.
Yes, that space is supposed to be there. It gets a number concatenated to the string that tells it how many to give.
By changing the 300 to a 10 you are now saving the file every ten seconds. Is that what you were trying to do?

edit: After playing with it for a few there was indeed a problem when creating a new world. Seems it was trying to write the file before the "players" directory was created by Minetest. I changed the directory to just the world folder so it should work now. I also changed a couple of minor things and added better comments to help you read it.
 

User avatar
TheReaperKing
Member
 
Posts: 493
Joined: Sun Nov 22, 2015 21:36

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by TheReaperKing » Tue Feb 09, 2016 02:27

Thank you so much for going out of your way to help me. I'll test it again tonight. I was only putting in the 10 seconds for testing purposes so I didn't have to wait 5 minutes everytime to see if it was working. Thanks again :)
-Mike

Edit - I was wondering, are you using Minetest 0.4.13? I'm still not receiving the item so what I'm doing is I made a wastemod mod folder and I'm pasting your code into my init.lua. I have successfully added the waste item but for some reason your code isn't working and I'm sure I'm missing something simple. It has created the dailyitems.txt but still no cobblestone in my inventory. I will be testing and updating more too tonight. Thanks so much for your patience I bet I am doing something super small incorrectly. Also is there a reason you use "core." vs "minetest." and does it matter? All the tutorials I've seen have it as minetest. so just wondering :)

I have also been putting "minetest.chat_send_all("Timer is working!")" for example in different parts of the code to try to locate where a problem area might be. The timer is indeed working but I put this in the add item part right above it and it does not display a chat message. I changed the seconds in a day bit to 10 aka:
local num_items = math.floor((t - players[pname].last) / 10)

And received 27 cobble stone right away and my chat message. No more cobble since then though yet. I left and came back and was given more cobblestone to 62 so it seems like the items are only given on server join, not throughout time spent on the server. Going to do more testing :)

Is the mix up because I forgot to specify in game day?

I put the additem in your timer loop and added the loop in "core.register_on_joinplayer(function(player)" and it seems to be giving me cobble every 10 seconds (what I have the loop set to). I imagine it is giving me so much because of the math.floor function # I have it set at. SOOO COOOLLL to see it working even though not 100% as intended yet but I'm learning so much from this. Thank you so much again!!!!
Project Lead of the Doom 3 Mod Last Man Standing - http://Doom3Coop.com

Project Lead of Platinum Arts Sandbox Free 3D Game Maker - http://SandboxGameMaker.com

Youtube Channel - https://www.youtube.com/user/PlatinumArtsKids
 

User avatar
TheReaperKing
Member
 
Posts: 493
Joined: Sun Nov 22, 2015 21:36

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by TheReaperKing » Tue Feb 09, 2016 04:30

So don't kill me but using this loop alone is basically all I need for giving players an item every game day or 300 seconds (I assumed that a game day is 5 minutes). I am super interested in your code as well and already learned so much. It might not seem that way but me being able to understand your code enough to modify it to what I was looking for is a huge step for me and my horrible coding ability.

Hopefully no one minds the double post but I made it so that anyone that finds it useful could more easily find it vs my big mess of a previous post.

Also I'd like to understand exactly what your code is doing, it seems that after a full day it is giving a player an item, but only when they first log in? Basically giving the players the backlogged items.

Here is the loop I am using thanks to your hard work:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
core.register_on_joinplayer(function(player)
   
   -- Give item every five minutes
local num_items = 1
local timer = 0
core.register_globalstep(function(dtime)
   timer = timer + dtime;
   -- do every five minutes (300 seconds)
   if timer >= 300 then
   player:get_inventory():add_item("main", "default:cobble "..num_items)
    timer = 0
   end
end)
end)
Project Lead of the Doom 3 Mod Last Man Standing - http://Doom3Coop.com

Project Lead of Platinum Arts Sandbox Free 3D Game Maker - http://SandboxGameMaker.com

Youtube Channel - https://www.youtube.com/user/PlatinumArtsKids
 

blert2112
Member
 
Posts: 244
Joined: Sat Apr 25, 2015 04:05
GitHub: blert2112

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by blert2112 » Tue Feb 09, 2016 05:55

Yeah, oops, sorry. I was thinking every day, not every game day. The code I posted will give the player an item once a day, a normal real life day, when they log in. Once a game day should be even easier but I can't do it tonight, maybe tomorrow.
 

twoelk
Member
 
Posts: 1092
Joined: Fri Apr 19, 2013 16:19

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by twoelk » Tue Feb 09, 2016 07:47

The Currency and economy mod by Dan Duncombe might be of interest here. Especially the "daily income" function suggested by Casimir
 

User avatar
TheReaperKing
Member
 
Posts: 493
Joined: Sun Nov 22, 2015 21:36

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by TheReaperKing » Thu Feb 11, 2016 03:47

Thanks so much twoelk! I think the loop is working pretty well so far though I have two things I'm working on which is to send a message "You don't feel so good.." so that they know they have it to the player vs global which I have now. Also I want to tie it with the "exertion" mod and make it poison them if the item remains in their inventory too long. It's so funny hearing them arguing about who gets to use the outhouse first haha. I really appreciate all the help everyone has given me especially blert2112 for writing all of that code. If people are interested I'd be happy to share my updated code once I get it working :)

I think this should work :) Works for me, time to test with the kiddos:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- A HUGE THANKS TO blert2112 FOR HIS HELP WITH THIS CODE!!!

--Super Abbreviated and simplified - gives a player an item every 10 minutes
core.register_on_joinplayer(function(player)
local pname = player:get_player_name()
   
   -- Give player item every ten minutes
local num_items = 1
local timer = 0
core.register_globalstep(function(dtime)
   timer = timer + dtime;
   -- do every ten minutes (600 seconds)
   if timer >= 600 then
   --minetest.chat_send_all("You don't feel so good.")
   minetest.chat_send_player(pname, "You don't feel so good :(") --tell each individual player it instead of global chat
   player:get_inventory():add_item("main", "wastemod:waste "..num_items)
    timer = 0
   end
end)
end)
Project Lead of the Doom 3 Mod Last Man Standing - http://Doom3Coop.com

Project Lead of Platinum Arts Sandbox Free 3D Game Maker - http://SandboxGameMaker.com

Youtube Channel - https://www.youtube.com/user/PlatinumArtsKids
 

blert2112
Member
 
Posts: 244
Joined: Sat Apr 25, 2015 04:05
GitHub: blert2112

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by blert2112 » Fri Feb 12, 2016 00:33

The code you posted seems to work for me also. The only problem I see is creating a global_step for each player. This may or may not lead to performance issues. Since the function is quite small and fast it may never be a problem.
The following does it with only one global_step. The only issue is that everyone gets their waste at the same time, with your version I believe players will get their waste at different times based on the login time. This code also harms the player (2hp) if he/she has not disposed of the waste before it gets run again.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local harm = 2

local timer = 0
core.register_globalstep(function(dtime)
   timer = timer + dtime;
   if timer >= 10 then
      local players = core.get_connected_players()
      for i = 1,#players do
         local name = players[i]:get_player_name()
         core.chat_send_player(name, "You don't feel so good :(")
         
         local inv = players[i]:get_inventory()
         if inv:contains_item("main", "wastemod:waste") then
            hp = players[i]:get_hp()
            players[i]:set_hp(hp - harm)
         end
         
         players[i]:get_inventory():add_item("main", "wastemod:waste")
      end
      timer = 0
   end
end)
 

User avatar
TheReaperKing
Member
 
Posts: 493
Joined: Sun Nov 22, 2015 21:36

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by TheReaperKing » Sat Feb 13, 2016 03:42

I do actually have an error in my code somewhere. I haven't been able to retrieve the error log from the school computer yet but every once in a while it was crashing the server. I never actually was able to receive the waste so I am wondering if it is related to me. I only remember something about a "nil" value, and I think it is related to the chat message so maybe somehow a nil player value in there sometimes.

I'll test out your code too and see if I get the crash and also compare our code and see what I missed. This has been so fun and such a learning experience, thank you again for all of your help. I hope you've been having fun with it too. We have a three weekend so I'll let you know what happens on Tuesday.

One minor note is that I have damage turned off so that is why I was going to give them the poisoned status which rapidly depletes their health and water. And if their health or water gets too low they are reduced to a crawl which I personally think is way worse than a respawn where they get their life restored. I'm sure I can figure something out especially with the great example you've given me. I'm using the exertion mod.

Take care and thanks again!!
-Mike
Project Lead of the Doom 3 Mod Last Man Standing - http://Doom3Coop.com

Project Lead of Platinum Arts Sandbox Free 3D Game Maker - http://SandboxGameMaker.com

Youtube Channel - https://www.youtube.com/user/PlatinumArtsKids
 

User avatar
TheReaperKing
Member
 
Posts: 493
Joined: Sun Nov 22, 2015 21:36

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by TheReaperKing » Fri Feb 26, 2016 02:56

I haven't had a chance to mess with it much yet because of studying for a test but both my code and your code crash when used with multiple players. Neither crashed on me when it was only me. I'm hoping to try to check it out more over the weekend. I included both of our crashes and I think they might be identical, I still need to compare it. Just FYI I am not ready for the harm stuff yet so I did comment out the harm at the top and this bit:
local inv = players[i]:get_inventory()
if inv:contains_item("main", "wastemod:waste") then
hp = players[i]:get_hp()
players[i]:set_hp(hp - harm)
end


Crash:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
MY CODE CRASH

2016-02-11 14:17:56: ERROR[main]: UNRECOVERABLE error occurred. Stopping server. Please fix the following error:
2016-02-11 14:17:56: ERROR[main]: Runtime error from mod '??' in callback ScriptApiEnv::environment_Step(): ...Jeanne\Desktop\D.s-Sandbox\bin\..\mods\wastemod\init.lua:25: attempt to index a nil value
2016-02-11 14:17:56: ERROR[main]: stack traceback:
2016-02-11 14:17:56: ERROR[main]:    ...Jeanne\Desktop\D.s-Sandbox\bin\..\mods\wastemod\init.lua:25: in function <...Jeanne\Desktop\D.s-Sandbox\bin\..\mods\wastemod\init.lua:19>
2016-02-11 14:17:56: ERROR[main]:    ...nne\Desktop\D.s-Sandbox\bin\..\builtin\game\register.lua:355: in function <...nne\Desktop\D.s-Sandbox\bin\..\builtin\game\register.lua:335>

In thread 16b0:
server.cpp:511: Server::step: A fatal error occurred: Runtime error from mod '??' in callback ScriptApiEnv::environment_Step(): ...Jeanne\Desktop\D.s-Sandbox\bin\..\mods\wastemod\init.lua:25: attempt to index a nil value
stack traceback:
   ...Jeanne\Desktop\D.s-Sandbox\bin\..\mods\wastemod\init.lua:25: in function <...Jeanne\Desktop\D.s-Sandbox\bin\..\mods\wastemod\init.lua:19>
   ...nne\Desktop\D.s-Sandbox\bin\..\builtin\game\register.lua:355: in function <...nne\Desktop\D.s-Sandbox\bin\..\builtin\game\register.lua:335>
Debug stacks:
DEBUG STACK FOR THREAD 14d4:
#0  EmergeThread::Thread
(Leftover data: #1  ServerMap::loadBlock)
(Leftover data: #2  ServerMap::loadBlock)
(Leftover data: #3  ItemStack::deSerialize)
DEBUG STACK FOR THREAD 16b0:
#0  main
#1  Dedicated server branch
#2  dedicated_server_loop
#3  Server::step
DEBUG STACK FOR THREAD 179c:
#0  ServerThread::Thread
#1  Server::Receive
(Leftover data: #2  Server::SendBlocks)
(Leftover data: #3  Server::SendChatMessage)
(Leftover data: #4  ItemStack::serialize)
(Leftover data: #5  getCraftingResult)
(Leftover data: #6  ItemStack::deSerialize)


Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
BLERT CODE CRASH

2016-02-22 14:02:15: ERROR[main]: UNRECOVERABLE error occurred. Stopping server. Please fix the following error:
2016-02-22 14:02:15: ERROR[main]: Runtime error from mod '??' in callback ScriptApiEnv::environment_Step(): ...Jeanne\Desktop\D.s-Sandbox\bin\..\mods\wastemod\init.lua:79: attempt to index a nil value
2016-02-22 14:02:15: ERROR[main]: stack traceback:
2016-02-22 14:02:15: ERROR[main]:    ...Jeanne\Desktop\D.s-Sandbox\bin\..\mods\wastemod\init.lua:79: in function <...Jeanne\Desktop\D.s-Sandbox\bin\..\mods\wastemod\init.lua:73>
2016-02-22 14:02:15: ERROR[main]:    ...nne\Desktop\D.s-Sandbox\bin\..\builtin\game\register.lua:355: in function <...nne\Desktop\D.s-Sandbox\bin\..\builtin\game\register.lua:335>

In thread a48:
server.cpp:511: Server::step: A fatal error occurred: Runtime error from mod '??' in callback ScriptApiEnv::environment_Step(): ...Jeanne\Desktop\D.s-Sandbox\bin\..\mods\wastemod\init.lua:79: attempt to index a nil value
stack traceback:
   ...Jeanne\Desktop\D.s-Sandbox\bin\..\mods\wastemod\init.lua:79: in function <...Jeanne\Desktop\D.s-Sandbox\bin\..\mods\wastemod\init.lua:73>
   ...nne\Desktop\D.s-Sandbox\bin\..\builtin\game\register.lua:355: in function <...nne\Desktop\D.s-Sandbox\bin\..\builtin\game\register.lua:335>
2016-02-22 14:02:15: ACTION[ServerThread]: Diana leaves game. List of players:
Debug stacks:
DEBUG STACK FOR THREAD a48:
#0  main
#1  Dedicated server branch
#2  dedicated_server_loop
#3  Server::step
DEBUG STACK FOR THREAD 1808:
#0  ServerThread::Thread
#1  Server::AsyncRunStep
#2  Server::DeleteClient
(Leftover data: #3  RemoteClient::GetNextBlocks)
(Leftover data: #4  ItemStack::serialize)
(Leftover data: #5  getCraftingResult)
(Leftover data: #6  ItemStack::deSerialize)
DEBUG STACK FOR THREAD 1b34:
#0  EmergeThread::Thread
(Leftover data: #1  ServerMap::loadBlock)
(Leftover data: #2  ServerMap::loadBlock)
(Leftover data: #3  ServerMap::loadBlock)
crash.txtOpen
Displaying crash.txt.
Project Lead of the Doom 3 Mod Last Man Standing - http://Doom3Coop.com

Project Lead of Platinum Arts Sandbox Free 3D Game Maker - http://SandboxGameMaker.com

Youtube Channel - https://www.youtube.com/user/PlatinumArtsKids
 

blert2112
Member
 
Posts: 244
Joined: Sat Apr 25, 2015 04:05
GitHub: blert2112

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by blert2112 » Fri Feb 26, 2016 03:47

I'm not having any troubles with it. I will need to see your full code to see what's going on.
 

User avatar
TheReaperKing
Member
 
Posts: 493
Joined: Sun Nov 22, 2015 21:36

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by TheReaperKing » Fri Feb 26, 2016 15:31

It doesn't crash when it is just me but only when I have multiple people on the server and it doesn't always crash I believe, just sometimes. Thanks so much for even looking at it, I really need to set aside some time this weekend.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- ADDED WASTE
minetest.register_craftitem("wastemod:waste", {
   description = "Waste",
   inventory_image = "wastemod_waste.png",
   --groups={waste},
})




-- A HUGE THANKS TO blert2112 FOR HIS HELP WITH THIS CODE!!!

--local harm = 2  Don't use yet, tie with being poisoned?

local timer = 0
core.register_globalstep(function(dtime)
   timer = timer + dtime;
   if timer >= 300 then
      local players = core.get_connected_players()
      for i = 1,#players do
         local name = players[i]:get_player_name()
         core.chat_send_player(name, "You don't feel so good :(")
         
       --[[   Remove hurt stuff for now and make it poison
         local inv = players[i]:get_inventory()
         if inv:contains_item("main", "wastemod:waste") then
            hp = players[i]:get_hp()
            players[i]:set_hp(hp - harm)
         end
         --]]
      
         players[i]:get_inventory():add_item("main", "wastemod:waste")
      end
      timer = 0
   end
end)
Project Lead of the Doom 3 Mod Last Man Standing - http://Doom3Coop.com

Project Lead of Platinum Arts Sandbox Free 3D Game Maker - http://SandboxGameMaker.com

Youtube Channel - https://www.youtube.com/user/PlatinumArtsKids
 

blert2112
Member
 
Posts: 244
Joined: Sat Apr 25, 2015 04:05
GitHub: blert2112

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by blert2112 » Fri Feb 26, 2016 17:29

Hmmm... Then it probably has something to do with the player logging out in the middle of the function running. Add a check to see if the player still exists before you add to the inventory.
 

User avatar
TheReaperKing
Member
 
Posts: 493
Joined: Sun Nov 22, 2015 21:36

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by TheReaperKing » Sun Feb 28, 2016 08:07

I am so sorry, you know what I think it is, I had some code down below that I didn't comment out. I have been trying to save the code to learn about it and looks like I missed some. I will be sure to test on Monday with the kiddos. Sorry about that and thank you so much for all of your help!!!!!!!!!!!!!!!!!
Project Lead of the Doom 3 Mod Last Man Standing - http://Doom3Coop.com

Project Lead of Platinum Arts Sandbox Free 3D Game Maker - http://SandboxGameMaker.com

Youtube Channel - https://www.youtube.com/user/PlatinumArtsKids
 

User avatar
TheReaperKing
Member
 
Posts: 493
Joined: Sun Nov 22, 2015 21:36

Re: Give An Item To All Players (Plus Slowing Down Tree Grow

by TheReaperKing » Sun Mar 06, 2016 04:13

The code seemed to be working well and there haven't been any crashes!! Thank you so much for all of your help! Are you ever open to some commissioned coding jobs/help? Take care! :D
-Mike
Project Lead of the Doom 3 Mod Last Man Standing - http://Doom3Coop.com

Project Lead of Platinum Arts Sandbox Free 3D Game Maker - http://SandboxGameMaker.com

Youtube Channel - https://www.youtube.com/user/PlatinumArtsKids
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron