Consumer recipes
Short patterns for common requests. Each assumes a connected rock::api::Client client (see first consumer) and runs on the game thread, for example in a Core frame callback or an Animation phase callback. namespace api = rock::api;.
Keep a hand out of ROCK's grabbing
A suppression lease lasts a few frames; renew it every frame you need it, from an Animation BeforeRock callback. Input bound with Write.
void renewLeftHandSuppression(const api::input::Api* input) {
api::input::HandInputSuppressionRequest request{};
request.hand = api::Hand::Left;
request.flags = static_cast<std::uint32_t>(api::input::HandInputSuppressionFlag::SuppressNormalGrabPress);
request.leaseFrames = 2;
input->setHandInputSuppression(client.owner(), &request); // stop renewing, or clear, to end it
}
Zero generation fields skip the generation check; nonzero ones must match the current sample.
Grab a reference into a hand
Grab bound with Read | Write. The request queues; poll its result on later frames.
std::uint64_t grabCommand{};
api::Status startGrab(const api::grab::Api* grab, std::uint32_t referenceFormId, const api::Sample& sample) {
api::grab::ForceGrabRequest request{};
request.hand = api::Hand::Right;
request.targetFormId = referenceFormId;
request.worldGeneration = sample.worldGeneration;
request.skeletonGeneration = sample.skeletonGeneration;
request.providerGeneration = sample.providerGeneration;
return grab->requestForceGrab(client.owner(), &request, &grabCommand); // RequestQueued is admission
}
bool grabFinished(const api::grab::Api* grab, bool& succeeded) {
api::grab::InteractionCommandResult result{};
if (grab->getInteractionCommandResult(client.owner(), grabCommand, &result) != api::Status::Ok) return false;
if (result.state == api::grab::InteractionCommandState::Queued) return false;
succeeded = result.state == api::grab::InteractionCommandState::Succeeded; // else read result.failure
return true;
}
Equip an inventory weapon into a hand
Weapon bound with Read | Write. Capture the stack immediately before the request.
std::uint64_t equipCommand{};
api::Status equipIntoLeftHand(const api::weapon::Api* weapon, std::uint32_t baseFormId, std::uint32_t stackIndex) {
api::weapon::EquipRequest request{};
request.hand = api::Hand::Left;
auto status = weapon->captureInventoryWeapon(client.owner(), baseFormId, stackIndex, &request.item);
if (status != api::Status::Ok) return status;
return weapon->requestInventoryEquip(client.owner(), &request, &equipCommand);
}
bool equipFinished(const api::weapon::Api* weapon, api::weapon::EquipResult& result) {
result = {};
if (weapon->getInventoryEquipResult(client.owner(), equipCommand, &result) != api::Status::Ok) return false;
return result.state != api::weapon::EquipState::Queued && result.state != api::weapon::EquipState::Switching;
}
result.weaponSlot is the slot the weapon went to; outgoingFormId names a weapon it replaced. Inspect flags even when the switch fails.
Follow what a hand holds
Grab getHandInteractionState may be read from any thread. Act on changes by comparing its sequences with the last values you saw.
std::uint64_t lastState{};
void pollRightHand(const api::grab::Api* grab) {
api::grab::HandInteractionState state{};
if (grab->getHandInteractionState(client.owner(), api::Hand::Right, &state) != api::Status::Ok) return;
if (state.stateSequence == lastState) return;
lastState = state.stateSequence;
// state.phase, state.flags and state.targetFormId describe the new state
}
For the exact records, flags and limits, see the API index.