- Joined
- Nov 17, 2010
- Messages
- 6,756
- Solutions
- 578
- Reaction score
- 5,305
Basically the script is trying to push the character in a random direction, when they enter/spawn/teleport onto this tile.
My question is how do we get rid of the table with a quick line of code?
Basically we need 2 random numbers ranging from -1 - 1, but both of the random numbers cannot be 0.
They can be 1 & 1, -1 & -1, but not 0 & 0.
This is the current code, posted in this thread.
The only idea I had was to do..
but I don't know how to exclude 0's..
Unless I do it like this?
But then it's almost as convoluted to look at as the table. xD
Does anyone have a better idea?
Cheers,
Xikini
My question is how do we get rid of the table with a quick line of code?
Basically we need 2 random numbers ranging from -1 - 1, but both of the random numbers cannot be 0.
They can be 1 & 1, -1 & -1, but not 0 & 0.
This is the current code, posted in this thread.
Code:
local positions = {
{-1, -1},
{-1, 0},
{-1, 1},
{1, -1},
{1, 0},
{1, 1},
{0, -1},
{0, 1},
}
function onStepIn(cid, item, position, fromPosition)
local rand = math.random(8)
local new_pos = {x = position.x + positions[rand][1], y = position.y + positions[rand][2], z = position.z}
doTeleportThing(cid, new_pos, true)
return true
end
The only idea I had was to do..
Code:
local a, b = (math.random(3) - 2), (math.random(3) - 2)
Unless I do it like this?
Code:
local rand_a, rand_b = (math.random(3) - 2), (math.random(3) - 2)
if rand_a == 0 and rand_b == 0 then
repeat
rand_b = (math.random(3) - 2)
until rand_b ~= 0
end
Does anyone have a better idea?
Cheers,
Xikini