-
Notifications
You must be signed in to change notification settings - Fork 9
/
stop-watch.xml
58 lines (50 loc) · 2.02 KB
/
stop-watch.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?xml version="1.0" encoding="UTF-8"?>
<mod name="stop-watch" version="1.0" author="slawkens" contact="[email protected]" enabled="yes">
<config name="stop-watch-config"><![CDATA[
messages = "yes" -- display messages when starting or stopping stop watch, fe. "Stop watch started at 12:05:04."?
animation = TEXTCOLOR_YELLOW
storage = 3004 -- storage value used to save stop watch state
limit = -1 -- time limit in seconds (-1 = no limit)
delay = 10 -- how often check if player have still stop watch in his inventory (in seconds, default 10, lower values can slow server)
]]></config>
<action itemid="6091" event="script" override="yes"><![CDATA[
domodlib('stop-watch-config')
local config = {
messages = getBooleanFromString(messages),
animation = animation,
storage = storage,
limit = limit,
delay = delay
}
local function repeatTimer(cid, repeats)
if(not isPlayer(cid) or getPlayerStorageValue(cid, config.storage) ~= 1) then
return
end
if(repeats == 0) then
addEvent(repeatTimer, 1000, cid, repeats + 1)
elseif((config.limit <= 0 or repeats < config.limit) and ((repeats % config.delay ~= 0) or (getPlayerItemCount(cid, 6091) > 0))) then
doSendAnimatedText(getCreaturePosition(cid), repeats, config.animation)
repeats = repeats + 1
addEvent(repeatTimer, 1000, cid, repeats)
else
setRunning(cid, false)
end
end
local function setRunning(cid, running)
setPlayerStorageValue(cid, config.storage, running and 1 or 0)
if(config.messages) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, os.date("Stop-watch " .. (running and "started" or "stopped") .. " at %H:%M:%S."))
end
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
if(getPlayerStorageValue(cid, config.storage) == 1) then
setRunning(cid, false)
return true
end
setRunning(cid, true)
repeatTimer(cid, 0)
return true
end
]]></action>
<item id="6091" name="stopwatch" override="yes"/>
</mod>