@@ -8,144 +8,153 @@ spawned_mobs = {}
8
8
9
9
-- Spawn a monster of the given name in a position, disabling the infotext of the monster
10
10
spawn_monster = function (pos , name )
11
- local obj = minetest .add_entity (pos , name )
12
-
13
- -- Get the registered monster object
14
- local mob_def = minetest .registered_entities [name ]
15
- if mob_def then
16
- -- Remove the update_tag function, this prevents showing the infotext
17
- mob_def .update_tag = function (self )
18
- end
19
- -- Provide some reward when the monster dies
20
- mob_def .on_die = function (self )
21
- set_reward_once (rwd_kill_monster )
22
- end
23
- end
24
-
25
- table.insert (spawned_mobs , obj )
11
+ local obj = minetest .add_entity (pos , name )
12
+
13
+ -- Get the registered monster object
14
+ local mob_def = minetest .registered_entities [name ]
15
+ if mob_def then
16
+ -- Remove the update_tag function, this prevents showing the infotext
17
+ mob_def .update_tag = function (self ) end
18
+ -- Provide some reward when the monster dies
19
+ mob_def .on_die = function (self )
20
+ set_reward_once (rwd_kill_monster )
21
+ end
22
+ end
23
+
24
+ table.insert (spawned_mobs , obj )
26
25
end
27
26
28
27
respawn_objective = function ()
29
- item = minetest .add_item (objective_pos , minetest .settings :get (" objective_item" ))
30
-
31
- -- Scale the item by some factor
32
- local scale_factor = 2
33
- local props = item :get_properties ()
34
-
35
- item :set_properties ({
36
- visual_size = {
37
- x = props .visual_size .x * scale_factor , y = props .visual_size .y * scale_factor , z = props .visual_size .z * scale_factor
38
- },
39
- collisionbox = {
40
- props .collisionbox [1 ] * scale_factor , props .collisionbox [2 ] * scale_factor , props .collisionbox [3 ] * scale_factor ,
41
- props .collisionbox [4 ] * scale_factor , props .collisionbox [5 ] * scale_factor , props .collisionbox [6 ] * scale_factor
42
- },
43
- selectionbox = {
44
- props .selectionbox [1 ] * scale_factor , props .selectionbox [2 ] * scale_factor , props .selectionbox [3 ] * scale_factor ,
45
- props .selectionbox [4 ] * scale_factor , props .selectionbox [5 ] * scale_factor , props .selectionbox [6 ] * scale_factor
46
- }
47
- })
48
-
49
- -- Override the 'on_punch' callback for this item to provide some reward when collected
50
- item :get_luaentity ().on_punch = function (self , _puncher )
51
- set_reward_once (rwd_objective , 0.0 )
52
- set_termination ()
53
- end
28
+ item = minetest .add_item (objective_pos , minetest .settings :get (" objective_item" ))
29
+
30
+ -- Scale the item by some factor
31
+ local scale_factor = 2
32
+ local props = item :get_properties ()
33
+
34
+ item :set_properties ({
35
+ visual_size = {
36
+ x = props .visual_size .x * scale_factor ,
37
+ y = props .visual_size .y * scale_factor ,
38
+ z = props .visual_size .z * scale_factor ,
39
+ },
40
+ collisionbox = {
41
+ props .collisionbox [1 ] * scale_factor ,
42
+ props .collisionbox [2 ] * scale_factor ,
43
+ props .collisionbox [3 ] * scale_factor ,
44
+ props .collisionbox [4 ] * scale_factor ,
45
+ props .collisionbox [5 ] * scale_factor ,
46
+ props .collisionbox [6 ] * scale_factor ,
47
+ },
48
+ selectionbox = {
49
+ props .selectionbox [1 ] * scale_factor ,
50
+ props .selectionbox [2 ] * scale_factor ,
51
+ props .selectionbox [3 ] * scale_factor ,
52
+ props .selectionbox [4 ] * scale_factor ,
53
+ props .selectionbox [5 ] * scale_factor ,
54
+ props .selectionbox [6 ] * scale_factor ,
55
+ },
56
+ })
57
+
58
+ -- Override the 'on_punch' callback for this item to provide some reward when collected
59
+ item :get_luaentity ().on_punch = function (self , _puncher )
60
+ set_reward_once (rwd_objective , 0.0 )
61
+ set_termination ()
62
+ end
54
63
end
55
64
56
65
minetest .register_on_joinplayer (function (player , _last_login )
57
- -- Disable HUD elements
58
- player :hud_set_flags ({
59
- crosshair = false ,
60
- basic_debug = false ,
61
- healthbar = false ,
62
- hotbar = false ,
63
- })
64
-
65
- -- Generate map and locate the player and monsters
66
- local map , _ = minetest .settings :get (" ascii_map" ):gsub (" \\ n" , " \n " )
67
- local material_wall = minetest .settings :get (" wall_material" )
68
- local y = 4.5 -- The height of the terrain
69
- local z = 0
70
- for row in string.gmatch (map , " [^\n ]+" ) do
71
- local x = 0
72
- for c in string.gmatch (row , " ." ) do
73
- if c == " #" then
74
- minetest .set_node ({x = x , y = y , z = z }, { name = material_wall })
75
- elseif c == " O" then
76
- objective_pos = {x = x , y = y + 1 , z = z }
77
- respawn_objective ()
78
- elseif c == " -" then
79
- y = y + 1
80
- z = - 1
81
- x = - 1
82
- elseif c == " @" then
83
- player_pos = {x = x , y = y , z = z }
84
- player :set_pos (player_pos )
85
- elseif c == " a" then
86
- local pos = {x = x , y = y , z = z }
87
- local name = minetest .settings :get (" monster_type_a" )
88
- spawn_monster (pos , name )
89
- table.insert (mobs_info , { pos = pos , name = name })
90
- elseif c == " b" then
91
- local pos = {x = x , y = y , z = z }
92
- local name = minetest .settings :get (" monster_type_b" )
93
- spawn_monster (pos , name )
94
- table.insert (mobs_info , { pos = pos , name = name })
95
- elseif c == " c" then
96
- local pos = {x = x , y = y , z = z }
97
- local name = minetest .settings :get (" monster_type_c" )
98
- spawn_monster (pos , name )
99
- table.insert (mobs_info , { pos = pos , name = name })
100
- elseif c == " d" then
101
- local pos = {x = x , y = y , z = z }
102
- local name = minetest .settings :get (" monster_type_d" )
103
- spawn_monster (pos , name )
104
- table.insert (mobs_info , { pos = pos , name = name })
105
- end
106
- x = x + 1
107
- end
108
- z = z + 1
109
- end
66
+ -- Disable HUD elements
67
+ player :hud_set_flags ({
68
+ crosshair = false ,
69
+ basic_debug = false ,
70
+ healthbar = false ,
71
+ hotbar = false ,
72
+ })
73
+
74
+ -- Generate map and locate the player and monsters
75
+ local map , _ = minetest .settings :get (" ascii_map" ):gsub (" \\ n" , " \n " )
76
+ local material_wall = minetest .settings :get (" wall_material" )
77
+ local y = 4.5 -- The height of the terrain
78
+ local z = 0
79
+ for row in string.gmatch (map , " [^\n ]+" ) do
80
+ local x = 0
81
+ for c in string.gmatch (row , " ." ) do
82
+ if c == " #" then
83
+ minetest .set_node ({ x = x , y = y , z = z }, { name = material_wall })
84
+ elseif c == " %" then
85
+ minetest .set_node ({ x = x , y = y , z = z }, { name = " default:glass" })
86
+ elseif c == " O" then
87
+ objective_pos = { x = x , y = y + 1 , z = z }
88
+ respawn_objective ()
89
+ elseif c == " -" then
90
+ y = y + 1
91
+ z = - 1
92
+ x = - 1
93
+ elseif c == " @" then
94
+ player_pos = { x = x , y = y , z = z }
95
+ player :set_pos (player_pos )
96
+ elseif c == " a" then
97
+ local pos = { x = x , y = y , z = z }
98
+ local name = minetest .settings :get (" monster_type_a" )
99
+ spawn_monster (pos , name )
100
+ table.insert (mobs_info , { pos = pos , name = name })
101
+ elseif c == " b" then
102
+ local pos = { x = x , y = y , z = z }
103
+ local name = minetest .settings :get (" monster_type_b" )
104
+ spawn_monster (pos , name )
105
+ table.insert (mobs_info , { pos = pos , name = name })
106
+ elseif c == " c" then
107
+ local pos = { x = x , y = y , z = z }
108
+ local name = minetest .settings :get (" monster_type_c" )
109
+ spawn_monster (pos , name )
110
+ table.insert (mobs_info , { pos = pos , name = name })
111
+ elseif c == " d" then
112
+ local pos = { x = x , y = y , z = z }
113
+ local name = minetest .settings :get (" monster_type_d" )
114
+ spawn_monster (pos , name )
115
+ table.insert (mobs_info , { pos = pos , name = name })
116
+ end
117
+ x = x + 1
118
+ end
119
+ z = z + 1
120
+ end
110
121
end )
111
122
112
- minetest .register_on_player_hpchange (
113
- function (player , hp_change , reason )
114
- if player :get_hp () + hp_change <= 0 then -- Check if the player will die
115
- set_termination ()
116
- return 0 -- Avoid the death of the player that shows the death screen
117
- end
118
- return hp_change
119
- end ,
120
- true )
123
+ minetest .register_on_player_hpchange (function (player , hp_change , reason )
124
+ if player :get_hp () + hp_change <= 0 then -- Check if the player will die
125
+ set_termination ()
126
+ return 0 -- Avoid the death of the player that shows the death screen
127
+ end
128
+ return hp_change
129
+ end , true )
121
130
122
131
minetest .register_globalstep (function (dtime )
123
- -- Set timeofday to midday
124
- minetest .set_timeofday (0.5 )
125
-
126
- -- Reset the environment if requested by the python interface
127
- if get_soft_reset () == 1 then
128
- -- Remove the objective item if it's already spawned
129
- item :remove ()
130
- -- Respawn the objective
131
- respawn_objective ()
132
-
133
- -- Remove all monsters
134
- for _ , mob in ipairs (spawned_mobs ) do
135
- mob :remove ()
136
- end
137
- spawned_mobs = {}
138
-
139
- -- Respawn all monsters
140
- for _ , info in ipairs (mobs_info ) do
141
- spawn_monster (info .pos , info .name )
142
- end
143
-
144
- -- Reset player's health and position
145
- local player = minetest .get_connected_players ()[1 ]
146
- player :set_hp (20 , {type = " set_hp" , from = " mod" })
147
- player :set_pos (player_pos )
148
-
149
- reset_termination ()
150
- end
132
+ -- Set timeofday to midday
133
+ minetest .set_timeofday (0.5 )
134
+
135
+ -- Reset the environment if requested by the python interface
136
+ if get_soft_reset () == 1 then
137
+ -- Remove the objective item if it's already spawned
138
+ item :remove ()
139
+ -- Respawn the objective
140
+ respawn_objective ()
141
+
142
+ -- Remove all monsters
143
+ for _ , mob in ipairs (spawned_mobs ) do
144
+ mob :remove ()
145
+ end
146
+ spawned_mobs = {}
147
+
148
+ -- Respawn all monsters
149
+ for _ , info in ipairs (mobs_info ) do
150
+ spawn_monster (info .pos , info .name )
151
+ end
152
+
153
+ -- Reset player's health and position
154
+ local player = minetest .get_connected_players ()[1 ]
155
+ player :set_hp (20 , { type = " set_hp" , from = " mod" })
156
+ player :set_pos (player_pos )
157
+
158
+ reset_termination ()
159
+ end
151
160
end )
0 commit comments