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

Method spawnVehicle

source/game/StarCommandProcessor.cpp:481–509  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

479}
480
481String CommandProcessor::spawnVehicle(ConnectionId connectionId, String const& argumentString) {
482 if (auto errorMsg = adminCheck(connectionId, "spawn vehicles"))
483 return *errorMsg;
484
485 try {
486 auto vehicleDatabase = Root::singleton().vehicleDatabase();
487 auto arguments = m_parser.tokenizeToStringList(argumentString);
488
489 VehiclePtr vehicle;
490
491 String name = arguments.at(0);
492
493 Json parameters = JsonObject();
494 if (arguments.size() >= 2)
495 parameters = Json::parse(arguments.at(1)).toObject();
496
497 vehicle = vehicleDatabase->create(name, parameters);
498 bool done = m_universe->executeForClient(connectionId,
499 [&](WorldServer* world, PlayerPtr const& player) {
500 vehicle->setPosition(player->aimPosition());
501 world->addEntity(std::move(vehicle));
502 });
503
504 return done ? "" : "Invalid client state";
505 } catch (StarException const& exception) {
506 Logger::warn("Could not spawn vehicle, exception caught: {}", outputException(exception, false));
507 return strf("Could not spawn vehicle");
508 }
509}
510
511String CommandProcessor::spawnStagehand(ConnectionId connectionId, String const& argumentString) {
512 if (auto errorMsg = adminCheck(connectionId, "spawn stagehands"))

Callers

nothing calls this directly

Calls 14

singletonClass · 0.85
strfFunction · 0.85
vehicleDatabaseMethod · 0.80
tokenizeToStringListMethod · 0.80
toObjectMethod · 0.80
executeForClientMethod · 0.80
parseFunction · 0.50
outputExceptionFunction · 0.50
atMethod · 0.45
sizeMethod · 0.45
createMethod · 0.45
setPositionMethod · 0.45

Tested by

no test coverage detected