diff options
author | Maverick2797 <git.maverick2797@gmail.com> | 2025-02-07 22:43:19 +0800 |
---|---|---|
committer | orwell <orwell@bleipb.de> | 2025-03-24 22:56:35 +0100 |
commit | a4a0151504c5764c183830fc0b71c777f75e7119 (patch) | |
tree | 3da71897d98a1ce95f066aeb949f105e66e35dad | |
parent | 7f085d194d403f60732caa2228ea7024d060042d (diff) | |
download | advtrains-a4a0151504c5764c183830fc0b71c777f75e7119.tar.gz advtrains-a4a0151504c5764c183830fc0b71c777f75e7119.tar.bz2 advtrains-a4a0151504c5764c183830fc0b71c777f75e7119.zip |
Add /at_chown to allow changing wagon ownership
-rw-r--r-- | advtrains/wagons.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index 52d39b7..10576c3 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -1565,3 +1565,32 @@ function advtrains.wagon_entity_pairs_in_train(train_id) if not train then return function() end end return advtrains.next_wagon_entity_in_train, train, 0 end + +minetest.register_chatcommand("at_chown", { + params = "<wagon_id> <player_name>", + description = "Change the owner of an advtrains wagon", + privs = {train_admin=true}, + func = function(name, param) + local params = string.split(param," ") + local wid = params[1] + local new_owner = params[2] + if not wid then return false end --no params added + --player name checks + if not new_owner then return false, attrans("Please specify a player name to transfer ownership to.") end --no player name argument + if not core.player_exists(new_owner) then return false, attrans("That player does not exist!") end --is a valid player + --wagon id checks + if not wid:match("%d%d%d%d%d%d") then return false, attrans("Not a valid wagon id.") end -- invalid wagon id + local w_data = advtrains.wagons[wid] + if not w_data then return false, attrans("That wagon does not exist!") end + -- actually chown the wagon + local curr_owner = w_data.owner + w_data.owner = new_owner + advtrains.wagons[wid] = w_data + advtrains.log("Chown", name, core.get_player_by_name(name):get_pos(), "wid="..wid..", from="..curr_owner..", to="..new_owner) + + if name ~= new_owner then + core.chat_send_player(new_owner, attrans("You have been given ownership of wagon @1", wid)) + end + return true, attrans("Wagon @1 ownership changed from @2 to @3", wid, curr_owner, new_owner) + end +})
\ No newline at end of file |