• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Wondering about a function.

Calon

Experienced Member
Joined
Feb 6, 2009
Messages
1,070
Reaction score
21
hello,
is there any function to remove some item[for example (stone)] from different position got the same item(stone) by a switch ??

For example a room got 4 stones in different positions,
if the player use a switch , a random stone disappear and the next time another stone remove etc.
i mean doRemoveItem but in a random way. :P

Rep ++
 
I'm not so good at lua, but I think can be done with math.random.

Something like:

LUA:
local stone = {
    [1] = 1234,
    [2] = 1222,
    [3] = 1236,
    [4] = 1555
}
 
doRemoveItem(cid, stone[math.random(4)], 1)

For positions maybe you can use getThingFromPos
 
Last edited:
I really dont remember how math.random works but it is something like this:

LUA:
local stonePos = {
    {x=1234,y=1234,z=7},
    {x=1235,y=1234,z=7},
    {x=1236,y=1234,z=7},
    {x=1237,y=1234,z=7}
}

local stoneRemove = math.random(stonePos)
doRemoveItem(getThingFromPos(stoneRemove).uid)
 
Code:
local stonePos = {
    {x=1234,y=1234,z=7},
    {x=1235,y=1234,z=7},
    {x=1236,y=1234,z=7},
    {x=1237,y=1234,z=7}
}

local i = 0
while i < #stonePos do
	i = i + 1
	local stone = getTileItemById(stonePos[math.random(#stonePos)], [COLOR="#FF0000"]stoneId[/COLOR]).uid
	if stone ~= 0 then
		doRemoveItem(stone)
		break
	end
end
 
works cool Cykotitan but what about if the player re use the switch for example the stone was gone before appears again then another new stone disappear ?
 
Last edited:
yes, until there's no stones left
confused_smile.gif
confused_smile.gif


you can set a global storage and then refuse to perform action if it's set
LUA:
if getStorage(1234) == 1 then
	return doPlayerSendCancel(cid, 'your text')
end

-- later in the code
doSetStorage(1234, 1)
 
Back
Top