Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kif_custom
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Minetest
kif_custom
Commits
b8df2d17
Commit
b8df2d17
authored
4 years ago
by
Peter Nerlich
Browse files
Options
Downloads
Patches
Plain Diff
add script to stop all trains x seconds after the last player left the server
parent
ad912cb8
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
advtrains/stop_on_inactivity.lua
+61
-0
61 additions, 0 deletions
advtrains/stop_on_inactivity.lua
settingtypes.txt
+5
-0
5 additions, 0 deletions
settingtypes.txt
with
66 additions
and
0 deletions
advtrains/stop_on_inactivity.lua
0 → 100644
+
61
−
0
View file @
b8df2d17
local
DISABLE_TIMEOUT
=
tonumber
(
minetest
.
settings
:
get
(
"kif_custom.advtrains.disable_timeout"
))
or
60
*
60
local
trains_disabled
=
#
minetest
.
get_connected_players
==
0
local
disable_job
=
nil
minetest
.
register_on_joinplayer
(
function
(
player
,
last_login
)
-- activate trains
if
disable_job
~=
nil
then
disable_job
:
cancel
()
disable_job
=
nil
end
if
trains_disabled
then
trains_disabled
=
false
end
end
)
minetest
.
register_on_leaveplayer
(
function
(
player
,
timed_out
)
if
#
minetest
.
get_connected_players
()
==
0
then
-- deactivate trains
if
disable_job
==
nil
then
disable_job
=
minetest
.
after
(
DISABLE_TIMEOUT
,
function
()
trains_disabled
=
true
disable_job
=
nil
end
)
end
end
end
)
-- overrides
assert
(
type
(
advtrains
.
train_ensure_init
)
==
"function"
)
local
old_train_ensure_init
=
advtrains
.
train_ensure_init
advtrains
.
train_ensure_init
=
function
(
k
,
v
)
if
trains_disabled
then
return
else
return
old_train_ensure_init
(
k
,
v
)
end
end
assert
(
type
(
advtrains
.
train_step_b
)
==
"function"
)
local
old_train_step_b
=
advtrains
.
train_step_b
advtrains
.
train_step_b
=
function
(
k
,
v
,
dtime
)
if
trains_disabled
then
return
else
return
old_train_step_b
(
k
,
v
,
dtime
)
end
end
assert
(
type
(
advtrains
.
train_step_c
)
==
"function"
)
local
old_train_step_c
=
advtrains
.
train_step_c
advtrains
.
train_step_c
=
function
(
k
,
v
,
dtime
)
if
trains_disabled
then
return
else
return
old_train_step_c
(
k
,
v
,
dtime
)
end
end
This diff is collapsed.
Click to expand it.
settingtypes.txt
+
5
−
0
View file @
b8df2d17
...
...
@@ -13,3 +13,8 @@ kif_custom.death.waypoint_expires_seconds_creative (Seconds in which waypoints e
# until it disappears, but also changes to a blue, green and finally red tint before disappearing.
# The saturation interpolates between the color and the grey shade of the same value.
kif_custom.death.waypoint_saturation (Color saturation) float 1 0 2
[advtrains]
# The amount of seconds until all trains are stopped after the last player has left.
kif_custom.advtrains.disable_timeout (Disable timeout) int 3600 0 604800
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment