Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
local gender_file = minetest.get_worldpath() .. "/player_genders"
local genders = {}
local function loadgenders()
local input = io.open(gender_file, "r")
if input then
repeat
local gender_choice = input:read("*n")
if gender_choice == nil then
break
end
local name = input:read("*l")
genders[name:sub(2)] = gender_choice
until input:read(0) == nil
io.close(input)
else
genders = {}
end
end
loadgenders()
local changed = false
minetest.register_chatcommand("player_male", {
description = "Sets your player model to the default male one",
func = function(name)
local player = minetest.env:get_player_by_name(name)
if player == nil then
return false
end
if true then
file = io.open(minetest.get_modpath("player_textures").."/textures/player_pilzadam.png")
if file then
file:close()
default.player_set_model(player, "character.b3d")
local filename = minetest.get_modpath("player_textures").."/textures/player_"..player:get_player_name()
local f = io.open(filename..".png")
if f then
f:close()
player:set_properties({
textures = {"player_"..player:get_player_name()..".png"},
})
end
end
player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30)
minetest.chat_send_player(name, "Set player model to male!")
changed = true
if changed then
local output = io.open(gender_file, "w")
output:write("1".." "..player:get_player_name().."\n")
end
changed = false
else
default.player_set_model(player, "character.b3d")
end
end,
})
minetest.register_chatcommand("player_female", {
description = "Sets your player model to the female one",
func = function(name)
local player = minetest.env:get_player_by_name(name)
if player == nil then
return false
end
if true then
default.player_set_model(player, "characterfemale.b3d")
file = io.open(minetest.get_modpath("player_textures").."/textures/player_pilzadam.png")
if file then
file:close()
local filename = minetest.get_modpath("player_textures").."/textures/player_"..player:get_player_name()
local f = io.open(filename..".png")
if f then
f:close()
player:set_properties({
textures = {"player_"..player:get_player_name()..".png"},
})
end
else
default.player_set_model(player, "characterfemale.b3d")
end
player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30)
minetest.chat_send_player(name, "Set player model to female!")
changed = true
if changed then
local output = io.open(gender_file, "w")
output:write("0".." "..player:get_player_name().."\n")
end
changed = false
end
end,
})
minetest.register_on_joinplayer(function(player)
loadgenders()
if genders[player:get_player_name()] == 1 then
default.player_set_model(player, "character.b3d")
player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30)
elseif genders[player:get_player_name()] == 0 then
default.player_set_model(player, "characterfemale.b3d")
player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30)
else
default.player_set_model(player, "character.b3d")
player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30)
minetest.chat_send_player(player:get_player_name(), "Please set your gender via /player_male or /player_female, thank you. You can also ignore this message and use the default male model. This message will be shown again when you rejoin.")
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.