as notas não foram ta ruim assim tao bem de mais
- Fórum
- OTServ
- Tutoriais
- Tutoriais de Scripting
- [Exercícios - Aula 9] Respostas
2
1.5k
info
Grupo: Conde
Registrado: 29/07/13
Posts: 780
Reputação: +60
Gênero: Masculino
Char no Tibia: aguarde...

14 de outubro de 2013 às 19:25

info
Grupo: Herói
Registrado: 14/12/10
Posts: 3.6k
Reputação: +846
Gênero: Masculino
Iae amados alunos, vocês estão aprendendo rápido e bem neste período, alguns tiveram dificuldades. A Escolinha em si, está praticamente no fim e restaram apenas 3 alunos rsrs. Neste tópico estarei postando as respostas da penúltima aula
Allan Harlen:
-- [[ Tarefa Looping Vamo Q Vamo Exe : 1 ]] -- -- [[ Exemplo N : 1 ]] -- function onSay(cid) while true do doSendMagicEffect(getThingPos(cid), 55) doPlayerAddItem(cid, 2160 , 5) print("Seu ot ta fudido ") end end -- [[ Exemplo N : 1 Concluido ]] -- -- [[ Exemplo N : 2 ]] -- function onUse(cid, item, fromPosition, itemEx, toPosition) while true do doPlayerRemoveItem(cid, 2160, 1) doCreateMonster("Demon", getThingPos(cid)) print("Invasão De Demon No Seu Lado Infinito Claro") end end -- [[ Exemplo N : 2 Concluido ]] -- -- [[ Exemplo N : 3 ]] -- function onStepIn(cid, item, fromPosition) while true do pos = {x = 1256, y= 1256, z=7} doTeleportThing(cid, pos) print("Você Vai Bugar No Teleport Muaahuaehahue") end end -- [[ Exemplo N : 3 Concluido ]] -- -- [[ Tarefa Looping Vamo Q Vamo Exe : 1 Concluido ]] -- -- [[ Tarefa Looping Vamo Q Vamo Exe : 2 ]] -- function onSay(cid) if getPlayerLevel(cid) > 100 then for a, b in ipairs(getPlayersOnline()) do doPlayerAddItem(cid, 2160, 100) doPlayerBroadcastMessage(cid, "Todos Player Acima Do Level 100 Ganharam 1kk" , 27) end end end -- [[ Tarefa Lopping Vamo Q Vamo Exe : 2 Concluida ]] -- -- [[ Tarefa Lopping Vamo Q Vamo Exe : 3 ]] -- local tb = { level = { 50, 100, 100, 150, 150, 250, }} local tba = tb,getPlayerLevel(cid) for k, v, i in ipairs(tba) do if k == tb.level[1] and k <= tb.level[2] then doPlayerAddItem(cid, 2160, 10) elseif v == tb.level[3] and v <= tb.level[4] then doPlayerAddItem(cid, 2160, 20) elseif i == tb.level[5] and i <= tb.level[6] then doPlayerAddItem(cid, 2160, 30) end end -- [[ Tarefa Lopping Vamo Q Vamo Exe : 3 Concluida ]] -- -- [[ Tarefa Lopping Vamo Q Vamo Exe : 4 ]] -- -- [[ Tarefa Lopping Vamo Q Vamo Exe : 4 Exe : 1 ]] -- x = 16 while x > 2 do x = x - 1 z = {x = 1258, y=1258, z= 7} doTeleportThing(cid, z) if getPlayerLevel(cid) > 50 then break end end -- [[ Tarefa Lopping Vamo Q Vamo Exe : 4 Exe : 1 Concluida]] -- -- [[ Tarefa Lopping Vamo Q Vamo Exe : 4 Exe : 1 ]] -- repeat doPlayerAddExp(cid, 10) if getPlayerLevel(cid) > 58 then break end until os.date("%D") == "8" -- [[ Tarefa Lopping Vamo Q Vamo Exe : 4 Exe : 1 Completo ]] -- -- [[ Tarefa Lopping Vamo Q Vamo Exe : 4 Exe : 2 ]] -- repeat doPlayerAddExp(cid, 10) if os.date("%D") == "8" then break end until os.date("%B") == "April" -- [[ Tarefa Lopping Vamo Q Vamo Exe : 4 Exe : 2 Completo ]] --Nota: 8,00
OBS: Allan, você está se confundindo um pouco na identação, entendeu um pouco apenas sobre os loopings, mas não soube utilizar os recursos, procure ler mais algumas vezes a aula.
Matheus Ribeiro:
-- 1º Exercício: Crie 3 exemplos de loopings infinitos; -- 1º) for i = 1 , math.huge do print(i) end -- 2º) a = 0 repeat print(a) until a ~= 0 -- 3º) x = 30 while x > 1 do print(x) end -- 2º Exercício: Crie um código, aonde mande 1kk para todos jogadores online, com level maior que 100. function onThink(cid) for _, i in ipairs(getPlayersOnline()) do if getPlayerLevel(i) > 100 then doPlayerAddMoney(i, 100000) end end end -- 3º Exercício: Utilizando tabelas, crie um "sistema", aonde ao fazer a quest.. function onUse(cid , item) local table = { [100] = {1, 10, 301415}, [150] = {11, 15, 301416}, [190] = {16, 19, 301417}, [250] = {20, 25, 301418}, [320] = {26, 32, 301419}, } for k,v in pairs(table) do if getPlayerLevel(cid) >= v[1] and getPlayerLevel(cid) <= v[2] then if getPlayerStorageValue(cid, v[3]) ~= 1 then doPlayerAddMoney(cid, k) setPlayerStorageValue(cid, v[3], 1) end end end end -- 4º Exercício: Dê 2 exemplos de OTServ para o break. -- 1º) while getPlayerLevel(cid) < 10 do doCreatureAddHealth(cid, 5) if getPlayerLevel(cid) > 10 then break end end -- 2º) while getCreatureCondition(cid, CONDITION_MANASHIELD) do doPlayerAddMana(cid, -5) if getCreatureCondition(cid, CONDITION_MANASHIELD) == false then break end endNota: 8,50
OBS: Matheus, você sempre foi mt esforçado, mas um pouco, digamos que "afobado". Encare isso como um elogio, você se dá bem com os códigos, entedendo sua lógica, mas por conta da afobação acaba errando algumas coisas. Procure dar mais uma estudadinha em return, e tome cuidado com os loopings infinitos, mesmo querendo que sejam finitos, rsrs.
Zilde Neto:
--[[ Exerc. 1 ]]-- while true then print("I'm the god of repeating *----*.") end --[[ Motivo: Essa função sempre será verdadeira, consequentemente, colocando outro true alÃ, vai dar errado e vai ficar repitindo o código infinitas vezes ]]-- repeat print("HU3HU3HU3 NOOB!") until true == false --[[ Motivo: True nunca será igual a False, consequentemente, o código irá ser repetido infinitas vezes na tentativa de realizar a checagem e igualá-los ]]-- repeat print("HU3HU3HU3 NOOB!") until false == true --[[ Motivo: O mesmo acima .____. ]]-- --[[ Exerc. 2 ]]-- function onSay(cid) for a, b in ipairs(getPlayersOnline()) do doPlayerAddItem(cid, 2160, 100) end return true end --[[ Exerc. 3 ]]-- function onUse(cid) local tablelvminmax = { st1 = 1, 50, st2 = 51, 100, st3 = 101, 150, st4 = 151, 200, st5 = 201, 250, } for a _, ipairs(getPlayerLevel(cid)) do if a == tablelvminmax.st1[1] and a <= tablelvminmax.st1[2] then doPlayerAddItem(cid, 2160, 10) elseif a == tablelvminmax.st2[1] and a <= tablelvminmax.st2[2] then doPlayerAddItem(cid, 2160, 20) elseif a == tablelvminmax.st3[1] and a <= tablelvminmax.st3[2] then doPlayerAddItem(cid, 2160, 30) elseif a == tablelvminmax.st4[1] and a <= tablelvminmax.st4[2] then doPlayerAddItem(cid, 2160, 40) elseif a == tablelvminmax.st5[1] and a <= tablelvminmax.st5[2] then doPlayerAddItem(cid, 2160, 50) end end end --[[ Exerc. 4 ]]-- while isKnight(cid) do doPlayerAddItem(cid, 2160, 1) if isDruid(cid) break end end -- Exemplo 1 /\ -- Exemplo 2 \/ repeat doPlayerAddItem(cid, 2160, 1) if os.date("%A") == "Sunday" then break end until os.date("%A") == "Saturday"Nota: 8,50
OBS: Você entendeu bem a estrutura do while e repeat, mas não muito bem para que servem as variáveis do for, dê mais uma lida e boa sorte.
Parabéns anjos, estudem