• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[MOD] Catch the item event!

kimokimo

Kimo
Joined
Jan 25, 2011
Messages
821
Solutions
6
Reaction score
156
GitHub
karimadnan
Here is something i made for my server but since its dead now iam releasing it.

Lua:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Catch the item" version="1.00" author="Kimo" contact="otland.net" enabled="yes">
<config name="catchtheitem_config"><![CDATA[
config = {
 center_pos = {x = 2736, y = 3497, z = 7},
 item = 8304,
 aid = 4003,
 effect = CONST_ANI_FIRE,
 teleportPosition = {x = 74, y = 136, z = 9, stackpos = 1}, -- Where the teleport will be created
 teleportToPosition = {x = 78, y = 136, z = 9}, -- Where the teleport will take you
 teleportId = 1387, -- Id of the teleport
 spawnItemTime1 = 1, -- Time when the first items will be created
 spawnItemTime2 = 1, -- Time when the second items will be created
 timeToStartEvent = 1, -- Minutes, after these minutes the teleport will be removed and the event will be declared started
 itemRewards = {{2160,10}, {13305,1}, {13539,1}}
}              
]]></config>
 
<talkaction words="!catch" event="script"><![CDATA[
function onSay()
        domodlib('catchtheitem_config')
        local tp = doCreateTeleport(config.teleportId, config.teleportToPosition, config.teleportPosition)
        doItemSetAttribute(tp, "aid", config.teleportActionId)
        doBroadcastMessage("Catch the item is starting in "..config.timeToStartEvent.." minute!", MESSAGE_EVENT_ADVANCE)
        addEvent(startEvent, config.timeToStartEvent * 1000 * 10)
        print(getGlobalStorageValue(3333))
       return true
end

function startEvent()
    domodlib('catchtheitem_config')
        local get = getThingfromPos(config.teleportPosition)
        if get.itemid == config.teleportId then
                doRemoveItem(get.uid, 1)
                doBroadcastMessage("Catch the item teleport have been removed and the first items wave will start in " .. config.spawnItemTime1 .. " ", MESSAGE_EVENT_ADVANCE)
                addEvent(SpawnItem1, config.timeToStartEvent * 1000 * 10)
        end
end
       
function SpawnItem1()
domodlib('catchtheitem_config')
        local field = {}
        local k = config.center_pos
        for i = -2, 3 do
                for j = -2, 4 do
                        table.insert(field, {x=k.x+i, y=k.y+j, z=k.z})
                end
        end
        for i = 1, 8 do
                local a = math.random(1, #field)
                local c = {x=field[a].x, y=field[a].y, z=field[a].z}
                if getThingFromPos({x=c.x, y=c.y, z=c.z, stackpos=1}).itemid ~= 9767 then
                        local b = doCreateItem(config.item, {x=c.x, y=c.y, z=c.z, stackpos=1})
                        doItemSetAttribute(b, "aid", config.aid)
                        doItemSetAttribute(c, "moveable", 0)
                        doSendDistanceShoot(config.center_pos, c, config.effect)
                end
        end
        doBroadcastMessage("Items wave 1 has been finished wave 2 in "..config.spawnItemTime2.." minute ", MESSAGE_EVENT_ADVANCE)
        addEvent(SpawnItem2, config.spawnItemTime2 * 1000 * 10)
end
 
 
function SpawnItem2()
domodlib('catchtheitem_config')
        local field = {}
        local k = config.center_pos
        for i = -2, 3 do
                for j = -1, 2 do
                        table.insert(field, {x=k.x+i, y=k.y+j, z=k.z})
                end
        end
        for i = 1, 8 do
                local a = math.random(1, #field)
                local c = {x=field[a].x, y=field[a].y, z=field[a].z}
                if getThingFromPos({x=c.x, y=c.y, z=c.z, stackpos=1}).itemid ~= 9767 then
                        local b = doCreateItem(config.item, {x=c.x, y=c.y, z=c.z, stackpos=1})
                        doItemSetAttribute(b, "aid", config.aid)
                        doSendDistanceShoot(config.center_pos, c, config.effect)
                end
        end
        doBroadcastMessage("Items wave 2 is finished and results in 1 minute", MESSAGE_EVENT_ADVANCE)
        addEvent(EndEvent, 1 * 1000 * 10)
end
 
 
function EndEvent()
domodlib('catchtheitem_config')
local function maximum(a)
        local mi = 1
        local m = a[mi]
        for i,val in ipairs(a) do
                if val > m then
                        mi = i
                        m = val
                end
        end
        return m
end
 
local first = {}
local second = 0
local third = 0
local players = getPlayersOnline()
local winamount = {}
local storage = 7777 --event storage
for i, pid in ipairs(players) do
        if getPlayerStorageValue(pid, storage) >= 0 then
                table.insert(winamount, getPlayerStorageValue(pid, storage))
        end
end
local winningamount = maximum(winamount)
local price = math.random(1, #config.itemRewards)
        for i, pid in ipairs(players) do
                if getPlayerStorageValue(pid, storage) == winningamount then
                        table.insert(first, getPlayerName(pid))
                end
        end
        if #first > 1 then
                doBroadcastMessage('[Catch the item]\n We have a draw between '..first[1]..' and '..first[2]..'!\nTherefor NO PRICES will be given!')
        else
                for i, pid in ipairs(players) do
                        if getPlayerStorageValue(pid, storage) == winningamount then
                                doBroadcastMessage('[Catch the item]\n And the winner is:\n'..first[1]..' with a total score of '..winningamount..'\nYour Price: '..config.itemRewards[price][2]..' x '..getItemNameById(config.itemRewards[price][1])..'\nCongratulations!')
                                doPlayerAddItem(pid, config.itemRewards[price][1], config.itemRewards[price][2])
                        end
                end
        end
        for i, pid in ipairs(players) do
                if getPlayerStorageValue(pid, storage) == (winningamount-1) then
                        if second == 0 then
                                doBroadcastMessage('[Catch the item]\n 2nd place is:\n'..getPlayerName(pid)..' with a total score of '..getPlayerStorageValue(pid, storage)..'\nCongratulations!')
                                second = 1
                        end
                end
        end
        for i, pid in ipairs(players) do
                if getPlayerStorageValue(pid, storage) == (winningamount-2) then
                        if third == 0 then
                                doBroadcastMessage('[Catch the item]\n 3rd place is:\n'..getPlayerName(pid)..' with a total score of '..getPlayerStorageValue(pid, storage)..'\nCongratulations!')
                                third = 1
                        end
                end
        end
        addEvent(EndEvent2, 1 * 1000 * 10)
       end
 
function EndEvent2()
setGlobalStorageValue(4444, 0)
setGlobalStorageValue(3333, 0)
        for _, kid in ipairs(getPlayersOnline()) do
                if(getPlayerStorageValue(kid, 7776) > 0) then
                        doTeleportThing(kid, getTownTemplePosition(getPlayerTown(kid)))
                        setPlayerStorageValue(kid, 7776, 0)
                        setPlayerStorageValue(kid, 7777, 0)
                end
        end
end
]]></talkaction>
 
<action actionid="4003" event="script"><![CDATA[
function onUse(cid, item, fromPosition, itemEx, toPosition)
        if item.actionid == 4003 then
                doRemoveItem(getThingFromPos(fromPosition).uid, 6119)
                setPlayerStorageValue(cid,7777, getPlayerStorageValue(cid,7777)+1)
                local score = getPlayerStorageValue(cid, 7777)
              doCreatureSay(cid, "Point!\nScore ="..getPlayerStorageValue(cid, 7777), 34)
              return true
        end
end
]]></action>

<movevent type="StepIn" actionid="3000" event="script"><![CDATA[
local config = {
        playerCount = 3333, -- Global storage for counting the players in the event
        maxPlayers = 20 -- Max players who can participate
}
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
        if getGlobalStorageValue(config.playerCount) < config.maxPlayers then
                        setGlobalStorageValue(config.playerCount, getGlobalStorageValue(config.playerCount)+1)
                                if getGlobalStorageValue(config.playerCount) == config.maxPlayers then
                                        doBroadcastMessage("Catch the item event is now full [" .. getGlobalStorageValue(config.playerCount) .. " players]! The event will soon start.")
                                else
                        doBroadcastMessage(getPlayerName(cid) .. " entered catch the item event! Currently " .. getGlobalStorageValue(config.playerCount) .. " players have joined!", MESSAGE_STATUS_CONSOLE_RED)
                end
        else
                doTeleportThing(cid, fromPosition)
                doPlayerSendCancel(cid, "The event is full. There is already " .. config.maxPlayers .. " players participating in the event.")
                return false
        end
                print(getGlobalStorageValue(config.playerCount) .. " Players in catch the item event.")
        return true
end
]]></movevent>
</mod>

BIG thanks to zyntax for helping me.

What is this?
When the event start you have x time to join and after the teleport is closed items will be created around the center position (you set) and the item have to be unsed in your server you can edite the id in script config and players have to use the item to get points make sure the item is unmoveable and after 2 waves of items the results will appear and players will be teleported back to temple.
 
Last edited:
What does this do? Puts an item in the middle of the room, then moves it fast and the first person to catch it wins?
 
Thanks for share,
Some pics or an Video will be Cool, for helping ppl know how it works!
 
Not working in 0.4 :/

Code:
[21:22:13.127] Description:
[21:22:13.128] [string "LuaInterface::loadBuffer"]:96: attempt to call global 'm
aximum' (a nil value)
[21:22:13.128] [Warning - Event::loadScript] Cannot load script (function onSay(
)
[21:22:13.129]         domodlib('catchtheitem_config')
[21:22:13.130]         local tp = doCreateTeleport(config.teleportId, config.tel
eportToPosition, config.teleportPosition)
[21:22:13.131]         doItemSetAttribute(tp, "aid", config.teleportActionId)
[21:22:13.131]         setGlobalStorageValue(config.playerCount, 0)
[21:22:13.132]         doBroadcastMessage("Catch the item is starting in " .. co
nfig.timeToStartEvent .. " minutes! The teleport will be closed when the event s
tart!", MESSAGE_EVENT_ADVANCE)
[21:22:13.134]         addEvent(startEvent, config.timeToStartEvent * 1000 * 10)

[21:22:13.134]         print(getGlobalStorageValue(3333))
[21:22:13.134]         return true
[21:22:13.135] end
[21:22:13.136]
[21:22:13.136] function startEvent()
[21:22:13.137]     domodlib('catchtheitem_config')
[21:22:13.137]         local get = getThingfromPos(config.teleportPosition)
[21:22:13.137]         if get.itemid == config.teleportId then
[21:22:13.138]                 doRemoveItem(get.uid, 1)
[21:22:13.138]                 doBroadcastMessage("Catch the item teleport have
been removed and the first items wave will start in " .. config.spawnItemTime1 .
. " ", MESSAGE_EVENT_ADVANCE)
[21:22:13.139]                 addEvent(SpawnItem1, config.spawnItemTime1 * 1000
 * 10)
[21:22:13.139]         end
[21:22:13.139] end
[21:22:13.140]
[21:22:13.141] function SpawnItem1()
[21:22:13.142] domodlib('catchtheitem_config')
[21:22:13.142]         if math.random (1,8) == 4 then
[21:22:13.142]                 local position = {fromx = 75, fromy = 133, tox =
81, toy = 138, z = 9}
[21:22:13.144]           for i = position.fromx, position.tox do
[21:22:13.144]           for j = position.fromy, position.toy do
[21:22:13.145]            local pos = {x = i, y = j, z = position.z, stackpos =
253}
[21:22:13.145]            local getThing = getTileItemById(pos, config.item)
[21:22:13.145]                 doItemSetAttribute(getThing.uid, "aid", 4003)
[21:22:13.146]                 doCreateItem(config.item, {x = config.center_pos.
x+1, y = config.center_pos.y+1, z = config.center_pos.z, stackpos = 1})
[21:22:13.147]                 doCreateItem(config.item, {x = config.center_pos.
x-1, y = config.center_pos.y+1, z = config.center_pos.z, stackpos = 1})
[21:22:13.148]                 doCreateItem(config.item, {x = config.center_pos.
x+2, y = config.center_pos.y-1, z = config.center_pos.z, stackpos = 1})
[21:22:13.148]                 doCreateItem(config.item, {x = config.center_pos.
x+1, y = config.center_pos.y+3, z = config.center_pos.z, stackpos = 1})
[21:22:13.148]                 doSendDistanceShoot(config.center_pos, {x = confi
g.center_pos.x+1, y = config.center_pos.y+1, z = config.center_pos.z}, CONST_ANI
_HOLY)
[21:22:13.149]                 doSendDistanceShoot(config.center_pos, {x = confi
g.center_pos.x-1, y = config.center_pos.y+1, z = config.center_pos.z}, CONST_ANI
_HOLY)
[21:22:13.150]                 doSendDistanceShoot(config.center_pos, {x = confi
g.center_pos.x+2, y = config.center_pos.y-1, z = config.center_pos.z}, CONST_ANI
_HOLY)
[21:22:13.151]                 doBroadcastMessage("Items wave 1 has been finishe
d wave 2 in " .. spawnItemTime2 .. "  ", MESSAGE_EVENT_ADVANCE)
[21:22:13.153]                 addEvent(SpawnItem2, config.spawnItemTime2 * 1000
 * 10)
[21:22:13.154]                          end
[21:22:13.154]                          end
[21:22:13.154]         else
[21:22:13.155]                 doItemSetAttribute(getThing.uid, "aid", 4003)
[21:22:13.155]                 doCreateItem(config.item, {x = config.center_pos.
x-2, y = config.center_pos.y+3, z = config.center_pos.z, stackpos = 1})
[21:22:13.156]                 doSendDistanceShoot(config.center_pos, {x = confi
g.center_pos.x-2, y = config.center_pos.y+3, z = config.center_pos.z}, CONST_ANI
_HOLY)
[21:22:13.156]                 doCreateItem(config.item, {x = config.center_pos.
x+1, y = config.center_pos.y-2, z = config.center_pos.z, stackpos = 1})
[21:22:13.157]                 doSendDistanceShoot(config.center_pos, {x = confi
g.center_pos.x+1, y = config.center_pos.y-2, z = config.center_pos.z}, CONST_ANI
_HOLY)
[21:22:13.159]                 doCreateItem(config.item, {x = config.center_pos.
x+1, y = config.center_pos.y+2, z = config.center_pos.z, stackpos = 1})
[21:22:13.163]                 doSendDistanceShoot(config.center_pos, {x = confi
g.center_pos.x+1, y = config.center_pos.y+2, z = config.center_pos.z}, CONST_ANI
_HOLY)
[21:22:13.166]                 addEvent(SpawnItem2, config.spawnItemTime2 * 1000
 * 10)
[21:22:13.166]         end
[21:22:13.167]         end
[21:22:13.167]
[21:22:13.168] function SpawnItem2()
[21:22:13.168]         local position = {fromx = 75, fromy = 133, tox = 81, toy
= 138, z = 9}
[21:22:13.169]   for i = position.fromx, position.tox do
[21:22:13.169]   for j = position.fromy, position.toy do
[21:22:13.169]   local pos = {x = i, y = j, z = position.z, stackpos = 253}
[21:22:13.170]   local getThing = getTileItemById(pos, config.item)
[21:22:13.170]         doItemSetAttribute(getThing.uid, "aid", 4003)
[21:22:13.171]         doCreateItem(config.item, {x = config.center_pos.x+2, y =
 config.center_pos.y-1, z = config.center_pos.z, stackpos = 1})
[21:22:13.171]         doCreateItem(config.item, {x = config.center_pos.x-3, y =
 config.center_pos.y+2, z = config.center_pos.z, stackpos = 1})
[21:22:13.172]         doCreateItem(config.item, {x = config.center_pos.x+1, y =
 config.center_pos.y-3, z = config.center_pos.z, stackpos = 1})
[21:22:13.175]         doCreateItem(config.item, {x = config.center_pos.x-1, y =
 config.center_pos.y+2, z = config.center_pos.z, stackpos = 1})
[21:22:13.175]         doSendDistanceShoot(config.center_pos, {x = config.center
_pos.x+2, y = config.center_pos.y-1, z = config.center_pos.z}, CONST_ANI_HOLY)
[21:22:13.177]         doSendDistanceShoot(config.center_pos, {x = config.center
_pos.x-3, y = config.center_pos.y+2, z = config.center_pos.z}, CONST_ANI_HOLY)
[21:22:13.178]         doSendDistanceShoot(config.center_pos, {x = config.center
_pos.x-1, y = config.center_pos.y+2, z = config.center_pos.z}, CONST_ANI_HOLY)
[21:22:13.178]         doBroadcastMessage("Items wave 2 is finished and results
in 1 minute", MESSAGE_EVENT_ADVANCE)
[21:22:13.178]         addEvent(EndEvent, 1 * 1000 * 10)
[21:22:13.180] end
[21:22:13.180] end
[21:22:13.182] end
[21:22:13.182]
[21:22:13.184] function EndEvent()
[21:22:13.184] local function maximum(a)
[21:22:13.184]         local mi = 1
[21:22:13.185]         local m = a[mi]
[21:22:13.185]         for i,val in ipairs(a) do
[21:22:13.185]                 if val > m then
[21:22:13.186]                         mi = i
[21:22:13.187]                         m = val
[21:22:13.187]                 end
[21:22:13.188]         end
[21:22:13.188]         return m
[21:22:13.189] end
[21:22:13.189] end
[21:22:13.189]
[21:22:13.189] local players = getPlayersOnline()
[21:22:13.191] local winamount = {}
[21:22:13.192] local storage = 7777 --event storage
[21:22:13.192] for i, pid in ipairs(players) do
[21:22:13.193]         if getPlayerStorageValue(pid, storage) >= 0 then
[21:22:13.194]                 table.insert(winamount, getPlayerStorageValue(pid
, storage))
[21:22:13.194]         end
[21:22:13.195] end
[21:22:13.195] local winningamount = maximum(winamount)
[21:22:13.196] for i, pid in ipairs(players) do
[21:22:13.196]         if getPlayerStorageValue(pid, storage) == winningamount t
hen
[21:22:13.197]                 local player = getPlayerName(pid)
[21:22:13.197]                 doBroadcastMessage('And the winner is:\n'..player
..' with a total score of '..winningamount..'\nCongratulations!')
[21:22:13.198]                 addEvent(TeleportPlayers, 1 * 1000 * 10)
[21:22:13.198]         end
[21:22:13.199] end
[21:22:13.203]
[21:22:13.222] function TeleportPlayers()
[21:22:13.223] for _, kid in ipairs(getPlayersOnline()) do
[21:22:13.224] if(getPlayerStorageValue(kid, 7777) > 1) then
[21:22:13.224] doTeleportThing(kid, getTownTemplePosition(getPlayerTown(kid)))
[21:22:13.225] setPlayerStorageValue(kid, 7777, 0)
[21:22:13.225] end
[21:22:13.226] end
[21:22:13.226] end
[21:22:13.227] )
 
Last edited:
Nice script, but i get error's.... hate mods, dont tell you exactly where to look/whats wrong....

This happens when you say "!catch"
Code:
:onSay
Description:
(luaInterface::luaDoItemSetAttribute) Invalid data type
Not sure what to do on this one....

This happens when the event is spose to start
Code:
:onSay
description:
data/lib/032-position.lua:2: attempt to index local 'fromPosition' <a nil value>
stack traceback:
data/lib/032-position.lua:2: in function 'isinRange'
[string "..."]:97: in function <[string "..."]:95>
This one i couldnt find any isinRange's to try and fix it, so idea?....
 
Looks like "config.teleportActionId" is not defined in the config.
 
Ok that should fix the first problem, although i am not sure what action id is spouse to be.. and what other function setting the action id might effect..

Still dont know what would fix the second problem i was having.
 
Code:
[10/03/2013 01:00:55] [Error - TalkAction Interface] 
[10/03/2013 01:00:55] In a timer event called from: 
[10/03/2013 01:00:55] buffer:onSay
[10/03/2013 01:00:55] Description: 
[10/03/2013 01:00:56] (luaDoItemSetAttribute) Item not found
Also get debug during event?
 
center_pos = {x = 2736, y = 3497, z = 7} Did you set this to the position of the item in the middle?
 
Back
Top