olha as notas tao melhorando kkk
- Fórum
- xTibia - Notícias e Suporte
- Soluções
- Archived
- [Exercícios - Aula 8] Respostas
2
445
info
Grupo: Conde
Registrado: 29/07/13
Posts: 780
Reputação: +60
Gênero: Masculino
Char no Tibia: aguarde...

03 de outubro de 2013 às 17:27

info
Grupo: Herói
Registrado: 14/12/10
Posts: 3.6k
Reputação: +846
Gênero: Masculino
Saudações jovens programadores, estarei postando neste tópico, as respostas da Aula 8 da escolinha de scripting, o conteúdo é: Tabelas.
Allan Harlen:
function onUse(cid, item, fromPosition, itemEx, toPosition) local math = cfg[math.random(1, #cfg.monster)] local level = cfg[math.random(1, #cfg.level)] local sto = storage[math.random(1, #cfgt.storage)] local cfg = { Monster = {"Demon", "Super Demon", "Apocalyps"}, Level = {150, 250, 50}, Storage = { 12589} } if getPlayerLevel(cid) >= level then doCreateMonster(math, getThingPos) return true elseif getPlayerStorageValue(cid, sto) then doPlayerSendTextMessage(cid, 18, "Só com "..sto.." Pode Usa Isso") else doPlayerSendTextMessage(cid, 18, "Só "..level.." Pode Passar Aki") return true end end -- [[ 2 Tarefa Da Aula 9 ]] -- function onUse(cid, item, fromPosition, itemEx, toPosition) local cfg = { 1888, 2160, 50} if getPlayerStorageValue(cid, cfg[1]) == 0 then doPlayerAddItem(cid, [2], 5) setPlayerStorageValue(cid, cfg[1], 1) doPlayerAddPremiumDays(cid, cfg[3]) else doPlayerSendCancel(cid,"Vocé Ja Completou essa Quest.") end return TRUE endNota: 7,50
OBS: Você está errando bastante na hora de chamar os valores da tabela, e não se esqueça de que não é possível retornar um valor de uma tabela, sem ela ter sido declarada antes. Dica: Teste os códigos antes de tudo.
Matheus Ribeiro:
-- 1 - Crie qualquer código, aonde deve haver uma espécie de configuração... config = { shows_messages = true, level_necessary = 10, exhaustion_time = 50, -- in seconds exaustion_storage = 1234, time_casting = 20, magical_effect = 10, } function checkfight(cid , interval) if exhaustion.check(cid, config.exaustion_storage) then return false end if config.shows_messages then doPlayerSendTextMessage(cid, 1, getCreatureName(cid).." ["..getPlayerLevel(cid).."]: Teleporting in " ..config.time_casting-interval.. " seconds") end doSendMagicEffect(getCreaturePosition(cid) , config.magical_effect) if getCreatureCondition(cid, CONDITION_INFIGHT) == false then doCreatureSetNoMove(cid, true) if config.time_casting-interval == 0 then doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid))) if config.shows_messages then doPlayerSendTextMessage(cid, 1, getCreatureName(cid).." ["..getPlayerLevel(cid).."]: Finally in "..getTownName(getPlayerTown(cid))) end doCreatureSetNoMove(cid, false) exhaustion.set(cid, config.exaustion_storage, config.exhaustion_time) end end if getCreatureCondition(cid, CONDITION_INFIGHT) and config.time_casting-interval == 0 then if config.shows_messages then doPlayerSendTextMessage(cid, 1, getCreatureName(cid).." ["..getPlayerLevel(cid).."]: I'm in battle") end doCreatureSetNoMove(cid, false) exhaustion.set(cid, config.exaustion_storage, 0) end end function onUse(cid) if config.level_necessary <= getPlayerLevel(cid) then if not exhaustion.check(cid, config.exaustion_storage) then for i = 1, config.time_casting do addEvent(checkfight ,1000*i ,cid , i) end else if config.shows_messages then doPlayerSendTextMessage(cid, 1, getCreatureName(cid).." ["..getPlayerLevel(cid).."]: I can only use again in "..exhaustion.get(cid, 1234).." seconds") end end else if config.shows_messages then doPlayerSendTextMessage(cid, 1, getCreatureName(cid).." ["..getPlayerLevel(cid).."]: I can only use it when you are level "..config.level_necessary) end end end -- 2 - Dê 3 exemplos de uso de index, e 3 exemplos de uso de tabelas -- contar o total de valores local monster = {'rat' , 'cave rat' , 'rotworm' , 'carrion rotworm'} print(monster[math.random(1 ,table.maxn(monster))]) -------------------------------------------------------------------- -- enserir valor local i = {20, 1, 5, 7, 8, 9} table.insert (i, 7, 'oi') print(i[table.maxn(i)]) --------------------------------------------------------------------- -- remover valor table3 = {1} table.remove (table3 , 1) print(table3[1]) --------------------------------------------------------------------- -- index local tabelax = {'oi' , 'kkk' , os.time() ,os.date()} print(tabelax[4]) -- tabelas -- String Aleatorias table ={ [1] = "Oi", [2] = "Tbm?", [3] = "blz?", [4] = "Fmz?", } local aleatorio = math.random(1 , #table) print(table[aleatorio]) -- Configuração do Script config = { printar_qts_vezes = 2, msg = "PRINTAR" } for i = 1 ,config.printar_qts_vezes do print(config.msg) end -- Guardar informações local oi = {} oi[1] = os.time() print(oi[1]) -- ou tabela = { ['demon'] = {level = 10 , looktype = 35} } print(tabela['demon'].looktype) print(tabela['demon'].level)Nota: 9,50
OBS: Muito bom, você está usando praticamente tudo já dado na escolinha e aparentemente estudando e aprendendo bem, parabéns.
Zilde Neto:
--\\// Edite apenas aqui! \\//-- local configs = { lvl = 50, exp = 5000, } --//\\ Edite apenas aqui! //\\-- --\\// Não altere nada a partir daqui! \\//-- local naomecha = { lvlcheck = getPlayerLevel(cid), } function onUse(cid) if naomecha.lvlcheck < configs.lvl then return doPlayerSendCancel(cid, "Voce ja concluiu a quest!") and false end if naomecha.lvlcheck => configs.lvl then doPlayerAddExp(cid, configs.exp) setPlayerStorageValue(uid, 34008, 1) return doPlayerSendTextMessage(cid, 27, "Parabens, voce concluiu a quest!") and true end end --[[ Exerc. 2 ]]-- local index1 = {[45] = 20, 46, [1] = 2} --// 20 e 2 com index diferentes, respectivamente 45 e 1 local index2 = {1, 8, 6} --// Cada um com sua index local index3 = {} --// Index com valor nil (Nulo) --\\// Exemplos de Tables //\\-- Exemplos de Indexes local infos = { nomes = {"Tio Roksas", "Pablo", "Allan", "Matheus", "Zilde"}, idades = {15, 18, 13, 30, 12} profissao = {"Doido", "Ajudante", "Mapper", "Seilá", "Estudante"}, } local tabelafunc = { func = getPlayerLevel(cid), name = getPlayerName(cid), } local tabelaquest = { storage = 47854, exp = 2640, level = 50, }Nota: 8,50
OBS: Muito bem, aprendendo a pegar valores de tabela. Dica: Estude melhor o return e escopo.
Galera, vocês são os únicos alunos restantes na Escolinha, estamos quase no final de tudo isso, e vejo que aprenderam bastante. DICA: Estudem melhor escopo e identação. bjs.