Fala galera, hoje trago pra vocês meu Fishing System... Eu ainda não sou nem um programador experiente mas consegui fazer esse sistema, eu fiz ele faz um bom tempo... Não programo mais em Lua, apenas C++... Mas espero que gostem... Caso achem algo que seria desnecessário ou outra maneira mais fácil de fazer tal coisa só dizer, estou aberto a crÃticas.
Bem, vamos lá!.
- Crie um arquivo chamado fish.lua em Actions e coloque:
local waterTiles = {4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4664, 4665, 4666}
--qnt = quantidade de pokes que pode vim (randomico)
-- isca 0 para pokes que vem sem isca.
local fishIsca = {
["Bug"] = {skill = 10, isca = 0, qnt = 2},
["Rat"] = {skill = 10, isca = 2678, qnt = 1},
["Dragon Lord"] = {skill = 10, isca = 2676, qnt = 1},
["Demon"] = {skill = 10, isca = 3976, qnt = 1},
["Dragon"] = {skill = 10, isca = 3976, qnt = 1},
}
minTime = 10 -- minimo de segundos para balangar a vara.
fishs = {}
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
if item:getId() ~= 2389 then
doFishing(player, item, fromPosition, itemEx, toPosition, isHotkey)
if iscaId ~= 0 then
player:removeItem(iscaId, 1)
end
else
pickFishing(player, item, fromPosition, itemEx, toPosition, isHotkey)
end
end
function doFishing(player, item, fromPosition, itemEx, toPosition, isHotKey, oldOutfit)
if player:getStorageValue(fishingStorage) == 0 then
local tileId = itemEx:getId()
local iscaId = player:getStorageValue(iscaId)
local playerSkill = player:getEffectiveSkillLevel(SKILL_FISHING)
if isInArray(waterTiles, tileId) then
fishPosition = itemEx:getPosition()
if iscaId ~= 0 then
for a, b in pairs(fishIsca) do
if playerSkill >= fishIsca[a].skill then
if iscaId == fishIsca[a].isca then
table.insert(fishs, a)
end
end
end
end
if iscaId == 0 then
for a, b in pairs(fishIsca) do
if playerSkill >= fishIsca[a].skill then
if iscaId == fishIsca[a].isca then
table.insert(fishs, a)
end
end
end
end
else
return true
end
if #fishs >= 1 then
player:setStorageValue(timeFish, minTime + (math.random(5, 10) + os.time()))
player:getPosition():sendDistanceEffect(itemEx:getPosition(), 32)
if iscaId ~= 0 then
if not player:removeItem(iscaId, 1) then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Sua isca "..configFish[iscaId].name.." acabou ou ela nao esta no seu inventario.")
player:setStorageValue(iscaId, 0)
player:unregisterEvent("Fishing")
else
player:registerEvent("Fishing")
player:setStorageValue(fishingStorage, 1)
end
else
player:registerEvent("Fishing")
player:setStorageValue(fishingStorage, 1)
end
end
else
return true
end
end
function pickFishing(player, item, fromPosition, itemEx, toPosition, isHotKey, oldOutfit)
local iscaId = player:getStorageValue(iscaId)
if item:getId() == 2389 then
if player:getStorageValue(fishingStorage) == 2 then
local randomFish = fishs[math.random(#fishs)]
for i = 1, math.random(1, fishIsca[randomFish].qnt) do
local pokeFish = Game.createMonster(randomFish, player:getPosition())
end
fishs = {}
player:setStorageValue(fishingStorage, 0)
player:addSkillTries(SKILL_FISHING, 1)
player:unregisterEvent("Fishing")
else
player:setStorageValue(fishingStorage, 0)
player:unregisterEvent("Fishing")
end
return true
end
end
- Agora crie outro arquivo em Actions chamado isca.lua e coloque:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey) local isca = item:getId() local iscaTable = 0 if not configFish[isca] then player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "isca inexistente.") return true end for a, b in pairs(configFish) do if a == isca then iscaTable = a end end if player:getStorageValue(iscaId) == isca then player:setStorageValue(iscaId, 0) player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, configFish[isca].name.." foi retirada da vara.") else player:setStorageValue(iscaId, iscaTable) player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, configFish[isca].name.." foi colocada na vara.") end end
Agora em Creaturescripts crie um arquivo chamado fishing.lua e coloque:
function onThink(player, interval, lastExecution, thinkInterval)
if not player then
return true
end
local playerPos = player:getPosition()
-- se tiver algo no caminho
if not playerPos:isSightClear(fishPosition, false) then
player:unregisterEvent("Fishing")
player:setStorageValue(fishingStorage, 0)
end
--fica olhando para isca / mandando effects
lookToDirection(playerPos, fishPosition, player)
if player:getStorageValue(fishingStorage) ~= 2 then
fishPosition:sendMagicEffect(27)
end
-- se a distancia for muito grande da isca
if playerPos:getDistance(fishPosition) > 5 then
player:setStorageValue(fishingStorage, 0)
player:say("Voce perdeu sua isca.", TALKTYPE_MONSTER_SAY)
player:unregisterEvent("Fishing")
return true
end
-- Tempo pra puxar / perder a isca.
local currentTime = os.time()
local fishTime = player:getStorageValue(timeFish)
if currentTime > fishTime then
player:say("Sua isca esta balangando..", TALKTYPE_MONSTER_SAY)
player:setStorageValue(fishingStorage, 2)
fishPosition:sendMagicEffect(28)
if currentTime > fishTime + 15 then
player:say("Demorou muito e perdeu a isca.", TALKTYPE_MONSTER_SAY)
player:setStorageValue(fishingStorage, 0)
player:unregisterEvent("Fishing")
end
end
return true
end
e registre esse evento no creaturescripts.xml
<event type="think" name="Fishing" script="fishing.lua"/>
- Agora na sua lib adicione isso:
--Fishing System
configFish = {
[2678] = {name = "coconut"},
[2676] = {name = "banana"},
[3976] = {name = "worm"}
}
timeFish = 2001 -- Tempo do Fishing
fishingStorage = 2002 -- Puxar / Jogar
iscaId = 2003 -- IscaId
fishPosition = nil -- Posicao da isca na agua
--END Fishing System
Bem, eu acho que é isso, espero não estar esquecendo nada... Enjoy.











