• 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!

TFS 1.X+ Create ite in area randon

darcioantonio

www.adventurerpg.com.br
Joined
Jul 30, 2013
Messages
170
Solutions
1
Reaction score
16
Location
Brasil
GitHub
darcioantonio
Twitch
darcio_
YouTube
MundoOTServer
Hi, good evening, is it possible to create an item in a certain random area?
I have a square and I want item 1746 to be created somewhere in the square.
I did this but it creates 1 item in every sqm of the whole area :(


LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
Box()
end

local danoSupremo = {
fromposdaSupremo = {x = 1252, y = 1007, z = 4},
toposdaSupremo = {x = 1261, y = 1013, z = 4}
}
function Box()
for a = danoSupremo.fromposdaSupremo.x, danoSupremo.toposdaSupremo.x do
for b = danoSupremo.fromposdaSupremo.y, danoSupremo.toposdaSupremo.y do
pos = {x = a, y = b, z = 4, stackpos = 255}
doCreateItem(1746, 1, pos)

end
end
end
 
Hi, good evening, is it possible to create an item in a certain random area?
I have a square and I want item 1746 to be created somewhere in the square.
I did this but it creates 1 item in every sqm of the whole area :(


LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
Box()
end

local danoSupremo = {
fromposdaSupremo = {x = 1252, y = 1007, z = 4},
toposdaSupremo = {x = 1261, y = 1013, z = 4}
}
function Box()
for a = danoSupremo.fromposdaSupremo.x, danoSupremo.toposdaSupremo.x do
for b = danoSupremo.fromposdaSupremo.y, danoSupremo.toposdaSupremo.y do
pos = {x = a, y = b, z = 4, stackpos = 255}
doCreateItem(1746, 1, pos)

end
end
end

Try this:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local danoSupremo = {
fromposdaSupremo = {x = 1252, y = 1007, z = 4},
toposdaSupremo = {x = 1261, y = 1013, z = 4}
}

    function Box()
        local randX = math.floor(math.random(0,(toposdaSupremo.x - toposdaSupremo.x)))
        local randY = math.floor(math.random(0,(toposdaSupremo.y - toposdaSupremo.y)))
        local pos = {x = fromposdaSupremo.x + randX, fromposdaSupremo.y + randY, z = 4}
        doCreateItem(1746, 1, pos)
    end
return true
end
 
Fiz dessa forma e funcionou

LUA:
local from = {x=1252,y=1007}
local to = {x=1261,y=1013}

function onUse(cid, item, fromPosition, itemEx, toPosition)
local setX = math.random(from.x,to.x)
local setY = math.random(from.y,to.y)
doCreateItem(1746, 1, {x = setX,y = setY,z = 4})
return true
end
 
Back
Top