View difference between Paste ID: Eq9tJzdp and KPy1Kf8s
SHOW: | | - or go back to the newest paste.
1
-- Gerenciador de sorteios
2
-- Escrito por Ninguem
3
4
adm = "Ninguem"
5
nome = "Sorteio de Teste"
6
mapa = [[<C><P Ca=""/><Z><S><S H="40" P="0,0,0.3,0.2,0,0,0,0" L="800" X="399" N="" Y="380" T="0" /></S><D /><O /></Z></C>]]
7
8
participante = {}
9
inicio = false
10
fim = false
11
qtd = 0
12
fast = 0
13
14
function eventTextAreaCallback(id, p, cmd)
15
	if cmd == "entrada" then
16
		ui.addTextArea(0, "<p align='center'>Participando", p, 200, 370, 400, 20, 1, 0x00ff00, 0.8,false)
17
		entrada(p, #participante + 1)
18
	elseif cmd == "inicio" then
19
		ui.addPopup(0, 2, "<p align='center'>Quantidade de sorteados", p, 300, 200, 200, false)
20
	elseif cmd == "novo" then
21
		novo()
22
	end
23
end
24
25
function eventNewPlayer(p)
26
	if not inicio and not fim then
27
		ui.addTextArea(0, "<p align='center'><a href='event:entrada'>Clique para participar do sorteio!", p, 200, 370, 400, 20, 1, 0xffff00, 0.8, false)
28
		ui.addTextArea(-3, "<p align='center'><font size='30px'>"..nome, p, 5, 40, 795, 40, 1, 1, 0.8, false)
29
	end
30
end
31
32
function eventPopupAnswer(id, p, cmd)
33
	if tonumber(cmd, 10) then
34
		if tonumber(cmd, 10) >= 1 and tonumber(cmd, 10) <= #participante then
35
			ui.removeTextArea(0, nil)
36
			ui.removeTextArea(-1, nil)
37
			qtd = tonumber(cmd, 10)
38
			fast = math.random(5,15)
39
			inicio = true
40
		end
41
	end
42
end
43
44
function participando(p)
45
	for i, v in pairs(participante) do
46
		if v == p then
47
			return true
48
		end
49
	end
50
	return false
51
end
52
53
function entrada(p, num)
54
	if not participando(p) then
55
		participante[num] = p
56
		ui.addTextArea(num, "<p align='center'>" .. p, nil, ((num-1)%8)*100+5, math.floor((num-1)/8)*30+100, 90, 20, 1, 1, 0.8, false)
57
	end
58
end
59
60
function novo()
61
	for i=1, #participante do
62
		ui.removeTextArea(i, nil)
63
		table.remove(participante, 1)
64
	end
65
	ui.addTextArea(0, "<p align='center'><a href='event:entrada'>Clique para participar do sorteio!", nil, 200, 370, 400, 20, 1, 0xffff00, 0.8, false)
66
	ui.addTextArea(-1, "<p align='center'><a href='event:inicio'>Iniciar", adm, 650, 370, 100, 20, 1, 0x0000ff, 0.8,false)
67
	tfm.exec.removePhysicObject(0)
68
	fim = false
69
end
70
71
function sorteio(tipo)
72
	local lista = {}
73
	local sorteado = 0
74
	for i=1, #participante do
75
		lista[i] = i
76
	end
77
	local rand = 0
78
	for i, v in pairs(participante) do
79
		ui.addTextArea(i, "<p align='center'>" .. v, nil, ((i-1)%8)*100+5, math.floor((i-1)/8)*30+100, 90, 20, 1, 1, 0.8, false)
80
	end
81
	for i=1, qtd do
82
		sorteado = math.random(#lista)
83
		rand = lista[sorteado]
84-
		table.remove(lista, rand)
84+
		table.remove(lista, sorteado)
85
		if tipo == "quase" then
86
			ui.addTextArea(rand, "<p align='center'><font color='#ffff00'>" .. participante[rand], nil, ((rand-1)%8)*100+5, math.floor((rand-1)/8)*30+100, 90, 20, 1, 0xffff00, 0.8, false)
87
		elseif tipo == "final" then
88
			ui.addTextArea(rand, "<p align='center'><font color='#00ff00'><b>" .. participante[rand], nil, ((rand-1)%8)*100+5, math.floor((rand-1)/8)*30+100, 90, 20, 1, 0x00ff00, 0.8, false)
89
		end
90
	end
91
end
92
93
function eventLoop()
94
	if inicio then
95
		if fast > 0 then
96
			sorteio("quase")
97
			fast = fast - 1
98
		else
99
			sorteio("final")
100
			inicio = false
101
			fim = true
102
			ui.addTextArea(-1, "<p align='center'><a href='event:novo'>Novo sorteio", adm, 650, 370, 100, 20, 1, 0x0000ff, 0.8,false)
103
		end
104
	end
105
	if fim then
106-
		tfm.exec.addPhysicObject(0, 400, 200, {type=12,color=math.random(0x666666, 0x777777), miceCollision=true, width=800, height=400})
106+
		tfm.exec.addPhysicObject(0, 400, 200, {type=12,color=math.random(0x666666, 0x777777), miceCollision=false, width=800, height=400})
107
		for i=1, 50 do
108
			tfm.exec.displayParticle(math.random(21,24), math.random(1,800), 20, math.random(-20,20)/100, math.random(10,1000)/100, 0, 0, nil)
109
		end
110
	end
111
end
112
113
tfm.exec.disableAutoShaman(true)
114
tfm.exec.disableAutoNewGame(true)
115
tfm.exec.newGame(mapa)
116
ui.addTextArea(0, "<p align='center'><a href='event:entrada'>Clique para participar do sorteio!", nil, 200, 370, 400, 20, 1, 0xffff00, 0.8, false)
117
ui.addTextArea(-1, "<p align='center'><a href='event:inicio'>Iniciar", adm, 650, 370, 100, 20, 1, 0x0000ff, 0.8,false)
118
ui.addTextArea(-3, "<p align='center'><font size='30px'>"..nome, nil, 5, 40, 795, 40, 1, 1, 0.8, false)
119
tfm.exec.setUIMapName("Script de sorteios")