Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harden scripting wrapper #104

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions code/server/src/core/builtins/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
#include <sol/sol.hpp>

#include "integrations/server/scripting/builtins/node/entity.h"
#include "shared/modules/human_sync.hpp"
#include "scripting/server_engine.h"

namespace MafiaMP::Scripting {
class Vehicle;
class Human final: public Framework::Integrations::Scripting::Entity {
public:
Human(flecs::entity_t ent): Entity(ent) {}
Human(flecs::entity ent): Entity(ent) {}
Human(flecs::entity_t ent): Entity(ent) {
const auto humanData = _ent.get<Shared::Modules::HumanSync::UpdateData>();

if (!humanData) {
throw std::runtime_error(fmt::format("Entity handle '{}' is not a Human!", ent));
}
}

Human(flecs::entity ent): Human(ent.id()) {}

static void EventPlayerDied(flecs::entity e);
static void EventPlayerConnected(flecs::entity e);
Expand Down
11 changes: 9 additions & 2 deletions code/server/src/core/builtins/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@
namespace MafiaMP::Scripting {
class Vehicle final: public Framework::Integrations::Scripting::Entity {
public:
Vehicle(flecs::entity_t ent): Entity(ent) {}
Vehicle(flecs::entity ent): Entity(ent) {}
Vehicle(flecs::entity_t ent) : Entity(ent) {
const auto vehData = _ent.get<Shared::Modules::VehicleSync::UpdateData>();

if (!vehData) {
throw std::runtime_error(fmt::format("Entity handle '{}' is not a Vehicle!", ent));
}
}

Vehicle(flecs::entity ent): Vehicle(ent.id()) {}

static void EventVehiclePlayerEnter(flecs::entity vehicle, flecs::entity player, int seatIndex);
static void EventVehiclePlayerLeave(flecs::entity vehicle, flecs::entity player);
Expand Down
Loading