97
97
98
98
minetest .register_chatcommand (" donate" , {
99
99
description = " Donate your match score to your teammate\n Can be used only once in 2.5 minutes" ,
100
- params = " <playername> [playernames] <score> [message]" ,
100
+ params = " <name [name2 name3 ...]> <score> [message]" ,
101
101
func = function (name , param )
102
102
local current_mode = ctf_modebase :get_current_mode ()
103
103
if not current_mode or not ctf_modebase .match_started then
@@ -106,17 +106,18 @@ minetest.register_chatcommand("donate", {
106
106
107
107
local pnames , score , dmessage = {}, 0 , " "
108
108
109
- local pcount = 0
109
+ local pcount , ismessage = 0 , false
110
110
111
111
for p in string.gmatch (param , " %S+" ) do
112
- if # dmessage > 0 then
112
+ if ismessage then
113
113
dmessage = dmessage .. " " .. p
114
114
elseif ctf_core .to_number (p ) and score == 0 then
115
115
score = p
116
116
else
117
117
local team = ctf_teams .get (p )
118
118
if not team and pcount > 0 then
119
119
dmessage = dmessage .. p
120
+ ismessage = true
120
121
else
121
122
if pnames [p ] then
122
123
return false , " You cannot donate more than once to the same person."
@@ -126,7 +127,7 @@ minetest.register_chatcommand("donate", {
126
127
return false , ' You cannot donate to yourself!'
127
128
end
128
129
129
- if not ctf_teams . get (p ) then
130
+ if not minetest . get_player_by_name (p ) then
130
131
return false , string.format (" Player %s is not online!" , p )
131
132
end
132
133
@@ -158,11 +159,7 @@ minetest.register_chatcommand("donate", {
158
159
return false , " You can donate no more than 400 score!"
159
160
end
160
161
161
- local scoretotal = 0
162
- for pname , _ in pairs (pnames ) do
163
- scoretotal = scoretotal + score
164
- end
165
-
162
+ local scoretotal = score * pcount
166
163
local cur_score = math.min (
167
164
current_mode .recent_rankings .get (name ).score or 0 ,
168
165
(current_mode .rankings :get (name ) or {}).score or 0
@@ -181,23 +178,16 @@ minetest.register_chatcommand("donate", {
181
178
182
179
dmessage = (dmessage and dmessage ~= " " ) and (" :" .. dmessage ) or " "
183
180
184
- local pname , names = next ( pnames ), " "
185
- while pname do
181
+ local names = " "
182
+ for pname , team in pairs ( pnames ) do
186
183
current_mode .recent_rankings .add (pname , {score = score }, true )
187
184
current_mode .recent_rankings .add (name , {score =- score }, true )
188
-
189
185
minetest .log (" action" , string.format (
190
186
" Player '%s' donated %s score to player '%s'" , name , score , pname
191
187
))
192
-
193
- names = names .. pname
194
-
195
- pname = next (pnames , pname )
196
- if pname then
197
- names = names .. " , "
198
- end
188
+ names = names .. pname .. " , "
199
189
end
200
-
190
+ names = names : sub ( 1 , - 3 )
201
191
if pcount > 2 then
202
192
names = string.gsub (names , " , (%S+)$" , " , and %1" )
203
193
elseif pcount > 1 then
0 commit comments