radio area spawn automatic detection feature, with reposition player if fails
* define spawn area from settings * autodetect limit of world and limit the radio spawn area to this * if radious area is big limit to almost the border * if radious area is small limit to almost 600 * disable if radio is too small or less than 3master
parent
6031e8d0e3
commit
73225604e6
10
README.md
10
README.md
|
@ -15,7 +15,7 @@ no matter what rules.
|
||||||
## Technical info
|
## 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
|
is found in some minutes.. cos all spawn managers in minetest causes problems
|
||||||
when players joins.
|
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,
|
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`.
|
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
|
License
|
||||||
------
|
------
|
||||||
|
|
37
init.lua
37
init.lua
|
@ -13,12 +13,38 @@ if beds == nil then
|
||||||
bed_respawn = false
|
bed_respawn = false
|
||||||
end
|
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
|
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
|
-- spawnrand function invocation, it uses internat "find_ground" to fid valid position from initial one
|
||||||
function spawnrand(player)
|
function spawnrand(player)
|
||||||
local elevation = 20
|
local elevation = 20
|
||||||
local radius = 600
|
local radius = ratio_area
|
||||||
local posx = math.random(-radius, radius)
|
local posx = math.random(-radius, radius)
|
||||||
local posz = math.random(-radius, radius)
|
local posz = math.random(-radius, radius)
|
||||||
local new_spawn = {x = -174 + posx, y = elevation, z = 178 + posz}
|
local new_spawn = {x = -174 + posx, y = elevation, z = 178 + posz}
|
||||||
|
@ -98,16 +124,19 @@ minetest.register_node('spawnrand:node', {
|
||||||
paramtype = 'light',
|
paramtype = 'light',
|
||||||
light_source = 10,
|
light_source = 10,
|
||||||
on_punch = function(pos, node, player)
|
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)
|
spawnrand(player)
|
||||||
end
|
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)
|
minetest.register_on_newplayer(function(player)
|
||||||
|
|
||||||
local pos
|
local pos
|
||||||
if player ~= nil then
|
if player ~= nil and enable_rand then
|
||||||
pos = player:getpos()
|
pos = player:getpos()
|
||||||
if notice_pos then
|
if notice_pos then
|
||||||
minetest.chat_send_player(player:get_player_name( ), "...awaiting new spawn from : ".. pos.x ..","..pos.y..","..pos.z )
|
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
|
local name, pos
|
||||||
|
|
||||||
if player ~= nil then
|
if player ~= nil and enable_rand then
|
||||||
name = player:get_player_name()
|
name = player:get_player_name()
|
||||||
pos = player:getpos()
|
pos = player:getpos()
|
||||||
if notice_pos then
|
if notice_pos then
|
||||||
|
|
1
mod.conf
1
mod.conf
|
@ -1,4 +1,5 @@
|
||||||
name = spawnrand
|
name = spawnrand
|
||||||
|
title = minetest-mod-spawnrand
|
||||||
depends =
|
depends =
|
||||||
optional_depends = beds
|
optional_depends = beds
|
||||||
description = SPAWN random on each respawn of player
|
description = SPAWN random on each respawn of player
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
# will send a chat notificatin private message to the player about new spawn position
|
# 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
|
||||||
|
|
Loading…
Reference in New Issue