Working on location exterior

This commit is contained in:
Vladislav Khorev committed 2026-05-21 20:30:49 +03:00
1 parent 3a73f3fbde
commit ffd5bd01a4
35 files changed
+72176 -124

No files matched your search

+55
View File
@@ -16,6 +16,8 @@ namespace ZL {
std::unordered_map<std::string, sol::protected_function> triggerEnterCallbacks;
std::unordered_map<std::string, sol::protected_function> triggerExitCallbacks;
std::unordered_map<std::string, sol::protected_function> cutsceneCompleteCallbacks;
std::unordered_map<int, sol::protected_function> npcBumpedByPlayerCallbacks;
std::unordered_map<int, sol::protected_function> npcBumpsPlayerCallbacks;
std::unordered_map<std::string, int>* globalInts = nullptr;
std::unordered_map<std::string, float>* globalFloats = nullptr;
sol::protected_function locationEnterCallback;
@@ -458,6 +460,37 @@ namespace ZL {
std::cerr << "[script] scale_object: object '" << name << "' not found\n";
});
// player_stop() — cancels the player's current walk target and stops them immediately.
api.set_function("player_stop",
[game]() {
if (game->player) game->player->stopInPlace();
});
// npc_stop(index) — cancels an NPC's current walk target and stops them immediately.
api.set_function("npc_stop",
[game](int index) {
auto& npcs = game->npcs;
if (index < 0 || index >= static_cast<int>(npcs.size())) {
std::cerr << "[script] npc_stop: index " << index
<< " out of range (0.." << npcs.size() - 1 << ")\n";
return;
}
npcs[index]->stopInPlace();
});
// set_npc_bump_callbacks(npc_index, on_player_bumps_npc, on_npc_bumps_player)
// Both callbacks are optional (pass nil to omit).
// on_player_bumps_npc() — player was moving and walked into the NPC.
// on_npc_bumps_player() — the NPC was moving and walked into the standing player.
// Each callback fires at most once every 5 seconds per NPC (cooldown managed by Location).
api.set_function("set_npc_bump_callbacks",
[this_impl = impl.get()](int index, sol::object onPlayerBumpsNpc, sol::object onNpcBumpsPlayer) {
if (onPlayerBumpsNpc.is<sol::protected_function>())
this_impl->npcBumpedByPlayerCallbacks[index] = onPlayerBumpsNpc.as<sol::protected_function>();
if (onNpcBumpsPlayer.is<sol::protected_function>())
this_impl->npcBumpsPlayerCallbacks[index] = onNpcBumpsPlayer.as<sol::protected_function>();
});
lua.script_file(scriptPath);
}
@@ -625,4 +658,26 @@ namespace ZL {
}
}
void ScriptEngine::callNpcBumpedByPlayerCallback(int npcIndex) {
if (!impl) return;
auto it = impl->npcBumpedByPlayerCallbacks.find(npcIndex);
if (it == impl->npcBumpedByPlayerCallbacks.end()) return;
auto result = it->second();
if (!result.valid()) {
sol::error err = result;
std::cerr << "[SCRIPT] on_player_bumps_npc error for NPC " << npcIndex << ": " << err.what() << "\n";
}
}
void ScriptEngine::callNpcBumpsPlayerCallback(int npcIndex) {
if (!impl) return;
auto it = impl->npcBumpsPlayerCallbacks.find(npcIndex);
if (it == impl->npcBumpsPlayerCallbacks.end()) return;
auto result = it->second();
if (!result.valid()) {
sol::error err = result;
std::cerr << "[SCRIPT] on_npc_bumps_player error for NPC " << npcIndex << ": " << err.what() << "\n";
}
}
} // namespace ZL