local clientpath = scriptpath.."client"..DIR_DELIM
dofile(clientpath .. "register.lua")
+dofile(clientpath .. "preview.lua")
--- This is an example function to ensure it's working properly, should be removed before merge
-core.register_on_shutdown(function()
- print("shutdown client")
+core.register_on_death(function()
+ core.display_chat_message("You died.")
end)
--- This is an example function to ensure it's working properly, should be removed before merge
-core.register_on_receiving_chat_messages(function(message)
- print("Received message " .. message)
- return false
-end)
-
--- This is an example function to ensure it's working properly, should be removed before merge
-core.register_on_sending_chat_messages(function(message)
- print("Sending message " .. message)
- return false
-end)
--- /dev/null
+-- This is an example function to ensure it's working properly, should be removed before merge
+core.register_on_shutdown(function()
+ print("shutdown client")
+end)
+
+-- This is an example function to ensure it's working properly, should be removed before merge
+core.register_on_receiving_chat_messages(function(message)
+ print("[PREVIEW] Received message " .. message)
+ return false
+end)
+
+-- This is an example function to ensure it's working properly, should be removed before merge
+core.register_on_sending_chat_messages(function(message)
+ print("[PREVIEW] Sending message " .. message)
+ return false
+end)
+
+core.register_on_hp_modification(function(hp)
+ print("[PREVIEW] HP modified " .. hp)
+end)
+
+core.register_on_damage_taken(function(hp)
+ print("[PREVIEW] Damage taken " .. hp)
+end)
core.registered_on_shutdown, core.register_on_shutdown = make_registration()
core.registered_on_receiving_chat_messages, core.register_on_receiving_chat_messages = make_registration()
core.registered_on_sending_chat_messages, core.register_on_sending_chat_messages = make_registration()
+core.registered_on_death, core.register_on_death = make_registration()
+core.registered_on_hp_modification, core.register_on_hp_modification = make_registration()
+core.registered_on_damage_taken, core.register_on_damage_taken = make_registration()
m_chat_queue.push(input);
}
+ ClientScripting *getScript() { return m_script; }
+
private:
// Virtual methods from con::PeerHandler
#include "guiKeyChangeMenu.h"
#include "guiPasswordChange.h"
#include "guiVolumeChange.h"
-#include "hud.h"
#include "mainmenumanager.h"
#include "mapblock.h"
#include "nodedef.h" // Needed for determining pointing to nodes
#include "version.h"
#include "minimap.h"
#include "mapblock_mesh.h"
+#include "script/clientscripting.h"
#include "sound.h"
if (event.type == CE_PLAYER_DAMAGE &&
client->getHP() != 0) {
- //u16 damage = event.player_damage.amount;
- //infostream<<"Player damage: "<<damage<<std::endl;
+ client->getScript()->on_damage_taken(event.player_damage.amount);
*damage_flash += 95.0 + 3.2 * event.player_damage.amount;
*damage_flash = MYMIN(*damage_flash, 127.0);
show_deathscreen(¤t_formspec, client, texture_src,
device, &input->joystick);
- chat_backend->addMessage(L"", L"You died.");
+ client->getScript()->on_death();
/* Handle visualization */
*damage_flash = 0;
player->hp = hp;
+ m_script->on_hp_modification(hp);
+
if (hp < oldhp) {
// Add to ClientEvent queue
ClientEvent event;
bool ate = lua_toboolean(L, -1);
return ate;
}
+
+void ScriptApiClient::on_damage_taken(int32_t damage_amount)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ // Get core.registered_on_chat_messages
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "registered_on_damage_taken");
+ // Call callbacks
+ lua_pushinteger(L, damage_amount);
+ runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
+}
+
+void ScriptApiClient::on_hp_modification(int32_t newhp)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ // Get core.registered_on_chat_messages
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "registered_on_hp_modification");
+ // Call callbacks
+ lua_pushinteger(L, newhp);
+ runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
+}
+
+void ScriptApiClient::on_death()
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ // Get registered shutdown hooks
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "registered_on_death");
+ // Call callbacks
+ runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
+}
// Chat message handlers
bool on_sending_message(const std::string &message);
bool on_receiving_message(const std::string &message);
+
+ void on_damage_taken(int32_t damage_amount);
+ void on_hp_modification(int32_t newhp);
+ void on_death();
};
#endif