-
Notifications
You must be signed in to change notification settings - Fork 9
/
poll_system.xml
59 lines (59 loc) · 2.32 KB
/
poll_system.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
59
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Poll System" enabled="yes">
<config name="polls"><![CDATA[
config = {
timeToEnd = 120 -- seconds
}
]]></config>
<talkaction words="!poll" event="script"><![CDATA[
domodlib("polls")
local s = config.timeToEnd
local function endPoll()
setGlobalStorageValue(12456, -1) -- poll start
for i = 12457, 12458 do
setGlobalStorageValue(i, 0) -- yes & no votes
end
db.executeQuery("UPDATE `player_storage` SET `value` = -1 WHERE `key` = 12468;")
doBroadcastMessage("The poll has ended.")
end
if not(param == "yes" or param == "no" or param == "end" or param == "") then
if getPlayerGroupId(cid) < 2 then
return doPlayerSendTextMessage(cid, 27, "You don't have access to execute a poll.")
end
if getGlobalStorageValue(12456) > 0 then
return doPlayerSendTextMessage(cid, 27, "Theres a poll already running. Type !poll to end the poll.")
end
doBroadcastMessage("Poll has started with question: " .. param .. "\nType !poll yes to vote with yes\n!poll no to vote with no.")
addEvent(endPoll, s * 1000)
setGlobalStorageValue(12456, 1)
for i = 12457, 12458 do
setGlobalStorageValue(i, 0) -- yes & no votes
end
else
if getGlobalStorageValue(12456) < 1 then
return doPlayerSendTextMessage(cid, 27, "No poll has started.")
end
if param == "end" then
if getPlayerGroupId(cid) < 2 then
return doPlayerSendTextMessage(cid, 27, "You don't have access to end a poll.")
end
return endPoll()
elseif param == "no" then
if getPlayerStorageValue(cid, 12468) == 1 then
return doPlayerSendTextMessage(cid, 27, "You have already voted.")
end
setPlayerStorageValue(cid, 12468, 1)
setGlobalStorageValue(12458, getGlobalStorageValue(12458)+1)
elseif param == "yes" then
if getPlayerStorageValue(cid, 12468) == 1 then
return doPlayerSendTextMessage(cid, 27, "You have already voted.")
end
setPlayerStorageValue(cid, 12468, 1)
setGlobalStorageValue(12457, getGlobalStorageValue(12457)+1)
end
doBroadcastMessage(getCreatureName(cid) .. " has voted with a " .. (param == "yes" and "Yes" or "No") .. "!", 20)
doBroadcastMessage("Current votes:\nYes: " .. getGlobalStorageValue(12457) .. "\nNo: " .. getGlobalStorageValue(12458) .. "\n120 seconds to end.", 20)
end
return true
]]></talkaction>
</mod>