Original link: https://www.shuizilong.com/house/archives/minetest-in-game-transfer/
Client modification
It was found that Minetest’s engine code is the same cpp as easyrpg, which means that it also has the opportunity to use emscripten to compile and run in the browser.
I searched online and found that someone has actually done this. . .
https://ift.tt/juUd590
So now the transfer command is very easy to implement, you can write it in js first, and then directly call the corresponding js method.
Safety issues are not considered. . Let’s do a simple and general implementation first. . Execute any script with the evil Dr.Eval method. . .
void escape_EM_ASM(const std::wstring &message) { std::wstring m = translate_string(message); std::string s(m.length(), 0); std::transform(m.begin(), m.end(), s.begin(), [] (wchar_t c) { return (char)c; }); MAIN_THREAD_ASYNC_EM_ASM(console.log("Msg: " + UTF8ToString($0)), s.c_str()); std::string c; c = ".EM_ASM "; if (s.find(c) != std::string::npos) { s = s.substr(s.find(c) + c.size()); MAIN_THREAD_ASYNC_EM_ASM(eval(UTF8ToString($0)), s.c_str()); return; } }
Note that I stepped on a pit here. . . https://ift.tt/Ljcvfnx
Simply put, this is the best way to use this command. . MAIN_THREAD_ASYNC_EM_ASM. . .
If the above code is replaced with EM_ASM, then the js code in the trigger can still be used when sending a message.
But if the parsing is invalid when the server receives the message once, the minetest.chat_send_player(name, text)
API in the module will go through the server once.
Mod modification
The first requirement of the mod is that we need to have an action that triggers the event of a right-click on the player. . . on_rightclick
or something. .
I searched around and found that there is no ready-made API. . .
But there is an existing mod that has this functionality. . . So let’s start with that mod. . .
First add the right_click event, we create a menu. . .
https://ift.tt/cJC9te1
minetest.register_on_rightclickplayer(function(player, clicker) local s = clicker:get_player_name() local t = player:get_player_name() local controls = clicker:get_player_control() if not(check_distance(clicker, player)) then minetest.chat_send_player(s, S("Target too far.")) return end local context = get_context(s) context.target = t local formspec = { "formspec_version[4]", "size[4.5,5.25]", "label[0.375,0.5;", minetest.formspec_escape("This is " .. t .. "."), "]", "button_exit[0.5,1;3.5,0.8;profile;Profile]", "button_exit[0.5,2;3.5,0.8;transfer;Transfer]", "button_exit[0.5,3;3.5,0.8;follow;Follow]", "button_exit[0.5,4;3.5,0.8;cancel;Cancel]" } minetest.show_formspec(s, "player:interact", table.concat(formspec, "")) end)
In the above code, we have opened a state context.target to record the current interaction object. .
Then you can process the receipt of the menu. . .
minetest.register_on_player_receive_fields(function(player, formname, fields) if formname == "player:interact" then local s = player:get_player_name() local t = get_context(s).target if fields.profile then minetest.chat_send_player(s, ".EM_ASM window.open(\"https://" .. t .. ".test.w3itch.io/zh-CN\", \"new\")") end if fields.transfer then minetest.chat_send_player(s, ".EM_ASM alert(feature not implement yet...)") end if fields. follow then minetest.chat_send_player(s, ".EM_ASM alert(feature not implement yet...)") end return true end end)
This article is transferred from: https://www.shuizilong.com/house/archives/minetest-in-game-transfer/
This site is for inclusion only, and the copyright belongs to the original author.