function enviarSnowball(cid, pos, rounds, dir)
local player = Player(cid)
if rounds == 0 then
return true
end
if player then
local dirConfig = SNOWBALL.direcoes[dir]
if dirConfig then
local novaPos = Position(pos.x + dirConfig.dirPos.x, pos.y + dirConfig.dirPos.y, pos.z)
if isWalkable(novaPos) then
if Tile(novaPos):getTopCreature() then
local killed = Tile(novaPos):getTopCreature()
if Player(killed:getId()) then
if SNOWBALL.corposCongelados[killed:getSex()] then
local killed_corpse = SNOWBALL.corposCongelados[killed:getSex()][killed:getDirection()][math.random(1, #SNOWBALL.corposCongelados[killed:getSex()][killed:getDirection()])]
Game.createItem(killed_corpse, 1, killed:getPosition())
local item = Item(getTileItemById(killed:getPosition(), killed_corpse).uid)
addEvent(function() item:remove(1) end, 3000)
end
killed:getPosition():sendMagicEffect(3)
killed:teleportTo(CACHE_GAMEAREAPOSITIONS[math.random(1, #CACHE_GAMEAREAPOSITIONS)])
killed:getPosition():sendMagicEffect(50)
killed:setStorageValue(10109, (killed:getStorageValue(10109) - SNOWBALL.pontosPerda))
killed:setStorageValue(10108, SNOWBALL.muniMorreu)
killed:sendTextMessage(29, (config.mensagemFoiAcertado):format(player:getName(), SNOWBALL.pontosPerda, killed:getStorageValue(10109)))
player:setStorageValue(10109, player:getStorageValue(10109) + SNOWBALL.pontosAcerto)
player:sendTextMessage(29, (SNOWBALL.mensagemAcertei):format(killed:getName(), pontosAcerto, player:getStorageValue(10109)))
if(CACHE_GAMEPLAYERS[2] == player:getId()) and player:getStorageValue(10109) >= Player(CACHE_GAMEPLAYERS[1]):getStorageValue(10109) then
player:getPosition():sendMagicEffect(7)
player:sendTextMessage(29, SNOWBALL.mensagemLider)
Player(CACHE_GAMEPLAYERS[1]):getPosition():sendMagicEffect(16)
Player(CACHE_GAMEPLAYERS[1]):sendTextMessage(29, SNOWBALL.mensagemPerdeuLider)
end
table.sort(CACHE_GAMEPLAYERS, function(a, b) return Player(a):getStorageValue(10109) > Player(b):getStorageValue(10109) end)
else
novaPos:sendMagicEffect(3)
end
return true
end
pos:sendDistanceEffect(newPos, 13)
pos = novaPos
return addEvent(enviarSnowball, SNOWBALL.muniVelocidade, player:getId(), pos, rounds - 1, dir)
end
novaPos:sendMagicEffect(3)
return true
end
end
return true
end