MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / entityEval

Method entityEval

source/game/StarCommandProcessor.cpp:749–781  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

747}
748
749String CommandProcessor::entityEval(ConnectionId connectionId, String const& lua) {
750 if (auto errorMsg = localCheck(connectionId, "execute server entity script"))
751 return *errorMsg;
752
753 if (auto errorMsg = adminCheck(connectionId, "execute server entity script"))
754 return *errorMsg;
755
756 String message;
757 bool done = m_universe->executeForClient(connectionId,
758 [&lua, &message](WorldServer* world, PlayerPtr const& player) {
759 auto queryRect = RectF::withCenter(player->aimPosition(), Vec2F{2, 2});
760 auto entities = world->query<ScriptedEntity>(queryRect);
761 if (entities.empty()) {
762 message = "Could not find scripted entity at cursor";
763 return;
764 }
765
766 ScriptedEntityPtr targetEntity;
767 for (auto const& entity : entities) {
768 if (!targetEntity
769 || vmagSquared(entity->position() - player->aimPosition())
770 < vmagSquared(targetEntity->position() - player->aimPosition()))
771 targetEntity = entity;
772 }
773
774 if (auto res = targetEntity->evalScript(lua))
775 message = toString(*res);
776 else
777 message = "Error evaluating script in entity context, check log";
778 });
779
780 return done ? message : "failed to do entity eval";
781}
782
783String CommandProcessor::enableSpawning(ConnectionId connectionId, String const&) {
784 if (auto errorMsg = adminCheck(connectionId, "enable world spawning"))

Callers

nothing calls this directly

Calls 7

vmagSquaredFunction · 0.85
toStringFunction · 0.85
executeForClientMethod · 0.80
aimPositionMethod · 0.45
emptyMethod · 0.45
positionMethod · 0.45
evalScriptMethod · 0.45

Tested by

no test coverage detected