Advertisement
CloneTrooper1019

Roblox - Command Line Env. Extras

Jun 2nd, 2014
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.21 KB | None | 0 0
  1. -- @CloneTrooper1019, 2014
  2. -- A few useful functions that load as part of the function environment in a plugin (for ROBLOX).
  3. -- Put this script into Notepad, save it as a .lua file, create a folder inside of roblox's plugin folder and put this file in here.
  4.  
  5. util = LoadLibrary("RbxUtility")
  6. _env = getfenv()
  7.  
  8. _env.import = function (asset)
  9.     if not asset or type(asset) ~= "number" then return end
  10.     asset = math.floor(asset)
  11.     local obj = game:GetService("InsertService"):LoadAsset(asset):GetChildren()
  12.     for _,v in pairs(obj) do
  13.         v.Parent = workspace
  14.         if v:findFirstChild("ThumbnailCamera") then
  15.             workspace.CurrentCamera.CoordinateFrame = v.ThumbnailCamera.CoordinateFrame
  16.         end
  17.     end
  18.     game.Selection:Set(obj)
  19. end
  20.  
  21. _env.product = function (asset,prop)
  22.     if not asset or type(asset) ~= "number" then return end
  23.     asset = math.floor(asset)  
  24.     local info = game:GetService("MarketplaceService"):GetProductInfo(asset)
  25.     if prop and info[prop] then
  26.         print(info[prop])
  27.     else
  28.         print(util.EncodeJSON(info))
  29.     end
  30. end
  31.  
  32. _env.selected = function ()
  33.     return game.Selection:Get()[1]
  34. end
  35.  
  36. _env.allSelected = function ()
  37.     return game.Selection:Get()
  38. end
  39.  
  40. _env.encode = function (t)
  41.     if not table_ or type(t) ~= "table" then return end
  42.     print(util.EncodeJSON(t))
  43.     return util.EncodeJSON(t)
  44. end
  45.  
  46. _env.decode = function (json)
  47.     if not json or type(json) ~= "string" then return end
  48.     return util.DecodeJSON(json)
  49. end
  50.  
  51. _env.help = function ()
  52.     local help = {
  53.         ["import(int assetId)"] = "- Inserts a model into the workspace using the InsertService";
  54.         ["product(int assetId, string property)"] = "- Prints the ProductInfo of an asset in JSON";
  55.         ["selected()"] = "- Returns the first selected object in studio";
  56.         ["allSelected()"] = "- Returns a table of all selected objects in studio";
  57.         ["encode(table t)"] = "- Prints a JSON string of the table argument 't'";
  58.         ["decode(string json)"] = "- Returns a table from a JSON string, or nil";
  59.     }
  60.     print(string.rep("-",160))
  61.     print()
  62.     print("ENVIRONMENT FUNCTIONS")
  63.     print()
  64.     for func,desc in pairs(help) do
  65.         print(func)
  66.         print(" "..desc)
  67.         print()
  68.     end
  69.     print()
  70.     print(string.rep("-",160))
  71. end
  72.  
  73. print("Command Env Loaded. Type 'help()' to see all the functions.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement