What's new

Efekt losowy

Status
Not open for further replies.

fidor11

User
Joined
Dec 29, 2010
Messages
18
Reaction score
0
Witam!

Chcia?bym zapyta? czy mo?liwe jest / je?li tak w jaki spos?b zrobienie czego? takiego jak opisz? poni?ej (na przyk?adzie naj?atwiej wyt?umaczy?) ;)

Po spe?nieniu bleblele warunk?w z puli zdarze? losowane jest jedno (lub kilka je?li jest to mo?liwe) zdarze?, z kt?rych ka?de opatrzone jest pewnym poziomem prawdopodobie?stwa. Np. po wdepni?ciu na kratk?, istnieje 40% szans ?e gracz zostanie teleportowany do X1 Y1 Z1, 40% ?e do X2 Y2 Z2 i 20% szans ?e trafi do X3 Y3 Z3. Dodatkowo ma 4% szans ?e dostanie 1 gp, 1% szans ?e dostanie 5 gp, pozosta?e 95% nie ma przypisanego ?adnego zdarzenia.
Gdyby kto? wiedzia?, i? co? takiego nie zadzia?a, prosz? niech si? odezwie i po prostu to napisze ;D
 
Z

Zbizu

Guest
Odp: Efekt losowy

Zapewne szukasz takiej cz??ci kodu i je?li czyta?e? regulamin dzia?u zale?y Ci na poprawieniu swojego skryptu. Cz??ci konieczne do edycji zaznaczy?em na bia?o. Jako, ?e nie zrobi?e? tematu w dziale Request wnioskuj?, ?e z dodaniem tego kodu do swojego skryptu sobie poradzisz. Dostosuj to sobie do w?asnych potrzeb:
Code:
pos1 = {x=1, y=1, z=1}
pos2 = {x=2, y=2, z=2}
pos3 = {x=3, y=3, z=3}

local items = {
                     [1] = {2148, 5},
                     [2] = {2148, 1}
                   }

[B][COLOR=White]if(blablabla jak napisales)[/COLOR][/B]then
procenty = math.random(1, 100)
szansa2 = math.random(1, 100)
if(procenty > 40 and procenty < 81)then
             doTeleportThing(cid,pos1)
            if(szansa2 < 6 and szansa2 =~ 1)then
                        doPlayerAddItem(cid,items[2][1],items[2][2])
                        doPlayerSendTextMessage(cid,22,"Entering to the cave. You have received " .. items[2][2] .." x " .. items[2][1] .. " .")
            elseif(szansa == 1)then
                        doPlayerAddItem(cid,items[1][1],items[1][2])
                        doPlayerSendTextMessage(cid,22,"Entering to the cave. You have received " .. items[1][2] .." x " .. items[1][1] .. " .")
            else
                        doPlayerSendTextMessage(cid,22,"Entering to the cave.") 
            end
elseif(procenty < 41)then
            doTeleportThing(cid,pos2)
            if(szansa2 < 6 and szansa2 =~ 1)then
                        doPlayerAddItem(cid,items[2][1],items[2][2])
                        doPlayerSendTextMessage(cid,22,"Entering to the  cave. You have received " .. items[2][2] .." x " .. items[2][1] .. " .")
            elseif(szansa == 1)then
                        doPlayerAddItem(cid,items[1][1],items[1][2])
                        doPlayerSendTextMessage(cid,22,"Entering to the  cave. You have received " .. items[1][2] .." x " .. items[1][1] .. " .")
            else
                        doPlayerSendTextMessage(cid,22,"Entering to the cave.") 
            end
else
            doTeleportThing(cid,pos3)
                        if(szansa2 < 6 and szansa2 =~ 1)then
                        doPlayerAddItem(cid,items[2][1],items[2][2])
                        doPlayerSendTextMessage(cid,22,"Entering to the  cave. You have received " .. items[2][2] .." x " .. items[2][1] .. " .")
            elseif(szansa == 1)then
                        doPlayerAddItem(cid,items[1][1],items[1][2])
                        doPlayerSendTextMessage(cid,22,"Entering to the  cave. You have received " .. items[1][2] .." x " .. items[1][1] .. " .")
            else
                        doPlayerSendTextMessage(cid,22,"Entering to the cave.") 
            end
end
else
            doPlayerSendTextMessage(cid,22,"[B][COLOR=White]Wiadomosc informujaca, ze warunki nie zostaly spelnione[/COLOR][/B].") 
end
 

Oskar

Forum friend
Joined
Jan 24, 2009
Messages
2,256
Reaction score
331
Odp: Efekt losowy

PHP:
local config = {
				[40] = {x={x=1, y=1, z=1}},
				[40] = {x={x=1, y=1, z=1}},
				[20] = {x={x=1, y=1, z=1}},
				bonus = {
						[1] = {2148,5},
						[4] = {2148,1},
						}
				}

function nazwaFunkcjiKtoraChceszUzyc(parametry)
local check = true
for k, v in pairs(config) do
	if math.random(100) <= k and check then
		doTeleportThing(cid, v.x)
		check = false
	end
	for m, n in pairs(v.bonus) do
		if math.random(100) <= m then
			return doPlayerAddItem(cid, n[1], n[2])
		end
	end
end
return true
end
Uwa?am ten tutaj za prostszy skrypt. W nawiasach kwadratowych '[ ]' wpisujesz procenty, a w zmiennej 'x' pozycje. Nie musisz nic grzeba? w skrypcie, wystarczy uzupe?ni? tabelk?.
 

fidor11

User
Joined
Dec 29, 2010
Messages
18
Reaction score
0
Odp: Efekt losowy

Drogi zbizu o to mi w?a?nie chodzi?o :D Troszk? to przerobie i mam wymarzony skrypt

Co do Oskara... Z jakiego? powodu jest problem z rozpatrzeniem linijki
PHP:
for k, v in pairs(config) do
i przez to wszystko si? sypie...

ps. dzi?kuje :)
 
Last edited:
Status
Not open for further replies.
Top