Daniel Kopeć
Member
During the automatic start of the event or entering the command: !startswimming such an error appears in the console.
How to Fix it?
[MOD] swimming event script:
How to Fix it?
[MOD] swimming event script:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Swimming_Event" version="3.0" author="DenZ" contact="otland.net" enabled="yes">
<config name="config_swimming_event">
<![CDATA[
configSwimmingEvent = {
storages = {
player = 'swimmingEventPlayer', -- set free storage
joining = 'swimmingEventJoining', -- set free storage
group = 'swimmingEventGroup', -- set free storage
exhaust = 'swimmingEventExhaust', -- set free storage
countEvent = 'swimmingEventCountEvent' -- set free storage
},
position = {x=16854, y=14548, z=7}, -- posiotion to which player is teleporting
rewards = {2157, 11197, 10515, 9077}, -- reward id which player can win (reward is random)
players = {
max = 9, -- max players in event
min = 2, -- min players to event start
minLevel = 200, -- min level to join to event
speed = 200 -- speed which players will have in event
},
days = {
['Monday'] = {'16:00:20'},
['Tuesday'] = {'16:00:20'},
['Wednesday'] = {'16:00:20'},
['Thursday'] = {'16:00:20'},
['Friday'] = {'16:00:20'},
['Saturday'] = {'13:08:20'},
['Sunday'] = {'16:00:20'}
},
delayTime = 5.0, -- time in which players who joined to event are teleporting to teleport position [minutes]
startEvent = 2, -- time from teleport to start event [seconds]
text = '-PL-\nAby wygrac i otrzymac nagrode, jako pierwszy dobiegnij do mety. Posluguj sie lina, maczeta oraz lopata.\n\n-ENG\nTo win and get a rewards, the first get to the finish line. Uses the rope, a machete and a shovel.'
}
]]>
</config>
<lib name="lib_swimming_event">
<![CDATA[
function doStartEventSwimming()
if configSwimmingEvent.players.min <= doCountPlayersSwimmingEvent() then
for _, cid in ipairs(getPlayersOnline()) do
if getCreatureStorage(cid, configSwimmingEvent.storages.player) > 0 then
doRemoveCondition(cid, CONDITION_INFIGHT) -- fight
doTeleportThing(cid, configSwimmingEvent.position) -- teleport pos
doChangeSpeed(cid, configSwimmingEvent.players.speed - getCreatureBaseSpeed(cid)) -- predkosc
doCreatureSetStorage(cid, configSwimmingEvent.storages.group, getPlayerGroupId(cid)) -- storage
doPlayerSetGroupId(cid, 7) -- grupa
addEvent(doCreatureSetNoMove, configSwimmingEvent.startEvent * 1000, cid, false)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Get ready. Swimming Event start in '..configSwimmingEvent.startEvent..' seconds.')
end
end
addEvent(doCheckSpeedSwimmingEvent, configSwimmingEvent.startEvent * 1000)
doBroadcastMessage('Swimming Event has started. LET\'S GO!')
else
for _, cid in ipairs(getPlayersOnline()) do
if getCreatureStorage(cid, configSwimmingEvent.storages.player) > 0 then
doCreatureSetStorage(cid, configSwimmingEvent.storages.player, -1)
doCreatureSetNoMove(cid, false)
doRemoveCondition(cid, CONDITION_INFIGHT)
end
end
doBroadcastMessage('Swimming Event hasn\'t started beacuse there were not enough players.')
end
doSetStorage(configSwimmingEvent.storages.joining, -1)
end
function doCountPlayersSwimmingEvent()
local x = 0
for _, cid in ipairs(getPlayersOnline()) do
if getCreatureStorage(cid, configSwimmingEvent.storages.player) > 0 then
x = x + 1
end
end
return x
end
function doStartCountingSwimmingEvent(x)
if configSwimmingEvent.delayTime-x > 0 then
doBroadcastMessage('Swimming Event is going to start in '..configswimmingEvent.delayTime-x..' minutes. You can join to the event by saying "!swimming join".')
addEvent(doStartCountingSwimmingEvent, 60*1000, x+1)
end
end
function doCheckSpeedSwimmingEvent()
if doCountPlayersSwimmingEvent() > 0 then
addEvent(doCheckSpeedSwimmingEvent, 1000)
end
for _, cid in ipairs(getPlayersOnline()) do
if getCreatureStorage(cid, configSwimmingEvent.storages.player) > 0 then
if getCreatureSpeed(cid) ~= configSwimmingEvent.players.speed then
doChangeSpeed(cid, (getCreatureSpeed(cid) < configSwimmingEvent.players.speed and configSwimmingEvent.players.speed - getCreatureSpeed(cid) or getCreatureSpeed(cid) > configSwimmingEvent.players.speed and - (getCreatureSpeed(cid) - configSwimmingEvent.players.speed)))
end
end
end
end
]]>
</lib>
<talkaction words="!swimming" event="script">
<![CDATA[
domodlib("config_swimming_event")
function onSay(cid, words, param)
if getStorage(configSwimmingEvent.storages.joining) ~= 1 then
return doPlayerSendCancel(cid, 'The Swimming Event hasn\'t started yet.')
elseif param == '' then
return doPlayerSendCancel(cid, 'Command param required (say: "!swimming join" or "!swimming leave.").')
elseif getPlayerLevel(cid) < configSwimmingEvent.players.minLevel then
return doPlayerSendCancel(cid, 'You can\'t join to the event if you don\'t have a require '..configSwimmingEvent.players.minLevel..' level.')
elseif getTileInfo(getThingPos(cid)).protection ~= true then
return doPlayerSendCancel(cid, 'You can\'t join to the event if you aren\'t in protection zone.')
elseif exhaustion.check(cid, configSwimmingEvent.storages.exhaust) ~= false then
return doPlayerSendCancel(cid, 'You must wait '..exhaustion.get(cid, configSwimmingEvent.storages.exhaust)..' seconds to use this command again.')
end
if param == 'join' then
if getCreatureStorage(cid, configSwimmingEvent.storages.player) > 0 then
return doPlayerSendCancel(cid, 'You have arleady joined to event. Wait patiently for start.')
elseif doCountPlayersSwimmingEvent() == configSwimmingEvent.players.max then
return doPlayerSendCancel(cid, 'Max players in the event have been reached.')
end
doCreatureSetNoMove(cid, true)
doPlayerPopupFYI(cid, configSwimmingEvent.text)
doCreatureSetStorage(cid, configSwimmingEvent.storages.player, 1)
doAddCondition(cid, createConditionObject(CONDITION_INFIGHT, -1))
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'You have joined to Swimming Event. You can\'t move until event don\'t start. Wait patiently for the event start.')
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'You have joined to Swimming Event.')
elseif param == 'leave' then
if getCreatureStorage(cid, configSwimmingEvent.storages.player) <= 0 then
return doPlayerSendCancel(cid, 'You can\'t leave from the event if you don\'t join.')
end
doCreatureSetNoMove(cid, false)
doCreatureSetStorage(cid, configSwimmingEvent.storages.player, -1)
doRemoveCondition(cid, CONDITION_INFIGHT)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'You have left from the Swimming Event.')
end
exhaustion.set(cid, configSwimmingEvent.storages.exhaust, 5)
return true
end
]]>
</talkaction>
<talkaction words="!startswimming" access="5" event="script">
<![CDATA[
domodlib("config_swimming_event")
domodlib("lib_swimming_event")
function onSay(cid, words, param)
doSetStorage(configSwimmingEvent.storages.joining, 1)
addEvent(doStartEventSwimming, configSwimmingEvent.delayTime * 60 * 1000)
doStartCountingSwimmingEvent(0)
for _, pid in ipairs(getPlayersOnline()) do
if getCreatureStorage(pid, configSwimmingEvent.storages.player) > 0 then
doCreatureSetStorage(pid, configSwimmingEvent.storages.player, -1)
doPlayerSetGroupId(pid, getCreatureStorage(pid, configSwimmingEvent.storages.group))
doChangeSpeed(pid, getCreatureBaseSpeed(pid) - configSwimmingEvent.players.speed)
doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)), true)
end
end
return true
end
]]>
</talkaction>
<movement type="StepIn" actionid="5467" event="script">
<![CDATA[
domodlib("config_swimming_event")
function onStepIn(cid, item, position)
if getCreatureStorage(cid, configSwimmingEvent.storages.player) > 0 then
local prize = math.random(#configSwimmingEvent.rewards)
doCreatureSetStorage(cid, configSwimmingEvent.storages.player, -1)
doPlayerAddItem(cid, configSwimmingEvent.rewards[prize], 1)
doChangeSpeed(cid, getCreatureBaseSpeed(cid) - configSwimmingEvent.players.speed)
doPlayerSetGroupId(cid, math.max(1, getCreatureStorage(cid, configSwimmingEvent.storages.group)))
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), true)
doBroadcastMessage('Swimming Event has finished. The winner is '..getCreatureName(cid)..'.')
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'You are winner. You have won '..getItemNameById(configSwimmingEvent.rewards[prize])..'.')
db.query("INSERT INTO `events` (`event_name`, `winner_name`, `won_item`, `time_win`) VALUES (\"Swimming\", \"" .. getCreatureName(cid) .. "\", \"" .. getItemNameById(configSwimmingEvent.rewards[prize]) .. "\", " .. getStorage(configSwimmingEvent.storages.countEvent) ..");")
doSetStorage(configSwimmingEvent.storages.countEvent, getStorage(configSwimmingEvent.storages.countEvent) + 1)
for _, pid in ipairs(getPlayersOnline()) do
if getCreatureStorage(pid, configSwimmingEvent.storages.player) > 0 then
doCreatureSetStorage(pid, configSwimmingEvent.storages.player, -1)
doPlayerSetGroupId(pid, math.max(1, getCreatureStorage(pid, configSwimmingEvent.storages.group)))
doChangeSpeed(pid, getCreatureBaseSpeed(pid) - configSwimmingEvent.players.speed)
doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)), true)
doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, 'You loss.')
end
end
end
return true
end
]]>
</movement>
<globalevent name="Swimming_Event_Days" interval="1000" event="script">
<![CDATA[
domodlib("config_swimming_event")
domodlib("lib_swimming_event")
local daysOpen = {}
for k, v in pairs(configSwimmingEvent.days) do
table.insert(daysOpen, k)
end
function onThink(interval)
if isInArray(daysOpen, os.date("%A")) then
if isInArray(configSwimmingEvent.days[os.date("%A")], os.date("%X", os.time())) then
if getStorage(configSwimmingEvent.storages.joining) ~= 1 then
doSetStorage(configSwimmingEvent.storages.joining, 1)
addEvent(doStartEventSwimming, configSwimmingEvent.delayTime * 60 * 1000)
doStartCountingSwimmingEvent(0)
for _, pid in ipairs(getPlayersOnline()) do
if getCreatureStorage(pid, configSwimmingEvent.storages.player) > 0 then
doCreatureSetStorage(pid, configSwimmingEvent.storages.player, -1)
doPlayerSetGroupId(pid, math.max(1, getCreatureStorage(pid, configSwimmingEvent.storages.group)))
doChangeSpeed(pid, getCreatureBaseSpeed(pid) - configSwimmingEvent.players.speed)
doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)), true)
end
end
end
end
end
return true
end
]]>
</globalevent>
<event type="login" name="Swimming_Event_Login" event="script">
<![CDATA[
domodlib("config_swimming_event")
function onLogin(cid)
if getCreatureStorage(cid, configSwimmingEvent.storages.player) > 0 then
doCreatureSetStorage(cid, configSwimmingEvent.storages.player, -1)
doPlayerSetGroupId(cid, math.max(1, getCreatureStorage(cid, configSwimmingEvent.storages.group)))
doCreatureSetNoMove(cid, false)
doRemoveCondition(cid, CONDITION_INFIGHT)
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), true)
end
return true
end
]]>
</event>
<globalevent name="Swimming_Event_Start" type="startup" event="script">
<![CDATA[
domodlib("config_swimming_event")
function onStartup()
doSetStorage(configSwimmingEvent.storages.joining, -1)
return true
end
]]>
</globalevent>
</mod>