Created
October 24, 2019 06:53
-
-
Save myxal/2747188b26988e353af72830da85e2ab to your computer and use it in GitHub Desktop.
Custom functions for DST - Skin chests
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
function MAPSELECT(value, key, selection) { | |
if (value.length != key.length){ | |
throw("lenghts of value and key must be equal") | |
} | |
output = "" | |
for (i=0;i<value.length;i++) { | |
if (key.charAt(i) == selection) { | |
output = output.concat(value.charAt(i)) | |
} | |
} | |
return output; | |
} | |
function GENWARDROBENAMES(character, collection, subset, separator){ | |
Utilities.sleep(300) | |
// by default, assume all wardrobe skins - head, chest, hands, legs, feet | |
// template: "WILSON_GLADIATOR", "BODY_WILSON_GLADIATOR", "LEGS_WILSON_GLADIATOR", "HAND_WILSON_GLADIATOR", "FEET_WILSON_GLADIATOR | |
subset = subset || "YYYYY" | |
separator = separator || "\n" | |
switch (character.toUpperCase()){ | |
case "MAXWELL": | |
character = "WAXWELL"; | |
break; | |
case "WIGFRID": | |
character = "WATHGRITHR"; | |
break; | |
case "WX-78": | |
character = "WX78" | |
break | |
} | |
if (subset.length != 5) { | |
throw("subset string must be 5 characters long") | |
} | |
skins = [] | |
// head | |
if (subset.charAt(0) == "Y"){ | |
skins.push((character + "_" + collection).toUpperCase()) | |
} | |
// chest | |
if (subset.charAt(1) == "Y"){ | |
skins.push("BODY_" + (character + "_" + collection).toUpperCase()) | |
} | |
// legs | |
if (subset.charAt(2) == "Y"){ | |
skins.push("HAND_" + (character + "_" + collection).toUpperCase()) | |
} | |
// hands | |
if (subset.charAt(3) == "Y"){ | |
skins.push("LEGS_" + (character + "_" + collection).toUpperCase()) | |
} | |
// feet | |
if (subset.charAt(4) == "Y"){ | |
skins.push("FEET_" + (character + "_" + collection).toUpperCase()) | |
} | |
return (skins.join(separator)) | |
} | |
function STEAMINVENTORY(profile, steamid, selection, debug){ | |
// uhhh, what did I want to use the selection for..? ¯\_(ツ)_/¯ | |
if (!( Boolean(profile) ^ Boolean(steamid) )) { | |
throw "Specify either profile, or Steam id. Not both, and not neither." | |
} | |
var url_inventory | |
if (profile) { | |
url_inventory = "http://steamcommunity.com/id/" + profile + "/inventory/json/322330/1" | |
} | |
if (steamid) { | |
url_inventory = "http://steamcommunity.com/profiles/" + steamid + "/inventory/json/322330/1" | |
} | |
if (debug) { return url_inventory } | |
//url_inventory = ("https://steamcommunity.com/id/myxal/inventory/json/322330/1") | |
const response = UrlFetchApp.fetch(url_inventory, {muteHttpExceptions: true}); | |
var jsonData = JSON.parse(response.getContentText()); | |
if (!jsonData.success) { | |
throw "Error fetching inventory: " + (jsonData.Error || "Unspecified Error") | |
} | |
// shamelessly copied from DST-skins-checklist; Thanks, Instant-Noodles! :) | |
// original: https://dst-skins-checklist.github.io | |
var jsonKeys_unique=Object.keys(jsonData.rgDescriptions); | |
var steamSkins=new Array(); | |
var jsonKeys_all=Object.keys(jsonData.rgInventory); | |
function duplicates(){ | |
r=0; | |
for(s=0; s<jsonKeys_all.length; s++){ | |
var t=jsonKeys_all[s]; | |
if(jsonData.rgDescriptions[x].classid==jsonData.rgInventory[t].classid){ | |
r++; | |
} | |
} | |
return r; | |
} | |
for(i=0; i<jsonKeys_unique.length; i++){ | |
var x=jsonKeys_unique[i]; | |
steamSkins.push({name: jsonData.rgDescriptions[x].name, prefab: jsonData.rgDescriptions[x].market_hash_name, quantity: duplicates()}); | |
} | |
return steamSkins.map(function(skin){return skin.prefab}).sort() | |
} | |
function GENOWNERSTRING(chestSkins, inventorySkins){ | |
// inventorySkins - range, Google sheets passes ranges as 2-dimensional arrays - [row][column] | |
// chestSkins - my multiline string, newline-separated list | |
if (!Array.isArray(inventorySkins)){ | |
throw "inventorySkins must be an array" | |
} else { | |
inventorySkins.forEach(function (row, index) { | |
if (row[0].length <1) { | |
inventorySkins.splice(index, (inventorySkins.legth - index)) | |
} else { | |
inventorySkins[index] = row[0] | |
} | |
}) | |
//inventorySkins = inventorySkins.map(function(e){return e[0]}) | |
} | |
if (!(typeof chestSkins) == 'string'){ | |
throw "chestSkins must be a string" | |
} else { | |
chestSkins = chestSkins.split("\n") | |
} | |
var output = ""; | |
chestSkins.forEach( function(item, index){ | |
output = output.concat((inventorySkins.indexOf(item) > -1) ? "Y" : "N" ); | |
}) | |
return output | |
} | |
function GENOWNERSTRINGS(chestSpec, inventorySkins){ | |
// chestSpec - 1 row, 2 columns: [ [newline-separated-skins, rarities] ] | |
// inventorySkins - 1-column range, Google sheets passes ranges as 2-dimensional arrays - [row][column] | |
// output: 1x2 range: owned rarities, missing rarities | |
if (!Array.isArray(inventorySkins)){ | |
throw "inventorySkins must be an array" | |
} else { | |
// flatten and trim inventorySkins - indexOf will only work properly if array is flat, and trim empty lines for speed | |
inventorySkins.forEach(function (row, index) { | |
if (row[0].length <1) { | |
inventorySkins.splice(index, (inventorySkins.legth - index)) | |
} else { | |
inventorySkins[index] = row[0] | |
} | |
}) | |
} | |
if (!(chestSpec.length == 1 && chestSpec[0].length == 2 )){ | |
throw "chestSpec must be range 1x2" | |
} | |
// chestSkins - my multiline string, newline-separated list | |
chestSkins = chestSpec[0][0].split("\n") | |
var out_owned = ""; | |
var out_missing = ""; | |
chestSkins.forEach( function(item, index){ | |
if (inventorySkins.indexOf(item) > -1) { | |
out_owned = out_owned.concat(chestSpec[0][1].charAt(index)) | |
} else { | |
out_missing = out_missing.concat(chestSpec[0][1].charAt(index)) | |
} | |
}) | |
return [ [out_owned, out_missing] ] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment