// native ArraySwap(Array:which, item1, item2); static cell AMX_NATIVE_CALL ArraySwap(AMX* amx, cell* params) { CellArray* vec = ArrayHandles.lookup(params[1]); if (!vec) { LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]); return 0; } size_t idx1 = (size_t)params[2]; size_t idx2 = (size_t)params[3]; if (idx1 >= vec->size()) { LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx1, vec->size()); return 0; } if (idx2 >= vec->size()) { LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx2, vec->size()); return 0; } vec->swap(idx1, idx2); return 1; }
static cell_t SwapArrayItems(IPluginContext *pContext, const cell_t *params) { CellArray *array; HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); } size_t idx1 = (size_t)params[2]; size_t idx2 = (size_t)params[3]; if (idx1 >= array->size()) { return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx1, array->size()); } if (idx2 >= array->size()) { return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx2, array->size()); } array->swap(idx1, idx2); return 1; }
// native ArraySwap(Array:which, item1, item2); static cell AMX_NATIVE_CALL ArraySwap(AMX* amx, cell* params) { CellArray* vec = HandleToVector(amx, params[1]); if (vec == NULL) { return 0; } size_t idx1 = (size_t)params[2]; size_t idx2 = (size_t)params[3]; if (idx1 >= vec->size()) { LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx1, vec->size()); return 0; } if (idx2 >= vec->size()) { LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx2, vec->size()); return 0; } vec->swap(idx1, idx2); return 1; }