Dantez
Moim sekretem jest ciasto
- Joined
- May 22, 2008
- Messages
- 1,206
- Reaction score
- 202
Author: Dantez
Version: 1.2
Platform: The Forgotten Server 0.3.6pl1
Version: 1.2
Platform: The Forgotten Server 0.3.6pl1
Dzia?anie:
Funkcje przeczesuj?ce map? w poszukaniu przedmiot?w i zamieniaj?ce je na ich odpowiedniki z tablicy.Spos?b u?ycia:
Mamy do wyboru dwie funkcje: chunk i line. R??ni? si? one sposobem przeszukiwania mapy. Chunk dzieli fragment na kawa?ki o wielko?ci podanej w configu. Line zamienia przedmioty pojedynczo, co jedna kratk?. Spos?b chunk jest szybszy, a line bardziej efektowny.Konfiguracja:
['keyword'] = {[ID1] = ID2
}
W tym przypadku ka?dy przedmiot o id ID1 zostanie zamieniony na ID2.
['keyword'] = {
[ID1] = {ID2, ID3, ID4}
}
Tutaj przedmiot o id ID1 zostanie zamieniony na losowy przedmiot o id z tablicy.
Skrypt:
[LUA]local config = {chunkSize = 40, -- 40x40 tiles
stackposScaned = 6, -- 6 stackpos for each tile
chunkDelay = 400, -- in ms
pointDelay = 3, -- in ms
}
local items = {
['winter'] = {
-- Borders
[4542] = 4737,
[4544] = 4739,
[4543] = 4738,
[4545] = 4740,
[4547] = 4742,
[4548] = 4743,
[4546] = 4741,
[4549] = 4744,
[4550] = 4745,
[4551] = 4746,
[4552] = 4747,
[4553] = 4748,
-- Grounds
[4526] = 670,
[4527] = 670,
[4528] = 670,
[4529] = 670,
[4530] = 670,
[4531] = 670,
[4532] = 670,
[4533] = 670,
[4534] = 670,
[4535] = 670,
[4536] = 670,
[4537] = 670,
[4538] = 670,
[4539] = 670,
[4540] = 670,
[4541] = 670,
-- Trees
[2700] = 2698,
[7024] = 7023,
[2720] = 7022,
[2718] = 7020,
-- Items
[6216] = 6609,
},
['summer'] = {
-- Grounds
[670] = {4526, 4529, 4530, 4534, 4535, 4536, 4538, 4539, 4541},
[6594] = {4526, 4529, 4530, 4532, 4534, 4535, 4536, 4539, 4541},
[6598] = {4526, 4527, 4529, 4530, 4531, 4534, 4535, 4536, 4539, 4541},
-- Borders
[4737] = 4542,
[4738] = 4543,
[4739] = 4544,
[4740] = 4545,
[4741] = 4546,
[4742] = 4547,
[4743] = 4548,
[4744] = 4549,
[4745] = 4550,
[4746] = 4551,
[4747] = 4552,
[4748] = 4553,
-- Trees
[2698] = 2700,
[7023] = 7024,
[7022] = 2720,
[7020] = 2718,
-- Items
[6609] = 6216,
}
}
function pointTransform(pos, phase)
for stackpos = 0, config.stackposScaned do
local groundItem = getThingFromPos({x = pos.x, y = pos.y, z = pos.z, stackpos = stackpos}, false)
if(groundItem.itemid ~= 0) then
local item = items[phase][groundItem.itemid]
if(item == 0) then
doRemoveThing(groundItem.uid)
elseif(item ~= nil) then
doTransformItem(groundItem.uid, (type(item) == "table") and item[math.random(#item)] or item)
end
else
return true
end
end
return true
end
function chunkTransform(start, finish, phase)
for y = start.y, finish.y do
for x = start.x, finish.x do
pointTransform({x=x, y=y, z=start.z}, phase)
end
end
return true
end
function chunk(start, finish, phase)
if(not items[phase] or type(items[phase]) ~= "table") then
return print("[Chunk transform] Phase " .. phase .. " doesn't exist or is not a table.") end
local timer, chunkCountX, chunkCountY = 0, math.ceil((finish.x - start.x)/config.chunkSize), math.ceil((finish.y - start.y)/config.chunkSize)
for z = start.z, finish.z do
for y = 1, chunkCountY do
posy = start.y + config.chunkSize * y
for x = 1, chunkCountX do
posx = start.x + config.chunkSize * x
addEvent(chunkTransform, timer * config.chunkDelay,
{x=start.x + config.chunkSize * (x-1) + (x > 1 and 1 or 0), y=start.y + config.chunkSize * (y-1) + (y > 1 and 1 or 0), z=z},
{x=(posx > finish.x and finish.x or posx), y=(posy > finish.y and finish.y or posy), z=z}, phase)
timer = timer + 1
end
end
end
return true
end
function line(start, finish, phase)
if(not items[phase] or type(items[phase]) ~= "table") then
return print("[Line transform] Phase " .. phase .. " doesn't exist or is not a table.") end
local timer = 0
for z = start.z, finish.z do
for y = start.y, finish.y do
for x = start.x, finish.x do
addEvent(pointTransform, config.pointDelay * timer, {x=x, y=y, z=z}, phase)
timer = timer + 1
end
end
end
return true
end[/LUA]
Wywo?ania:
[LUA]chunk(startPos, endPos, arrayIndex)point(startPos, endPos, arrayIndex)[/LUA]