2013-05-25 00:51:02 +02:00
|
|
|
/*
|
|
|
|
Minetest
|
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cpp_api/s_player.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "cpp_api/s_internal.h"
|
2014-05-17 06:47:12 +02:00
|
|
|
#include "common/c_converter.h"
|
|
|
|
#include "common/c_content.h"
|
2017-09-04 22:08:59 +02:00
|
|
|
#include "debug.h"
|
2018-03-31 12:30:43 +02:00
|
|
|
#include "inventorymanager.h"
|
|
|
|
#include "lua_api/l_inventory.h"
|
|
|
|
#include "lua_api/l_item.h"
|
2013-12-12 07:51:35 +01:00
|
|
|
#include "util/string.h"
|
2013-05-25 00:51:02 +02:00
|
|
|
|
|
|
|
void ScriptApiPlayer::on_newplayer(ServerActiveObject *player)
|
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
2014-04-28 03:02:48 +02:00
|
|
|
// Get core.registered_on_newplayers
|
|
|
|
lua_getglobal(L, "core");
|
2013-05-25 00:51:02 +02:00
|
|
|
lua_getfield(L, -1, "registered_on_newplayers");
|
|
|
|
// Call callbacks
|
2014-10-02 21:58:13 +02:00
|
|
|
objectrefGetOrCreate(L, player);
|
2015-08-12 04:27:54 +02:00
|
|
|
runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
|
2013-05-25 00:51:02 +02:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:05:18 +02:00
|
|
|
void ScriptApiPlayer::on_dieplayer(ServerActiveObject *player, const PlayerHPChangeReason &reason)
|
2013-05-25 00:51:02 +02:00
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
2018-03-28 17:05:18 +02:00
|
|
|
// Get callback table
|
2014-04-28 03:02:48 +02:00
|
|
|
lua_getglobal(L, "core");
|
2013-05-25 00:51:02 +02:00
|
|
|
lua_getfield(L, -1, "registered_on_dieplayers");
|
2018-03-28 17:05:18 +02:00
|
|
|
|
|
|
|
// Push arguments
|
2014-10-02 21:58:13 +02:00
|
|
|
objectrefGetOrCreate(L, player);
|
2018-03-28 17:05:18 +02:00
|
|
|
pushPlayerHPChangeReason(L, reason);
|
|
|
|
|
|
|
|
// Run callbacks
|
|
|
|
runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
|
2013-05-25 00:51:02 +02:00
|
|
|
}
|
|
|
|
|
2014-05-17 06:47:12 +02:00
|
|
|
bool ScriptApiPlayer::on_punchplayer(ServerActiveObject *player,
|
|
|
|
ServerActiveObject *hitter,
|
|
|
|
float time_from_last_punch,
|
|
|
|
const ToolCapabilities *toolcap,
|
|
|
|
v3f dir,
|
|
|
|
s16 damage)
|
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
// Get core.registered_on_punchplayers
|
|
|
|
lua_getglobal(L, "core");
|
|
|
|
lua_getfield(L, -1, "registered_on_punchplayers");
|
|
|
|
// Call callbacks
|
|
|
|
objectrefGetOrCreate(L, player);
|
|
|
|
objectrefGetOrCreate(L, hitter);
|
|
|
|
lua_pushnumber(L, time_from_last_punch);
|
|
|
|
push_tool_capabilities(L, *toolcap);
|
|
|
|
push_v3f(L, dir);
|
|
|
|
lua_pushnumber(L, damage);
|
2015-08-12 04:27:54 +02:00
|
|
|
runCallbacks(6, RUN_CALLBACKS_MODE_OR);
|
2018-06-30 17:11:38 +02:00
|
|
|
return readParam<bool>(L, -1);
|
2014-05-17 06:47:12 +02:00
|
|
|
}
|
|
|
|
|
2021-01-11 18:03:31 +01:00
|
|
|
void ScriptApiPlayer::on_rightclickplayer(ServerActiveObject *player,
|
|
|
|
ServerActiveObject *clicker)
|
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
// Get core.registered_on_rightclickplayers
|
|
|
|
lua_getglobal(L, "core");
|
|
|
|
lua_getfield(L, -1, "registered_on_rightclickplayers");
|
|
|
|
// Call callbacks
|
|
|
|
objectrefGetOrCreate(L, player);
|
|
|
|
objectrefGetOrCreate(L, clicker);
|
|
|
|
runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
|
|
|
|
}
|
|
|
|
|
2019-02-11 00:03:26 +01:00
|
|
|
s32 ScriptApiPlayer::on_player_hpchange(ServerActiveObject *player,
|
|
|
|
s32 hp_change, const PlayerHPChangeReason &reason)
|
2015-05-30 16:56:42 +02:00
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
2015-08-25 07:44:53 +02:00
|
|
|
int error_handler = PUSH_ERROR_HANDLER(L);
|
|
|
|
|
2015-05-30 16:56:42 +02:00
|
|
|
// Get core.registered_on_player_hpchange
|
|
|
|
lua_getglobal(L, "core");
|
|
|
|
lua_getfield(L, -1, "registered_on_player_hpchange");
|
|
|
|
lua_remove(L, -2);
|
|
|
|
|
2018-03-28 17:05:18 +02:00
|
|
|
// Push arguments
|
2015-05-30 16:56:42 +02:00
|
|
|
objectrefGetOrCreate(L, player);
|
|
|
|
lua_pushnumber(L, hp_change);
|
2018-03-28 17:05:18 +02:00
|
|
|
pushPlayerHPChangeReason(L, reason);
|
|
|
|
|
|
|
|
// Call callbacks
|
|
|
|
PCALL_RES(lua_pcall(L, 3, 1, error_handler));
|
2015-05-30 16:56:42 +02:00
|
|
|
hp_change = lua_tointeger(L, -1);
|
2015-08-25 07:44:53 +02:00
|
|
|
lua_pop(L, 2); // Pop result and error handler
|
2015-05-30 16:56:42 +02:00
|
|
|
return hp_change;
|
|
|
|
}
|
|
|
|
|
2013-05-25 00:51:02 +02:00
|
|
|
bool ScriptApiPlayer::on_respawnplayer(ServerActiveObject *player)
|
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
2014-04-28 03:02:48 +02:00
|
|
|
// Get core.registered_on_respawnplayers
|
|
|
|
lua_getglobal(L, "core");
|
2013-05-25 00:51:02 +02:00
|
|
|
lua_getfield(L, -1, "registered_on_respawnplayers");
|
|
|
|
// Call callbacks
|
2014-10-02 21:58:13 +02:00
|
|
|
objectrefGetOrCreate(L, player);
|
2015-08-12 04:27:54 +02:00
|
|
|
runCallbacks(1, RUN_CALLBACKS_MODE_OR);
|
2018-06-30 17:11:38 +02:00
|
|
|
return readParam<bool>(L, -1);
|
2013-05-25 00:51:02 +02:00
|
|
|
}
|
|
|
|
|
2015-05-19 08:24:14 +02:00
|
|
|
bool ScriptApiPlayer::on_prejoinplayer(
|
|
|
|
const std::string &name,
|
|
|
|
const std::string &ip,
|
|
|
|
std::string *reason)
|
2013-12-12 07:51:35 +01:00
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
2014-04-28 03:02:48 +02:00
|
|
|
// Get core.registered_on_prejoinplayers
|
|
|
|
lua_getglobal(L, "core");
|
2013-12-12 07:51:35 +01:00
|
|
|
lua_getfield(L, -1, "registered_on_prejoinplayers");
|
|
|
|
lua_pushstring(L, name.c_str());
|
|
|
|
lua_pushstring(L, ip.c_str());
|
2015-08-12 04:27:54 +02:00
|
|
|
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
|
2013-12-12 07:51:35 +01:00
|
|
|
if (lua_isstring(L, -1)) {
|
2018-06-30 17:11:38 +02:00
|
|
|
reason->assign(readParam<std::string>(L, -1));
|
2013-12-12 07:51:35 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-04 22:08:59 +02:00
|
|
|
bool ScriptApiPlayer::can_bypass_userlimit(const std::string &name, const std::string &ip)
|
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
|
|
|
// Get core.registered_on_prejoinplayers
|
|
|
|
lua_getglobal(L, "core");
|
|
|
|
lua_getfield(L, -1, "registered_can_bypass_userlimit");
|
|
|
|
lua_pushstring(L, name.c_str());
|
|
|
|
lua_pushstring(L, ip.c_str());
|
|
|
|
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
|
|
|
|
return lua_toboolean(L, -1);
|
|
|
|
}
|
|
|
|
|
2020-05-23 13:24:06 +02:00
|
|
|
void ScriptApiPlayer::on_joinplayer(ServerActiveObject *player, s64 last_login)
|
2013-05-25 00:51:02 +02:00
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
2014-04-28 03:02:48 +02:00
|
|
|
// Get core.registered_on_joinplayers
|
|
|
|
lua_getglobal(L, "core");
|
2013-05-25 00:51:02 +02:00
|
|
|
lua_getfield(L, -1, "registered_on_joinplayers");
|
|
|
|
// Call callbacks
|
2014-10-02 21:58:13 +02:00
|
|
|
objectrefGetOrCreate(L, player);
|
2020-05-23 13:24:06 +02:00
|
|
|
if (last_login != -1)
|
|
|
|
lua_pushinteger(L, last_login);
|
|
|
|
else
|
|
|
|
lua_pushnil(L);
|
|
|
|
runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
|
2013-05-25 00:51:02 +02:00
|
|
|
}
|
|
|
|
|
2016-01-05 02:49:11 +01:00
|
|
|
void ScriptApiPlayer::on_leaveplayer(ServerActiveObject *player,
|
|
|
|
bool timeout)
|
2013-05-25 00:51:02 +02:00
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
2014-04-28 03:02:48 +02:00
|
|
|
// Get core.registered_on_leaveplayers
|
|
|
|
lua_getglobal(L, "core");
|
2013-05-25 00:51:02 +02:00
|
|
|
lua_getfield(L, -1, "registered_on_leaveplayers");
|
|
|
|
// Call callbacks
|
2014-10-02 21:58:13 +02:00
|
|
|
objectrefGetOrCreate(L, player);
|
2016-01-05 02:49:11 +01:00
|
|
|
lua_pushboolean(L, timeout);
|
|
|
|
runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
|
2013-05-25 00:51:02 +02:00
|
|
|
}
|
|
|
|
|
2013-08-03 23:45:49 +02:00
|
|
|
void ScriptApiPlayer::on_cheat(ServerActiveObject *player,
|
|
|
|
const std::string &cheat_type)
|
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
2014-04-28 03:02:48 +02:00
|
|
|
// Get core.registered_on_cheats
|
|
|
|
lua_getglobal(L, "core");
|
2013-08-03 23:45:49 +02:00
|
|
|
lua_getfield(L, -1, "registered_on_cheats");
|
|
|
|
// Call callbacks
|
2014-10-02 21:58:13 +02:00
|
|
|
objectrefGetOrCreate(L, player);
|
2013-08-03 23:45:49 +02:00
|
|
|
lua_newtable(L);
|
|
|
|
lua_pushlstring(L, cheat_type.c_str(), cheat_type.size());
|
|
|
|
lua_setfield(L, -2, "type");
|
2015-08-12 04:27:54 +02:00
|
|
|
runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
|
2013-08-03 23:45:49 +02:00
|
|
|
}
|
|
|
|
|
2013-05-25 00:51:02 +02:00
|
|
|
void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player,
|
|
|
|
const std::string &formname,
|
2015-05-19 08:24:14 +02:00
|
|
|
const StringMap &fields)
|
2013-05-25 00:51:02 +02:00
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
2019-01-06 17:21:04 +01:00
|
|
|
// Get core.registered_on_player_receive_fields
|
2014-04-28 03:02:48 +02:00
|
|
|
lua_getglobal(L, "core");
|
2013-05-25 00:51:02 +02:00
|
|
|
lua_getfield(L, -1, "registered_on_player_receive_fields");
|
|
|
|
// Call callbacks
|
|
|
|
// param 1
|
2014-10-02 21:58:13 +02:00
|
|
|
objectrefGetOrCreate(L, player);
|
2013-05-25 00:51:02 +02:00
|
|
|
// param 2
|
|
|
|
lua_pushstring(L, formname.c_str());
|
|
|
|
// param 3
|
|
|
|
lua_newtable(L);
|
2015-05-19 08:24:14 +02:00
|
|
|
StringMap::const_iterator it;
|
|
|
|
for (it = fields.begin(); it != fields.end(); ++it) {
|
|
|
|
const std::string &name = it->first;
|
|
|
|
const std::string &value = it->second;
|
2013-05-25 00:51:02 +02:00
|
|
|
lua_pushstring(L, name.c_str());
|
|
|
|
lua_pushlstring(L, value.c_str(), value.size());
|
|
|
|
lua_settable(L, -3);
|
|
|
|
}
|
2015-08-12 04:27:54 +02:00
|
|
|
runCallbacks(3, RUN_CALLBACKS_MODE_OR_SC);
|
2013-05-25 00:51:02 +02:00
|
|
|
}
|
2015-05-19 08:24:14 +02:00
|
|
|
|
2020-05-23 13:24:06 +02:00
|
|
|
void ScriptApiPlayer::on_authplayer(const std::string &name, const std::string &ip, bool is_success)
|
2018-02-15 21:18:54 +01:00
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
2020-05-23 13:24:06 +02:00
|
|
|
// Get core.registered_on_authplayers
|
2018-02-15 21:18:54 +01:00
|
|
|
lua_getglobal(L, "core");
|
2020-05-23 13:24:06 +02:00
|
|
|
lua_getfield(L, -1, "registered_on_authplayers");
|
|
|
|
|
|
|
|
// Call callbacks
|
2018-02-15 21:18:54 +01:00
|
|
|
lua_pushstring(L, name.c_str());
|
|
|
|
lua_pushstring(L, ip.c_str());
|
2020-05-23 13:24:06 +02:00
|
|
|
lua_pushboolean(L, is_success);
|
|
|
|
runCallbacks(3, RUN_CALLBACKS_MODE_FIRST);
|
2018-02-15 21:18:54 +01:00
|
|
|
}
|
2018-03-31 12:30:43 +02:00
|
|
|
|
|
|
|
void ScriptApiPlayer::pushMoveArguments(
|
2018-03-31 13:47:19 +02:00
|
|
|
const MoveAction &ma, int count,
|
|
|
|
ServerActiveObject *player)
|
2018-03-31 12:30:43 +02:00
|
|
|
{
|
|
|
|
lua_State *L = getStack();
|
|
|
|
objectrefGetOrCreate(L, player); // player
|
|
|
|
lua_pushstring(L, "move"); // action
|
2018-03-31 13:47:19 +02:00
|
|
|
InvRef::create(L, ma.from_inv); // inventory
|
2018-03-31 12:30:43 +02:00
|
|
|
lua_newtable(L);
|
|
|
|
{
|
|
|
|
// Table containing the action information
|
2018-03-31 13:47:19 +02:00
|
|
|
lua_pushstring(L, ma.from_list.c_str());
|
2018-03-31 12:30:43 +02:00
|
|
|
lua_setfield(L, -2, "from_list");
|
2018-03-31 13:47:19 +02:00
|
|
|
lua_pushstring(L, ma.to_list.c_str());
|
2018-03-31 12:30:43 +02:00
|
|
|
lua_setfield(L, -2, "to_list");
|
|
|
|
|
2018-03-31 13:47:19 +02:00
|
|
|
lua_pushinteger(L, ma.from_i + 1);
|
2018-03-31 12:30:43 +02:00
|
|
|
lua_setfield(L, -2, "from_index");
|
2018-03-31 13:47:19 +02:00
|
|
|
lua_pushinteger(L, ma.to_i + 1);
|
2018-03-31 12:30:43 +02:00
|
|
|
lua_setfield(L, -2, "to_index");
|
|
|
|
|
|
|
|
lua_pushinteger(L, count);
|
|
|
|
lua_setfield(L, -2, "count");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptApiPlayer::pushPutTakeArguments(
|
|
|
|
const char *method, const InventoryLocation &loc,
|
|
|
|
const std::string &listname, int index, const ItemStack &stack,
|
|
|
|
ServerActiveObject *player)
|
|
|
|
{
|
|
|
|
lua_State *L = getStack();
|
|
|
|
objectrefGetOrCreate(L, player); // player
|
|
|
|
lua_pushstring(L, method); // action
|
|
|
|
InvRef::create(L, loc); // inventory
|
|
|
|
lua_newtable(L);
|
|
|
|
{
|
|
|
|
// Table containing the action information
|
|
|
|
lua_pushstring(L, listname.c_str());
|
|
|
|
lua_setfield(L, -2, "listname");
|
|
|
|
|
|
|
|
lua_pushinteger(L, index + 1);
|
|
|
|
lua_setfield(L, -2, "index");
|
|
|
|
|
|
|
|
LuaItemStack::create(L, stack);
|
|
|
|
lua_setfield(L, -2, "stack");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return number of accepted items to be moved
|
|
|
|
int ScriptApiPlayer::player_inventory_AllowMove(
|
2018-03-31 13:47:19 +02:00
|
|
|
const MoveAction &ma, int count,
|
|
|
|
ServerActiveObject *player)
|
2018-03-31 12:30:43 +02:00
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
|
|
|
lua_getglobal(L, "core");
|
|
|
|
lua_getfield(L, -1, "registered_allow_player_inventory_actions");
|
2018-03-31 13:47:19 +02:00
|
|
|
pushMoveArguments(ma, count, player);
|
2018-03-31 12:30:43 +02:00
|
|
|
runCallbacks(4, RUN_CALLBACKS_MODE_OR_SC);
|
|
|
|
|
|
|
|
return lua_type(L, -1) == LUA_TNUMBER ? lua_tonumber(L, -1) : count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return number of accepted items to be put
|
|
|
|
int ScriptApiPlayer::player_inventory_AllowPut(
|
2018-03-31 13:47:19 +02:00
|
|
|
const MoveAction &ma, const ItemStack &stack,
|
2018-03-31 12:30:43 +02:00
|
|
|
ServerActiveObject *player)
|
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
|
|
|
lua_getglobal(L, "core");
|
|
|
|
lua_getfield(L, -1, "registered_allow_player_inventory_actions");
|
2018-03-31 13:47:19 +02:00
|
|
|
pushPutTakeArguments("put", ma.to_inv, ma.to_list, ma.to_i, stack, player);
|
2018-03-31 12:30:43 +02:00
|
|
|
runCallbacks(4, RUN_CALLBACKS_MODE_OR_SC);
|
|
|
|
|
|
|
|
return lua_type(L, -1) == LUA_TNUMBER ? lua_tonumber(L, -1) : stack.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return number of accepted items to be taken
|
|
|
|
int ScriptApiPlayer::player_inventory_AllowTake(
|
2018-03-31 13:47:19 +02:00
|
|
|
const MoveAction &ma, const ItemStack &stack,
|
2018-03-31 12:30:43 +02:00
|
|
|
ServerActiveObject *player)
|
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
|
|
|
lua_getglobal(L, "core");
|
|
|
|
lua_getfield(L, -1, "registered_allow_player_inventory_actions");
|
2018-03-31 13:47:19 +02:00
|
|
|
pushPutTakeArguments("take", ma.from_inv, ma.from_list, ma.from_i, stack, player);
|
2018-03-31 12:30:43 +02:00
|
|
|
runCallbacks(4, RUN_CALLBACKS_MODE_OR_SC);
|
|
|
|
|
|
|
|
return lua_type(L, -1) == LUA_TNUMBER ? lua_tonumber(L, -1) : stack.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report moved items
|
|
|
|
void ScriptApiPlayer::player_inventory_OnMove(
|
2018-03-31 13:47:19 +02:00
|
|
|
const MoveAction &ma, int count,
|
|
|
|
ServerActiveObject *player)
|
2018-03-31 12:30:43 +02:00
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
|
|
|
lua_getglobal(L, "core");
|
|
|
|
lua_getfield(L, -1, "registered_on_player_inventory_actions");
|
2018-03-31 13:47:19 +02:00
|
|
|
pushMoveArguments(ma, count, player);
|
2018-03-31 12:30:43 +02:00
|
|
|
runCallbacks(4, RUN_CALLBACKS_MODE_FIRST);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report put items
|
|
|
|
void ScriptApiPlayer::player_inventory_OnPut(
|
2018-03-31 13:47:19 +02:00
|
|
|
const MoveAction &ma, const ItemStack &stack,
|
2018-03-31 12:30:43 +02:00
|
|
|
ServerActiveObject *player)
|
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
|
|
|
lua_getglobal(L, "core");
|
|
|
|
lua_getfield(L, -1, "registered_on_player_inventory_actions");
|
2018-03-31 13:47:19 +02:00
|
|
|
pushPutTakeArguments("put", ma.to_inv, ma.to_list, ma.to_i, stack, player);
|
2018-03-31 12:30:43 +02:00
|
|
|
runCallbacks(4, RUN_CALLBACKS_MODE_FIRST);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report taken items
|
|
|
|
void ScriptApiPlayer::player_inventory_OnTake(
|
2018-03-31 13:47:19 +02:00
|
|
|
const MoveAction &ma, const ItemStack &stack,
|
2018-03-31 12:30:43 +02:00
|
|
|
ServerActiveObject *player)
|
|
|
|
{
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
|
|
|
lua_getglobal(L, "core");
|
|
|
|
lua_getfield(L, -1, "registered_on_player_inventory_actions");
|
2018-03-31 13:47:19 +02:00
|
|
|
pushPutTakeArguments("take", ma.from_inv, ma.from_list, ma.from_i, stack, player);
|
2018-03-31 12:30:43 +02:00
|
|
|
runCallbacks(4, RUN_CALLBACKS_MODE_FIRST);
|
|
|
|
}
|