diff --git a/README.md b/README.md index a798ac9..86cf943 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ no matter what rules. ## Technical info ------------- -This mod has an improved way to do not hand server if no valild spawn point +This mod has an improved way to do not hang server if no valild spawn point is found in some minutes.. cos all spawn managers in minetest causes problems when players joins. @@ -36,6 +36,14 @@ or taidkez's rspawn original work. It will send a chat notificatin private message to the player about new spawn position, is configurable with `spawnrand.notification_position` boolean value with defaults as `true`. +The spawn area will have a radious almost to the limit (but not the), from center of world, +is configurable with `spawnrand.radius_area` integer value with defaults as `20000`. + +#### performance + +If your server has huge users, you must increase the spawn area, but not so much, people +will just be repositioned at new position event define a new spawn if fails, so performance +will be not an issue if no a valid spawn point will found. License ------ diff --git a/init.lua b/init.lua index 40288b9..07a2e36 100644 --- a/init.lua +++ b/init.lua @@ -13,12 +13,38 @@ if beds == nil then bed_respawn = false end +-- enalbe random only if radio are enought in game +local enable_rand = true + +-- send notification to players only if enabled local notice_pos = minetest.settings:get_bool("spawnrand.notification_position") or true +-- detect limits of maps to do not spawn close to borders +local mapgen_limit = tonumber(minetest.settings:get("mapgen_limit")) or 30000 + +-- set the radio of the spawn area to search +local radius_area = tonumber(minetest.settings:get("spawnrand.radius_area")) or math.abs(mapgen_limit) + +-- now autodetection of the area and limits +radius_area = math.abs(radius_area) + +if ( radius_area >= mapgen_limit ) then + radius_area = mapgen_limit -- too big or invalid +end +if ( radius_area < 100 ) then + radius_area = 300 -- too small will hit performance in big servers +end +if ( radius_area >= 20000 ) then + radius_area = radius_area - mapgen_limit * 0.2 -- avoid borders +end +if ( radius_area < 3 ) then + enable_rand = false -- this area is nonsense disable then +end + -- spawnrand function invocation, it uses internat "find_ground" to fid valid position from initial one function spawnrand(player) local elevation = 20 - local radius = 600 + local radius = ratio_area local posx = math.random(-radius, radius) local posz = math.random(-radius, radius) local new_spawn = {x = -174 + posx, y = elevation, z = 178 + posz} @@ -98,16 +124,19 @@ minetest.register_node('spawnrand:node', { paramtype = 'light', light_source = 10, on_punch = function(pos, node, player) + if not enable_rand then + minetest.chat_send_player(player:get_player_name( ), "WARNING radio is 1, current position : ".. pos.x ..","..pos.y..","..pos.z ) + end spawnrand(player) end }) --- newspam in new player join +-- newspam in new player join, if radio 1 disable rand due performance, new players do not have bed rest yet minetest.register_on_newplayer(function(player) local pos - if player ~= nil then + if player ~= nil and enable_rand then pos = player:getpos() if notice_pos then minetest.chat_send_player(player:get_player_name( ), "...awaiting new spawn from : ".. pos.x ..","..pos.y..","..pos.z ) @@ -122,7 +151,7 @@ minetest.register_on_respawnplayer(function(player) local name, pos - if player ~= nil then + if player ~= nil and enable_rand then name = player:get_player_name() pos = player:getpos() if notice_pos then diff --git a/mod.conf b/mod.conf index b1770fb..5748d00 100644 --- a/mod.conf +++ b/mod.conf @@ -1,4 +1,5 @@ name = spawnrand +title = minetest-mod-spawnrand depends = optional_depends = beds description = SPAWN random on each respawn of player diff --git a/settingtypes.txt b/settingtypes.txt index ea00ae1..cd2f84f 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -1,2 +1,5 @@ # will send a chat notificatin private message to the player about new spawn position -spawnrand.notification_position (Send a private notification about new pos to player) bool true +spawnrand.notification_position (Send a private notification about new pos to player, can be set in game) bool true + +# radious spawn area to randomlly put the positon, by default only 600 nodes from center +spawnrand.radius_area (Ratio area from center to find a spawn position, cannot set in game, must be set before run) int 20000