void ScriptApiEnv::environment_OnMapgenInit(MapgenParams *mgparams) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_mapgen_inits lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_mapgen_inits"); // Call callbacks lua_newtable(L); lua_pushstring(L, mgparams->mg_name.c_str()); lua_setfield(L, -2, "mgname"); lua_pushinteger(L, mgparams->seed); lua_setfield(L, -2, "seed"); lua_pushinteger(L, mgparams->water_level); lua_setfield(L, -2, "water_level"); std::string flagstr = writeFlagString(mgparams->flags, flagdesc_mapgen, (u32)-1); lua_pushstring(L, flagstr.c_str()); lua_setfield(L, -2, "flags"); script_run_callbacks(L, 1, RUN_CALLBACKS_MODE_FIRST); }
void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player, const std::string &formname, const StringMap &fields) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_chat_messages lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_player_receive_fields"); // Call callbacks // param 1 objectrefGetOrCreate(L, player); // param 2 lua_pushstring(L, formname.c_str()); // param 3 lua_newtable(L); StringMap::const_iterator it; for (it = fields.begin(); it != fields.end(); ++it) { const std::string &name = it->first; const std::string &value = it->second; lua_pushstring(L, name.c_str()); lua_pushlstring(L, value.c_str(), value.size()); lua_settable(L, -3); } script_run_callbacks(L, 3, RUN_CALLBACKS_MODE_OR_SC); }
void ScriptApiPlayer::on_dieplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_dieplayers lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_dieplayers"); // Call callbacks objectrefGetOrCreate(L, player); script_run_callbacks(L, 1, RUN_CALLBACKS_MODE_FIRST); }
bool ScriptApiPlayer::on_respawnplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_respawnplayers lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_respawnplayers"); // Call callbacks objectrefGetOrCreate(L, player); script_run_callbacks(L, 1, RUN_CALLBACKS_MODE_OR); bool positioning_handled_by_some = lua_toboolean(L, -1); return positioning_handled_by_some; }
void ScriptApiEnv::environment_OnGenerated(v3s16 minp, v3s16 maxp, u32 blockseed) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_generateds lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_generateds"); // Call callbacks push_v3s16(L, minp); push_v3s16(L, maxp); lua_pushnumber(L, blockseed); script_run_callbacks(L, 3, RUN_CALLBACKS_MODE_FIRST); }
void ScriptApiPlayer::on_cheat(ServerActiveObject *player, const std::string &cheat_type) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_cheats lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_cheats"); // Call callbacks objectrefGetOrCreate(L, player); lua_newtable(L); lua_pushlstring(L, cheat_type.c_str(), cheat_type.size()); lua_setfield(L, -2, "type"); script_run_callbacks(L, 2, RUN_CALLBACKS_MODE_FIRST); }
bool ScriptApiPlayer::on_prejoinplayer(std::string name, std::string ip, std::string &reason) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_prejoinplayers lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_prejoinplayers"); lua_pushstring(L, name.c_str()); lua_pushstring(L, ip.c_str()); script_run_callbacks(L, 2, RUN_CALLBACKS_MODE_OR); if (lua_isstring(L, -1)) { reason.assign(lua_tostring(L, -1)); return true; } return false; }
void ScriptApiEnv::environment_Step(float dtime) { SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_environment_step"<<std::endl; // Get core.registered_globalsteps lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_globalsteps"); // Call callbacks lua_pushnumber(L, dtime); try { script_run_callbacks(L, 1, RUN_CALLBACKS_MODE_FIRST); } catch (LuaError &e) { getServer()->setAsyncFatalError(e.what()); } }
void ScriptApiEnv::player_event(ServerActiveObject* player, std::string type) { SCRIPTAPI_PRECHECKHEADER // Get minetest.registered_playerevents lua_getglobal(L, "minetest"); lua_getfield(L, -1, "registered_playerevents"); // Call callbacks objectrefGetOrCreate(player); // player lua_pushstring(L,type.c_str()); // event type try { script_run_callbacks(L, 2, RUN_CALLBACKS_MODE_FIRST); } catch (LuaError &e) { getServer()->setAsyncFatalError(e.what()); } }
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); script_run_callbacks(L, 6, RUN_CALLBACKS_MODE_OR); return lua_toboolean(L, -1); }