Skip to content

Instantly share code, notes, and snippets.

@cvega
Last active May 26, 2020 16:20
Show Gist options
  • Save cvega/366e288753e34783305d7fc3dabf22c4 to your computer and use it in GitHub Desktop.
Save cvega/366e288753e34783305d7fc3dabf22c4 to your computer and use it in GitHub Desktop.
rust - oxide items json
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using UnityEngine;
// items.json plugin for oxide (return JSON array with rust items (id, name, shortname, craftingStackable)
namespace Oxide.Plugins
{
[Info("Items JSON Dump", "decay.dev", "0.0.1")]
[Description("Get JSON dump of all rust items, based on ItemsInfo by misticos")]
class ItemsJSON : RustPlugin
{
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
{ "Incorrect Arguments", "Please, specify correct arguments." }
}, this);
}
private void Init()
{
cmd.AddConsoleCommand("items.json", this, CommandConsoleHandle);
}
private bool CommandConsoleHandle(ConsoleSystem.Arg arg)
{
if (!arg.IsAdmin)
return false;
arg.ReplyWith(GetItemsJSON());
return true;
}
private string GetItemsJSON()
{
List<Hashtable> itemsList = new List<Hashtable>();
var catalog = ItemManager.itemList;
for (var i = 0; i < catalog.Count; i++)
{
var item = catalog[i];
Hashtable Item = new Hashtable();
Item["id"] = item.itemid;
Item["name"] = item.name;
Item["shortname"] = item.shortname;
Item["craftingStackable"] = item.craftingStackable;
itemsList.Add(Item);
}
string json = JsonConvert.SerializeObject(itemsList, Formatting.Indented);
return json;
}
private string GetMsg(string key, string userId = null) => lang.GetMessage(key, this, userId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment