• 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

klekSu

Stroke my ego.
Joined
Nov 4, 2008
Messages
1,285
Reaction score
18
Jak zrobić math.random od 2 do 134, bez 135 od 136 do 160 bez 161 do 191 i od 192 do 351 w jednej funkcji? :eek:

Próbowałem czegoś takiego, ale nie idzie.

Lua:
local pierwszy = math.random(2, 134)
local drugi = math.random(136, 160)
local trzeci = math.random(192, 351)
local random_id = {pierwszy, drugi, trzeci}
local orandom = random_id[math.random(1, #random_id)]

lookType = orandom
 
Last edited:
Lua:
local ran = { {2,134},{136,160},{162,190},{192,351};};
local t=math.random(1,#ran);
local o=math.random(ran[t][1],ran[t][2]);
 
Dzięki :)

Erm, nie działa to poprawnie :eek:
 
Last edited by a moderator:
Lua Code:
local rnd
local forbiddenArr = {135, 161} -- bez ktorych

repeat
rnd = math.random(2, 351)
until not isInArray(forbiddenArr, rnd)

pr0-- && czytelnosc++
 
Lua:
local disabled = {135, 161}

repeat
        local ran = math.random(2,351)
until not isInArray(disabled,ran)

o ile dobrze zrozumialem :X
 
@up
rnd w Kaczooha
ran w moim

w tej zmiennej masz wylosowana liczbe.
 
Gdy robię print (rnd) to pokazuje same 72, a gdy ran nie pokazuje nic :f
 
looktype.jpg

Tak powinno byc ok
 
KaczooH śmiejesz się ze mnie :p nie ładnie :p ale zobacz poprzedni post
 
PHP:
function random(a,b,c)
	if(type(c)~="table")then c={} end
	rnd = 0
	repeat
		rnd = math.random(a,b)
	until not isInArray(c,rnd)
	return rnd
end

używasz:

random(1,10, {3,2})

losowa liczba z pośród 1-10, omija 2 i 3.
 
Lua Code:
local rnd
local forbiddenArr = {135, 161} -- bez ktorych

repeat
rnd = math.random(2, 351)
until not isInArray(forbiddenArr, rnd)

pr0-- && czytelnosc++

Lua:
local disabled = {135, 161}

repeat
        local ran = math.random(2,351)
until not isInArray(disabled,ran)

o ile dobrze zrozumialem :X

Jak zrobić math.random od 2 do 134, bez 135 od 136 do 160 bez 161 do 191 i od 192 do 351 w jednej funkcji? :eek:

siema
 
No dobra, wiem o co chodzi :p
Lua:
    local tmp = getCreatureOutfit(cid)
    tmp.lookType = rnd
    doCreatureChangeOutfit(cid, tmp)
 
Srr, nie zauwazylem, ze jest zakres tez na zablokowane i tylko jedna niedozwolona wartosc, wiec edit untila
Lua:
until (rnd ~= 131) and ((rnd < 161) or (rnd > 191))
 
Last edited:
także nie zauważyłem, tutaj masz wersje funkcji

PHP:
function rnd(a,b,c)
	local leave = {}
	if(type(c)~="table")then c={} else
		for _,i in ipairs(c) do
			if(type(i) == "table")then
				for j=tonumber(i[1]), tonumber(i[2]) do
					table.insert(leave, j)
				end
			else
				table.insert(leave, tonumber(i))
			end
		end
	end
	rnd = 0
	repeat
		rnd = math.random(a,b)
	until not isInArray(leave,rnd)
	return rnd
end
użycie:
PHP:
rnd(2, 351, {135,{161,191}})
jak będziesz częściej używał, to w funkcji wygodniej.
 
Back
Top