• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction Advanced poll system whit logs!

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
106
Location
Brazil
  • Author:
    bearpaw.png
  • Tested on: TFS 0.3.6

With this poll system you can:
  • Start a poll and send to all players the result
  • Cancel a poll
  • Use more than 2 opitions
  • Auto message
  • Save logs about the poll
:thumbup:
Add this tags on talkactions.xml:
Code:
<talkaction words="/pmanage" event="script" access="3" value="vote.lua" />
<talkaction words="!poll" event="script" value="vote.lua" />
And the script:
Lua:
---Script by mock the bear
local messageDalay = 60 -- 1 min
local saveLog = true
local options = {
['y'] = {372111,'YES'},
['n'] = {372112,'NO'},
}
function sendm(m)
	if getGlobalStorageValue(372199) == 1 then
		doBroadcastMessage(m,21)
		addEvent(sendm,messageDalay*1000,m)
	end
end
function saveLog(var)
        if not saveLog then return end
	local f = io.open('data/logs/quiz.txt','a+')
	if f then
		f:write(var)
		f:close()
	end
end
function onSay(cid, words, param, channel)  ---Script by mock the bear
	local k = getGlobalStorageValue(372199)
	if words == '!poll' then
		if k == 1 then
			if getPlayerStorageValue(cid,372188) ~= getGlobalStorageValue(372188) then
				if options[param] then
					setGlobalStorageValue(options[param][1],getGlobalStorageValue(options[param][1])+1)
					doPlayerSendTextMessage(cid,25,'Thank by the vote')
					setPlayerStorageValue(cid,372188,getGlobalStorageValue(372188))
				else
					local op = ''
					for i,b in pairs(options) do
						op = op..i..', '
					end
					if op:sub(op:len()-1,op:len()) == ', ' then
						op = op:sub(1,op:len()-2)
					end
					doPlayerSendTextMessage(cid,25,'The options is: '..op)
				end
			else
				doPlayerSendTextMessage(cid,25,'You already voted.')
			end
		end
	elseif getPlayerGroupId(cid) >= 3 then
		if param == 'r' then
			local op = ''
			for i,b in pairs(options) do
				op = op..'['..getGlobalStorageValue(b[1])..'] votes to '..b[2]..'\n'
			end
			doBroadcastMessage('Result!\n'..op..'Poll #'..getGlobalStorageValue(372188)..'',21)
			setGlobalStorageValue(372199,-1)
			saveLog('Result at '..os.date("%d %B %Y %X ", os.time())..' Poll #'..getGlobalStorageValue(372188)..'\n'..op..'\n----------------------------\n')
		elseif param == 'c' then
			doBroadcastMessage('Poll canceled!')
			saveLog('Poll #'..os.time()..' canceled by '..getCreatureName(cid)..'\n----------------------------\n')
		else
			if getGlobalStorageValue(372199,1) ~= 1 then
				local op = ''
				for i,b in pairs(options) do
					op = op..'!poll '..i..' to '..b[2]..'\n'
					setGlobalStorageValue(b[1],0)
				end
				setGlobalStorageValue(372199,1)
				setGlobalStorageValue(372188,os.time())
				saveLog('Poll #'..os.time()..' stsrted by '..getCreatureName(cid)..' at '..os.date("%d %B %Y %X ", os.time())..'\n'..param..'\n')
				sendm('Poll started!\n'..param..'\nSay:\n'..op..'\nPoll #'..os.time()..'')
			else
				doPlayerSendTextMessage(cid,25,'Already is a poll running. Say [/pmanage r] to results and [/pmanage c] to cancel.')
			end
		end
	end
	return true
end
Enjoy
 
Last edited:
Great script...
I think wich you are the best in this area.


And this space? xD
Code:
---Script by mock the bear
[...]
		if k == 1 then
			if getPlayerStorageValue(cid,372188) ~= getGlobalStorageValue(372188) then
				if options[param] then
					setGlobalStorageValue(options[param][1],getGlobalStorageValue(options[param][1])+1)
					doPlayerSendTextMessage(cid,25,'Thank by the vote')
					setPlayerStorageValue(cid,372188,[SIZE="5"][B]getGlobalStorageV  alue[/B][/SIZE](372188))
				else
[...]
Enjoy
 
Last edited:
@JuanC
fu** forum format bugs :S
i have VB 3.8.x code
 
Mock, this is great, but if your add the option for change the question in-game, this is going to be better.
 
Code:
['y'] = {[B][COLOR="Red"]372111[/COLOR][/B],'YES'},
['n'] = {[B][COLOR="Red"]372112[/COLOR][/B],'NO'},

WHAAT?
 
@Joseph15
you say /quiz Do you like high exp?
and player say !vote y
or
!vote n
and the you say /quiz r and see the result
 
Just incase someone wants this for TFS 1.2!

<!-- Gods -->
<talkaction words="/vote" separator=" " script="vote.lua" />

<!-- player talkactions -->
<talkaction words="!yes" script="vote.lua"/>
<talkaction words="!no" script="vote.lua"/>

data/talkactions/scripts/vote.lua
Code:
function vote_clean()
setGlobalStorageValue(9955, 0)
setGlobalStorageValue(2222, 0)
setGlobalStorageValue(2223, 0)
return true
end

function vote_end()
broadcastMessage("Votes on YES - ("..getGlobalStorageValue(2222).."), votes on NO - ("..getGlobalStorageValue(2223)..").")
addEvent(vote_clean, 2000)
return true
end

function onSay(cid, words, param)
local vote_end_time = 60
if getGlobalStorageValue(9955) ~= 1 then
if words == '/vote' then
addEvent(vote_end, vote_end_time * 5000)
broadcastMessage("The question is: "..param..". To vote for YES please use the command \'!yes\', else use the command \'!no\'.")
setGlobalStorageValue(9955, 1)
end
end
if getGlobalStorageValue(9955) == 1 then
if words == '!yes' and getPlayerStorageValue(cid,7236) <= os.time() then
setGlobalStorageValue(2222, getGlobalStorageValue(2222) + 1)
doPlayerSendTextMessage(cid, 19, 'You gave vote in this poll, your voice is YES.')
setPlayerStorageValue(cid,7236, os.time()+(vote_end_time))
elseif words == '!no' and getPlayerStorageValue(cid,7236) <= os.time() then
setGlobalStorageValue(2223, getGlobalStorageValue(2223) + 1)
doPlayerSendTextMessage(cid, 19, 'You gave vote in this poll, your voice is NO.')
setPlayerStorageValue(cid,7236, os.time()+(vote_end_time))
elseif getPlayerStorageValue(cid,7236) >= os.time() then
doPlayerSendTextMessage(cid, 19, "You have already voted in this poll!")
end
else
doPlayerSendTextMessage(cid, 19, "The vote hasn't been started.")
end
return true
end
 
with*
edit: oh my fucking god didnt knew that was a 3+3 years old post
 
Back
Top