• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua need a little help with create random items in random positions

5lave Ots

Active Member
Joined
Oct 2, 2017
Messages
246
Solutions
1
Reaction score
40
Location
Ankrahmun
edited:
now I need an lua code tfs 0.4 860
that check if a tile with pos X have
no item on it,,
and not house tile
and not pz tile,
can anyone help?

this will be used in a script that create random reward boxes is some places of the city
 
Last edited:
now I been working to make this one, now I have 2 things missing

my problems are:
1) when I call this function>> the broadcast said that 12 items was created, but actualy they are 8
so I need to check if items created == random value, then its okay, else repeat loop
2) second thing, I need to make a function that remove the these box items after 30 minutes
Lua:
local pos = {
{x=1000,y=1005,z=7 ,stackpos=1},
{x=1000,y=1006,z=7 ,stackpos=1},
{x=1000,y=1007,z=7 ,stackpos=1},
{x=1000,y=1008,z=7 ,stackpos=1},
and much more}

function drop(posy)
local created = 0
local itemsrand = math.random(5,15)
doBroadcastMessage('There are '..itemsrand..' Loot Crates have been created on the city, they will be removed within 30 minutes. Good Luck!')
for i = 0, itemsrand do
if created < itemsrand then
poso = posy[math.random(1, #posy)]
if (getTileThingByPos(poso).uid == 0) then
if getTileInfo(poso).protection == false
and (getTileInfo(poso).house == false)
and getTopCreature(poso).uid == 0 then
doCreateItem(10616, 1, poso)
created = created + 1
end
end
end
end
return true
end
 
Lost 4 box could land in protection zone or house, but script broadcasts fixed value on the start wich is itemsrand, but should broadcast created items at the end instead.
Guess "posy" is your "pos" table. And what do you store in there are all positions of a map?

If its some unique item you could add duration attrubute to it.

Also with this script couple boxes can be spawned on the same spot.
 
Back
Top