Added more scripts
This commit is contained in:
1 parent
63c9d7b35b
commit
403b93e7f5
5 files changed
+47
-13
No files matched your search
+18
-5
@@ -14,9 +14,11 @@ static ZL::Game* s_game = nullptr;
|
||||
PYBIND11_EMBEDDED_MODULE(game_api, m) {
|
||||
m.doc() = "Game scripting API";
|
||||
|
||||
// npc_walk_to(index, x, y, z)
|
||||
// Tells the NPC at `index` in Game::npcs to walk to world position (x,y,z).
|
||||
m.def("npc_walk_to", [](int index, float x, float y, float z) {
|
||||
// npc_walk_to(index, x, y, z, on_arrived=None)
|
||||
// Tells the NPC at `index` to walk to (x,y,z).
|
||||
// on_arrived is an optional Python callable invoked once when the NPC arrives.
|
||||
// It can call npc_walk_to again (or anything else) to chain behaviour.
|
||||
m.def("npc_walk_to", [](int index, float x, float y, float z, py::object on_arrived) {
|
||||
if (!s_game) {
|
||||
std::cerr << "[script] game_api.npc_walk_to: engine not ready\n";
|
||||
return;
|
||||
@@ -27,10 +29,21 @@ PYBIND11_EMBEDDED_MODULE(game_api, m) {
|
||||
<< " out of range (0.." << npcs.size() - 1 << ")\n";
|
||||
return;
|
||||
}
|
||||
npcs[index]->setTarget(Eigen::Vector3f(x, y, z));
|
||||
std::function<void()> cb;
|
||||
if (!on_arrived.is_none()) {
|
||||
cb = [on_arrived]() {
|
||||
try {
|
||||
on_arrived();
|
||||
} catch (const py::error_already_set& e) {
|
||||
std::cerr << "[script] on_arrived callback error:\n" << e.what() << "\n";
|
||||
}
|
||||
};
|
||||
}
|
||||
npcs[index]->setTarget(Eigen::Vector3f(x, y, z), std::move(cb));
|
||||
},
|
||||
py::arg("index"), py::arg("x"), py::arg("y"), py::arg("z"),
|
||||
"Command NPC[index] to walk to world position (x, y, z).");
|
||||
py::arg("on_arrived") = py::none(),
|
||||
"Command NPC[index] to walk to (x,y,z). on_arrived is called when the NPC arrives.");
|
||||
}
|
||||
|
||||
namespace ZL {
|
||||
|
||||
Reference in new issue
Block a user