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

math.random

donacool

Mapper Scripter Ot Owner
Joined
Jan 15, 2010
Messages
97
Reaction score
0
can someone tell me how do i use a math.random but that it only be 1 to 2

like fisrt 1 then 2 then 1 then 2 then 1 then 2
 
no like this
Code:
function onStepIn(item, position, lastPosition, fromPosition, toPosition, actor)
local alphaTeam = {x = 1000, y = 1000, z = 7}
local bravoTeam = {x = 1000, y = 1000, z = 7}
local number = math.random(1, 2)
local tileid = 474
local tileuid = 1897554

if isPlayer(cid) and item.itemid == tileid and item.uid == tileuid then
	if number == 1 then
		doTeleportThing(cid, alphaTeam)
		doSendTextMessage(cid, CONST_ME_DESCR, "You are a alpha teamer!")
	end return true
	elseif number == 2 then
		doTeleportThing(cid, bravoTeam)
		doSendTextMessage(cid, CONST_ME_DESCR, "You are a bravo teamer!")
	end return true
end
return true
end
its okey?
im not sure if i need to put so mant returns true
please post something that can help me
 
Code:
local dest = {
	[1] = {x = 1000, y = 1000, z = 7},
	[2] = {x = 1000, y = 1000, z = 7}
}

local names = {"Alpha", "Bravo"}

local tileid = 474
local tileuid = 1897554

function onStepIn(item, position, lastPosition, fromPosition, toPosition, actor)
	if isPlayer(cid) and item.itemid == tileid and item.uid == tileuid then
		local number = math.random(1, 2)
		doTeleportThing(cid, dest[number])
		doSendTextMessage(cid, CONST_ME_DESCR, "You are a ".. names[number] .." teamer!")
	end
end
 
you can also use
  • math.random() with no arguments generates a real number between 0 and 1.
  • math.random(upper) generates integer numbers between 1 and upper.
  • math.random(lower, upper) generates integer numbers between lower and upper.

Lua:
math.random(2)
 
Last edited:
don't include the two integers

Lua:
math.random(2)

u-mad1.jpg


By the way: no difference :)
 
Back
Top