View difference between Paste ID: rfrLzwUh and PV8LrAk5
SHOW: | | - or go back to the newest paste.
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
-- http://emudevs.com/showthread.php/2620-custom-item-entry-patch-file-creator
6
local Command = "#patchit";
7
local RequiredRank = 3 -- 3 is default admin rank on TC
8
9
--template function
10
--encodes 'val' to a string of length 'size'
11
--if rev is true, uses big-endian format. otherwise uses little-endian
12
--returns string if successful, nil otherwise
13
local function format(val, size, rev)
14
	val = tonumber(val);
15
	size = tonumber(size) or 4;
16
	if (not val or size < 1 or size > 4) then return; end
17
		
18
	local f = {};
19
	for i = 0, size-1 do
20
		table.insert(f, rev and 1 or #f+1, string.char(bit32.extract(val, i*8, 8)));
21
	end
22
	return table.concat(f);
23
end
24
25
local function main(event, player, msg)
26
	if (player:GetGMRank() == RequiredRank and msg:lower() == Command:lower()) then
27
		local query = WorldDBQuery("SELECT `entry`, `class`, `subclass`, `SoundOverrideSubclass`, `displayid`, `InventoryType`, `Material`, `sheath` FROM item_template")
28
		if (query)then -- and query:GetRowCount() > 0) 
29
			local startTime = os.clock();
30
			local file = assert(io.open("item.dbc", "w+b"), "Couldn't create new item.dbc in server directory!");
31
			file:setvbuf("no");
32
			
33
			local rowCount = query:GetRowCount();
34
			--No, the last two concatinations aren't needed. it's just easier to see the individual bytes that way
35
			file:write("WDBC" .. format(rowCount) .. "\8\0\0\0" .. "\32\0\0\0" .."\1\0\0\0");
36
			
37
			for i = 1, rowCount do
38
				local entry = query:GetUInt32(0);
39
				local class = query:GetUInt8(1);
40
				local subclass = query:GetUInt8(2);
41
				local sound = query:GetInt8(3);
42
				local material = query:GetInt8(6);
43
				local display = query:GetUInt32(4);
44
				local invtype = query:GetUInt8(5);
45
				local sheath = query:GetUInt8(7);
46
				
47
				local row = {format(entry), format(class), format(subclass), format(sound), format(material), format(display), format(invtype), format(sheath)};
48
				file:write(table.concat(row));
49
				
50
				query:NextRow();
51
			end
52
			
53
			file:write("\0");
54
			file:flush();
55
			file:close();
56
			
57
			player:SendBroadcastMessage(string.format("Recreated item.dbc with %u rows. Time taken: %0.02f seconds.", rowCount, os.clock() - startTime));
58
		end
59
	end
60
end
61
62
if (RegisterPlayerEvent) then
63
	RegisterPlayerEvent(18, main);
64
else
65
	RegisterServerHook(18, main);
66
end