I am trying to script a function, that spawns several items randomly on the map.
My aim: I have 12 defined spots and 4 items. The items should be spread out randomly on random spots.
Sadly I cannot figure out, how to do that. I am sure, I am doing it far too complicate, but thats the only way I know how to do. (or better "don't know how to...")
All I get are several error messages and the preview doesn't start. Can anyone help me, please?
Code: Select all
function AddQuestItem()
local tMap = spawn("treasure_map");
tMap.scrollitem:setScrollImage("mod_assets/textures/note_pic/asia_tiger.tga")
-- decide which item is spawned
local x = math.random(1,4)
if x == 1 then
local itemA = spawn("ancient_apparatus");
local itemB = tMap;
local itemC = spawn("globe_spherical_map");
local itemD = spawn("telescope");
end
if x == 2 then
local itemB = spawn("ancient_apparatus");
local itemC = tMap;
local itemD = spawn("globe_spherical_map");
local itemA = spawn("telescope");
end
if x == 3 then
local itemC = spawn("ancient_apparatus");
local itemD = tMap;
local itemA = spawn("globe_spherical_map");
local itemB = spawn("telescope");
end
if x == 4 then
local itemD = spawn("ancient_apparatus");
local itemA = tMap;
local itemB = spawn("globe_spherical_map");
local itemC = spawn("telescope");
end
-- decide where item is spawned
local spotA = math.random(1,5)
local spotB = math.random(1,7)
local spotC = math.random(1,7)
local spotD = math.random(1,7)
if spotA == 1 then
sx_barrel_chest_8.surface:addItem(itemA.item);
end
if spotA == 2 then
sx_barrel_chest_02_9.surface:addItem(itemA.item);
end
if spotA == 3 then
ratling1_5.monster:addItem(itemA.item);
end
if spotA == 4 then
ratling1_4.monster:addItem(itemA.item);
end
if spotA == 5 then
ratling1_2.monster:addItem(itemA.item);
end
if spotB == 1 then
spawn(itemB.item, 9, 23, 10, 2, 0) -- behind barrels
end
if spotB == 2 then
spawn(itemB.item, 9, 6, 18, 0, 0) -- under bush
end
if spotB == 3 then
spawn(itemB.item, 9, 26, 17, 3, 0) -- in water
end
if spotB == 4 then
spawn(itemB.item, 9, 3, 11, 2, 0)-- upper left
end
if spotB == 5 then
spawn(itemB.item, 9, 17, 15, 0, 0) -- under table
end
if spotB == 6 then
ratling3_6.monster:addItem(itemB.item);
end
if spotB == 7 then
ratling2_1.monster:addItem(itemB.item);
end
if spotC == 1 then
spawn(itemC.item, 9, 23, 10, 2, 0) -- behind barrels
end
if spotC == 2 then
spawn(itemC.item, 9, 6, 18, 0, 0) -- under bush
end
if spotC == 3 then
spawn(itemC.item, 9, 26, 17, 3, 0) -- in water
end
if spotC == 4 then
spawn(itemC.item, 9, 3, 11, 2, 0)-- upper left
end
if spotC == 5 then
spawn(itemC.item, 9, 17, 15, 0, 0) -- under table
end
if spotC == 6 then
ratling3_6.monster:addItem(itemC.item);
end
if spotC == 7 then
ratling2_1.monster:addItem(itemC.item);
end
if spotD == 1 then
spawn(itemD.item, 9, 23, 10, 2, 0) -- behind barrels
end
if spotD == 2 then
spawn(itemD.item, 9, 6, 18, 0, 0) -- under bush
end
if spotD == 3 then
spawn(itemD.item, 9, 26, 17, 3, 0) -- in water
end
if spotD == 4 then
spawn(itemD.item, 9, 3, 11, 2, 0)-- upper left
end
if spotD == 5 then
spawn(itemD.item, 9, 17, 15, 0, 0) -- under table
end
if spotD == 6 then
ratling3_6.monster:addItem(itemD.item);
end
if spotD == 7 then
ratling2_1.monster:addItem(itemD.item);
end
end