Advertisement
blackwolfsden

item patch creator

Feb 12th, 2014
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.37 KB | None | 0 0
  1. -- By Laurea of EmuDevs.com
  2. -- creates a new populated items.dbc in you server folder
  3. -- containing all ingame entries plus all custom item entries
  4. -- all credits to Laurea for this
  5. local Command = "#patchit";
  6. local RequiredRank = 3 -- 3 is default admin rank on TC
  7.  
  8. --template function
  9. --encodes 'val' to a string of length 'size'
  10. --if rev is true, uses big-endian format. otherwise uses little-endian
  11. --returns string if successful, nil otherwise
  12. local function format(val, size, rev)
  13.     val = tonumber(val);
  14.     size = tonumber(size) or 4;
  15.     if (not val or size < 1 or size > 4) then return; end
  16.        
  17.     local f = {};
  18.     for i = 0, size-1 do
  19.         table.insert(f, rev and 1 or #f+1, string.char(bit32.extract(val, i*8, 8)));
  20.     end
  21.     return table.concat(f);
  22. end
  23.  
  24. local function main(event, player, msg)
  25.     if (player:GetGMRank() == RequiredRank and msg:lower() == Command:lower()) then
  26.         local query = WorldDBQuery("SELECT `entry`, `class`, `subclass`, `SoundOverrideSubclass`, `displayid`, `InventoryType`, `Material`, `sheath` FROM item_template")
  27.         if (query)then -- and query:GetRowCount() > 0)
  28.             local startTime = os.clock();
  29.             local file = assert(io.open("item.dbc", "w+b"), "Couldn't create new item.dbc in server directory!");
  30.             file:setvbuf("no");
  31.            
  32.             local rowCount = query:GetRowCount();
  33.             --No, the last two concatinations aren't needed. it's just easier to see the individual bytes that way
  34.             file:write("WDBC" .. format(rowCount) .. "\8\0\0\0" .. "\32\0\0\0" .."\1\0\0\0");
  35.            
  36.             for i = 1, rowCount do
  37.                 local entry = query:GetUInt32(0);
  38.                 local class = query:GetUInt8(1);
  39.                 local subclass = query:GetUInt8(2);
  40.                 local sound = query:GetInt8(3);
  41.                 local material = query:GetInt8(6);
  42.                 local display = query:GetUInt32(4);
  43.                 local invtype = query:GetUInt8(5);
  44.                 local sheath = query:GetUInt8(7);
  45.                
  46.                 local row = {format(entry), format(class), format(subclass), format(sound), format(material), format(display), format(invtype), format(sheath)};
  47.                 file:write(table.concat(row));
  48.                
  49.                 query:NextRow();
  50.             end
  51.            
  52.             file:write("\0");
  53.             file:flush();
  54.             file:close();
  55.            
  56.             player:SendBroadcastMessage(string.format("Recreated item.dbc with %u rows. Time taken: %0.02f seconds.", rowCount, os.clock() - startTime));
  57.         end
  58.     end
  59. end
  60.  
  61. if (RegisterPlayerEvent) then
  62.     RegisterPlayerEvent(18, main);
  63. else
  64.     RegisterServerHook(18, main);
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement