Itutorial
Legendary OT User
- Joined
- Dec 23, 2014
- Messages
- 2,334
- Solutions
- 68
- Reaction score
- 1,012
Advanced fishing action and talkaction script.
This code supports:
-Monster catching
-Fish up items/trash
-Chance to break rod
-Use worms
-Chance to catch random fish
-*Automatic Fishing*
-players can check what monsters they or another player has fished up with a talkaction
Actionscript
Talkaction: !catchs // !catchs playername
This code supports:
-Monster catching
-Fish up items/trash
-Chance to break rod
-Use worms
-Chance to catch random fish
-*Automatic Fishing*
-players can check what monsters they or another player has fished up with a talkaction
Actionscript
Lua:
--All chances are out of 100000--
local waters = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 7236, 10499, 15401, 15402}
local monsters = {
[1] = {name = "Fish1", levelReq = 50, fishingReq = 50, storage = 10000, chance = 1000, msg = nil, magicEffect = CONST_ME_LOSEENERGY},
[2] = {name = "Fish2", levelReq = 50, fishingReq = 50, storage = 10001, chance = 800, msg = "|PLAYERNAME| has caught a Fish2!", magicEffect = CONST_ME_LOSEENERGY}
}
local items = {
[1] = {itemid = 1111, chance = 1000, onGround = true}, -- true = the item will fall on the ground under the player. This is used for player fishing trash if wanted.
[2] = {itemid = 1111, chance = 800, onGround = false}
}
local monsterEnabled = true
local itemsEnabled = true
--Set to false if you do not want any of these--
local chanceBreakRod = 1000
local catchFish = 1000
local fishIds = {1111, 1111, 1111} --Type the fish ids they can catch => normal, salmon, ect.
local useWorms = false
local automaticFishing = false --If this is true players will not have to fish manually they will fish until they move.--
local msgStart = "You will automatically fish until you move."
local msgStop = "You have stopped automatic fishing."
-------------------------------------------------
function onUse(player, item, target, fromPosition, toPosition, isHotkey)
if not isInArray(waters, target:getId()) then
return false
end
local TILE = Tile(fromPosition)
if TILE:getPzInfo() then
return player:sendCancelMessage("You cannot fish in protection zones.")
end
if useWorms and not player:removeItem("worm", 1) then
return player:sendCancelMessage("You need worms to fish with!")
end
if monsterEnabled then
for i = 1, #monsters do
if player:getLevel() >= monsters[i].levelReq and player:getSkillLevel(SKILL_FISHING) >= monsters[i].fishingReq then
if math.random(1, 100000) <= monsters[i].chance then
local MONS = Game.createMonster(monsters[i].name, fromPosition)
if MONS then
MONS:setDescription(MONS:getDescription().."\nIt was caught by: "..player:getName()..".")
end
if player:getStorageValue(monsters[i].storage) == nil then
player:setStorageValue(monsters[i].storage, 1)
else
player:setStorageValue(monsters[i].storage, player:getStorageValue(monsters[i].storage) + 1)
end
if monsters[i].msg then
local text = string.gsub(monsters[i].msg, "|PLAYERNAME|", player:getName())
Game.broadcastMessage(text, 1)
end
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have caught a(n) "..monsters[i].name.."!")
player:getPosition():sendMagicEffect(monsters[i].magicEffect)
break
end
end
end
end
if itemsEnabled then
for i = 1, #items do
if math.random(1, 100000) <= items[i].chance then
if items[i].onGround then
Game.createItem(items[i].itemid, 1, fromPosition)
else
player:addItem(items[i].itemid, 1)
end
break
end
end
end
if chanceBreakRod ~= false and math.random(1, 100000) <= chanceBreakRod then
item:remove()
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Your fishing rod has broken.")
end
if catchFish ~= false and math.random(1, 100000) <= catchFish then
local fishId = fishIds[math.random(1, #fishIds)]
player:addItem(fishId, 1)
end
if automaticFishing then
local pos = player:getPosition()
local pid = player:getId()
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, msgStart)
startAutomaticFishing(pid, pos, toPosition)
end
player:addSkillTries(SKILL_FISHING, 1)
toPosition:sendMagicEffect(CONST_ME_LOSEENERGY}
return true
end
function startAutomaticFishing(pid, pos, toPosition)
local player = Player(pid)
if player then
if player:getPosition() == pos then
if useWorms and player:getItemCount(1111) < 1 then
return player:sendCancelMessage("You need worms to fish with!")
end
if monsterEnabled then
for i = 1, #monsters do
if player:getLevel() >= monsters[i].levelReq and player:getSkillLevel(SKILL_FISHING) >= monsters[i].fishingReq then
if math.random(1, 100000) <= monsters[i].chance then
local MONS = Game.createMonster(monsters[i].name, fromPosition)
if MONS then
MONS:setDescription(MONS:getDescription().."\nIt was caught by: "..player:getName()..".")
end
if player:getStorageValue(monsters[i].storage) == nil then
player:setStorageValue(monsters[i].storage, 1)
else
player:setStorageValue(monsters[i].storage, player:getStorageValue(monsters[i].storage) + 1)
end
if monsters[i].msg then
local text = string.gsub(monsters[i].msg, "|PLAYERNAME|", player:getName())
Game.broadcastMessage(text, 1)
end
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have caught a(n) "..monsters[i].name.."!")
player:getPosition():sendMagicEffect(monsters[i].magicEffect)
break
end
end
end
end
if itemsEnabled then
for i = 1, #items do
if math.random(1, 100000) <= items[i].chance then
if items[i].onGround then
Game.createItem(items[i].itemid, 1, fromPosition)
else
player:addItem(items[i].itemid, 1)
end
break
end
end
end
if chanceBreakRod ~= false and math.random(1, 100000) <= chanceBreakRod then
item:remove()
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Your fishing rod has broken.")
end
if catchFish ~= false and math.random(1, 100000) <= catchFish then
local fishId = fishIds[math.random(1, #fishIds)]
player:addItem(fishId, 1)
end
player:addSkillTries(SKILL_FISHING, 1)
toPosition:sendMagicEffect(CONST_ME_LOSEENERGY}
addEvent(startAutomaticFishing, 2000, pid, pos, toPosition)
end
end
end
Talkaction: !catchs // !catchs playername
Lua:
function onSay(player, words, param, channel)
if param == "" then
local text = "[Catches]\n"
for i = 1, #monsters do
if player:getStorageValue(monsters[i].storage) == nil then
player:setStorageValue(monsters[i].storage, 1)
end
text = text..""..monsters[i].name..": "..player:getStorageValue(monsters[i].storage).."\n"
end
player:showTextDialog(2160, text)
else
local target = Player(param)
if not target then
return player:sendCancelMessage("Player is not online or does not exist.")
end
local text = "["..param.."'s Catches]\n"
for i = 1, #monsters do
if target:getStorageValue(monsters[i].storage) == nil then
target:setStorageValue(monsters[i].storage, 1)
end
text = text..""..monsters[i].name..": "..target:getStorageValue(monsters[i].storage).."\n"
end
player:showTextDialog(2160, text)
end
return true
end