Last active
February 28, 2018 01:31
-
-
Save kabukki/66f19b9752a6725e625a81157a66edfa to your computer and use it in GitHub Desktop.
LUA script to scan Loud sky room collisions to CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---------------------------------------- | |
---------- Scan Loud Sky room ---------- | |
---------------------------------------- | |
-- Instructions: | |
-- . Change Coord descriptors | |
-- to match yours (X and Y might be swapped) | |
-- . Change output file directory | |
-- . Change scan settings | |
-- | |
-- made by @kabukki | |
---------------------------------------- | |
-- Room coordinates | |
X_MIN = 5035 | |
X_MAX = 7365 | |
Y_MIN = 31435 | |
Y_MAX = 33760 | |
Z_MAX = 2600 -- Head touches roof | |
Z_MIN = 122 -- Ground level | |
-- Room dimensions | |
X_LENGTH = X_MAX - X_MIN -- 2330 | |
Y_LENGTH = Y_MAX - Y_MIN -- 2325 | |
-- Coord descriptors | |
X_DESC = 'X' | |
Y_DESC = 'Y' | |
Z_DESC = 'Height' | |
GRV_DESC = 'Gravity' | |
-- Coord & gravity records | |
addr = getAddressList() | |
curX = addr.getMemoryRecordByDescription(X_DESC) | |
curY = addr.getMemoryRecordByDescription(Y_DESC) | |
curZ = addr.getMemoryRecordByDescription(Z_DESC) | |
gravity = addr.getMemoryRecordByDescription(GRV_DESC) | |
-- Scan settings | |
SCAN_STEP = 50 | |
SCAN_X_START = X_MIN | |
SCAN_X_END = X_MAX | |
SCAN_Y_START = Y_MIN | |
SCAN_Y_END = Y_MAX | |
SCAN_Z_TIMEOUT = 700 | |
SCAN_Z_STEP = 300 | |
function get (record) | |
return tonumber(record.getValue()) | |
end | |
function fallFrom (z) | |
curZ.setValue(z) | |
sleep(SCAN_Z_TIMEOUT) | |
end | |
function writeToCSV (x, y, z) | |
io.write(string.format('%d,%d,%.0f\n', x, y, z)) | |
end | |
-- Prepare output to file | |
filedir = 'D:\\path\\to\\output\\directory' | |
filename = string.format('z%d_x%d-%d_y%d-%d.csv', SCAN_STEP, SCAN_X_START, SCAN_X_END, SCAN_Y_START, SCAN_Y_END) | |
file = io.open(filedir .. '\\' .. filename, 'w+') | |
io.output(file) | |
io.write('x,y,z\n') | |
-- Set gravity really high to fall faster | |
gravity.setValue(-100000) | |
-- Loop over room | |
for x = SCAN_X_START, SCAN_X_END, SCAN_STEP do | |
for y = SCAN_Y_START, SCAN_Y_END, SCAN_STEP do | |
curX.setValue(x) | |
curY.setValue(y) | |
curZ.setValue(Z_MAX + SCAN_Z_STEP) | |
repeat | |
-- Make the player fall @ x;y | |
fallFrom(get(curZ) - SCAN_Z_STEP) | |
-- If we bounced somewhere, ignore this coordinate | |
if get(curX) ~= x or get(curY) ~= y then | |
break | |
end | |
writeToCSV(x, y, get(curZ)) | |
until get(curZ) <= Z_MIN + SCAN_Z_STEP | |
end | |
end | |
-- Reset gravity | |
gravity.setValue(-980) | |
-- Close file | |
io.close(file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment