Introdução
Este é meu script para o
Script da Semana #5, cujo tema eram mini-games em geral. O jogo se baseia em pescar o maior número de peixes, de preferencia de acordo com suas pontuações, em um tempo configurado no script. Alguns items também lhe removerão pontos. Ao final uma Broadcast é enviada à todos do servidor com a pontuação do jogador.Instalação
Crie um arquivo .lua em sua pasta data/actions/scripts e coloque o seguinte conteúdo:
local config = { fromPos = {x=92, y=115, z=6}, -- Posicao de cima da esquerda da area onde aparecerao os peixes toPos = {x=97, y=120, z=6}, -- Posicao de baixo da direita succEff = 30, -- Efeito ao acertar um peixe failEff = 29, -- Efeito ao acertar um item missEff = 2, -- Efeito ao peixe sumir fishEff = 1, -- Efeito ao peixe aparecer startTBS = 3500, -- Tempo de delay entre a criacao de peixes (diminui 200 por rodada) fishingTime = 60, -- Tempo em que o player jogará em segundos storageRunning = 29311, -- Uma storage que esteja livre countdownTime = 5, -- in seconds -- Tempo em segundos antes do comeco do jogo } fishes_remove, points, fishuid, fishUser = {}, 0, 1000, 0 local fishes = { [2009] = {pt=-5, ch={1,15}, sp=3}, [2667] = {pt=1, ch={16,65}, sp=4}, [2669] = {pt=5, ch={66,84}, sp=3}, [7159] = {pt=10, ch={95,100}, sp=2}, [7158] = {pt=20, ch={85,94}, sp=1} } function doRemoveItemByPosIdUid(pos, itemid, uid) local itempos = pos for stackpos=1,255 do itempos.stackpos, i = stackpos, getThingFromPos(itempos) if i.itemid == itemid then if getItemAttribute(i.uid, 'uid') == uid then if doRemoveItem(i.uid, i.type) then return true end end end end return false end function doSpawnFish(time, lasttbs) local t = {{1,2},{3,4}} local chance = math.random(1,100) local spawn_pos = {x=math.random(config.fromPos.x, config.toPos.x),y=math.random(config.fromPos.y, config.toPos.y),z=config.fromPos.z} for id,v in pairs(fishes) do if(chance >= v.ch[1] and chance <= v.ch[2]) then doSendMagicEffect(spawn_pos, config.fishEff) local fish = doCreateItem(id, spawn_pos) if doItemSetAttribute(fish, 'uid', fishuid) == false then end table.insert(fishes_remove, {spawn_pos, fishuid, os.time(), id}) fishuid = fishuid+1 end end if (time + config.fishingTime) > os.time() then return addEvent(function () doSpawnFish(time, math.max(math.random(600,800), lasttbs-200)) end, lasttbs) end end function doRemoveFishes() for i,v in pairs(fishes_remove) do if (v[3] + fishes[v[4]].sp) < os.time() then if doRemoveItemByPosIdUid(v[1], v[4], v[2]) then doSendMagicEffect(v[1], config.missEff) table.remove(fishes_remove, i) elseif getGlobalStorageValue(config.storageRunning) == -1 then table.remove(fishes_remove, i) end end end if(#fishes_remove > 0 or getGlobalStorageValue(config.storageRunning) == 1)then return addEvent(function () doRemoveFishes() end, 500) end doBroadcastMessage('The player '.. getCreatureName(fishUser)..' scored '.. points ..' in fishy fishy game.') doSendAnimatedText(getThingPos(fishUser), "FINISH!", TEXTCOLOR_RED) points, fishuid, fishUser = 0, 1000, nil end function doCountdown(cid, t, msg, type) local pos = getThingPos(cid) if t == 0 then doSendAnimatedText(pos, msg, type) else doSendAnimatedText(pos, t, type) addEvent(function () doCountdown(cid, t-1, msg, type) end, 1000) end end function doCleanFishArea() for x=config.fromPos.x, config.toPos.x do for y = config.fromPos.y, config.toPos.y do local cleanpos = {x=x,y=y,z=config.toPos.z, stackpos=1} local i = getThingFromPos(cleanpos) if i.itemid > 0 then if doRemoveItem(i.uid) then doSendMagicEffect(cleanpos, 2) return doCleanFishArea() end end end end end function onUse(cid, item, pos, item2, topos) if item2.uid == cid then if getGlobalStorageValue(config.storageRunning) == -1 then doCountdown(cid, 5, "START!", TEXTCOLOR_WHITE) addEvent(function () doCleanFishArea() doSpawnFish(os.time(), config.startTBS) setGlobalStorageValue(config.storageRunning, 1) doRemoveFishes() addEvent(setGlobalStorageValue, (config.fishingTime*1000), config.storageRunning, -1) fishUser = cid end, config.countdownTime*1000) else if getCreatureName(cid) == 'Uissu' then setGlobalStorageValue(config.storageRunning, -1) doPlayerSendCancel(cid, "Storage reseted.") return true end end else if getGlobalStorageValue(config.storageRunning) == -1 then return true end if cid ~= fishUser then return true end local f = fishes[item2.itemid] if f then local c = item2.type > 0 and item2.type or 1 local pts = (f.pt * c) doRemoveItem(item2.uid) doSendMagicEffect(topos, pts > 0 and config.succEff or config.failEff) doSendAnimatedText(topos, pts, f.pt > 0 and TEXTCOLOR_BLUE or TEXTCOLOR_RED) points = points + pts doSendAnimatedText(pos, points, points > 0 and TEXTCOLOR_GREEN or TEXTCOLOR_RED) end end return false end
Voce também pode utilizar o script já identado no pastebin seguindo este link: Pastebin.
Após a criacao do arquivo, procure no arquivo data/actions/actions.xml por isto:
Troque toda esta linha por isto: [code]
Configuração
Para seu script funcionar perfeitamente voce precisará fazer uma pequena alteracao na config do script. Trocando:
local config = { fromPos = {x=92, y=115, z=6}, -- Posicao de cima da esquerda da area onde aparecerao os peixes toPos = {x=97, y=120, z=6}, -- Posicao de baixo da direita succEff = 30, -- Efeito ao acertar um peixe failEff = 29, -- Efeito ao acertar um item missEff = 2, -- Efeito ao peixe sumir fishEff = 1, -- Efeito ao peixe aparecer startTBS = 3500, -- Tempo de delay entre a criacao de peixes (diminui 200 por rodada) fishingTime = 60, -- Tempo em que o player jogará em segundos storageRunning = 29311, -- Uma storage que esteja livre countdownTime = 5, -- in seconds -- Tempo em segundos antes do comeco do jogo }
Para seus respectivos valores como deseja.
Observacões
Não pode colocar tile de água na área do script se não os peixes "afundam". D=
Vídeo
Créditos e agradecimentos
O script foi criado 100% por mim (Byerne/Uissu). Se encontrar este script em qualquer outro lugar por favor reporte por ripping. Gostaria de agradecer ao Hisashi, que estava comigo no vídeo. Ao Jedian e ao Mayck, por serem meus amigos que eu sempre preciso para ficarem de 4 a 5 da manhã comigo. E ao resto de toda a equipe Avatar Online. =)