Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Fishy Fishy Minigame
- Copyrights @ XTibia Byerne
- Link: xtibia.com/forum/topic/180468-action-fishy-fishy-mini-game/]]--
- local config = {
- fromPos = {x=92, y=115, z=6},
- toPos = {x=97, y=120, z=6},
- succEff = 30,
- failEff = 29,
- missEff = 2,
- fishEff = 1,
- startTBS = 3500,
- fishingTime = 60, -- in seconds
- storageRunning = 29311,
- countdownTime = 5, -- in seconds
- }
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement