• 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!

TalkAction [8.0]Poll system(Forgotten Server & Evolutions)

Delirium

OTLand veteran
Staff member
Global Moderator
Joined
May 28, 2007
Messages
3,365
Solutions
1
Reaction score
289
Location
Athens, Greece
Welcome.This is a talk action.With this script if you are a gamemaster or higher you can make your own polls on the server you play.

Let's start

First add this to data/talkactions/lib/talkactions.lua


Code:
function exhaust(cid, storevalue, exhausttime)
-- Exhaustion function by Alreth, v1.1 2006-06-24 01:31
-- Returns 1 if not exhausted and 0 if exhausted
    
    newExhaust = os.time()
    oldExhaust = getPlayerStorageValue(cid, storevalue)
    if (oldExhaust == nil or oldExhaust < 0) then
        oldExhaust = 0
    end
    if (exhausttime == nil or exhausttime < 0) then
        exhausttime = 1
    end
    diffTime = os.difftime(newExhaust, oldExhaust)
    if (diffTime >= exhausttime or diffTime < 0) then
        setPlayerStorageValue(cid, storevalue, newExhaust) 
        return 1
    else
        return 0
    end
end

This will make the exhaustion in the script works perfectly

For evolutions:

save this as poll.lua in data/talkactions/scripts

Code:
local ActiveValue = 666
local YesValue = 1000
local NoValue =  2000
local ExhaustTime = 6000000 --- Time (in minutes) that the player will have to wait 'till he can vote again Default = 10min
local AutoEnd = true ---Use Auto End (set true or false)
local ToEnd = 1000*60*10 -- Time to auto-end poll (in miliseconds) Default = 10min
local WriteBook = false --- Write a book with the results (true or false)

function onSay(cid, words, param)
	if words == '!makepoll' then	
		if getPlayerAccess(cid) >= 3 then
			if getGlobalStorageValue(ActiveValue) ~= 1 then
				if param ~= nil then
					doPlayerSay(cid,'Poll: '..param..'',9)
					setGlobalStorageValue(YesValue,0)
					setGlobalStorageValue(NoValue,0)
					setGlobalStorageValue(ActiveValue,1)
					if AutoEnd == true then
						addEvent(EndPoll,ToEnd,cid)
					end
				end
			else
				doPlayerSendTextMessage(cid,22,'A poll is already running.')
			end
		else
			doPlayerSendCancel(cid,'Only Gamemasters can make a poll')
		end
	elseif words == '!vote' and getGlobalStorageValue(ActiveValue) == 1 and exhaust(cid,500,ExhaustTime) == 1 then
		if param == 'yes' then
			setGlobalStorageValue(YesValue,getGlobalStorageValue(YesValue)+1)
			doPlayerSendTextMessage(cid,22,'Thanks for your vote.')
		elseif param == 'no' then
			setGlobalStorageValue(NoValue,getGlobalStorageValue(NoValue)+1)
			doPlayerSendTextMessage(cid,22,'Thanks for your vote.')
		else
			doPlayerSendTextMessage(cid,22,'Use only !vote "yes or !vote "no.')
		end			
	elseif words == '!endpoll' then
		if getPlayerAccess(cid) >= 3 then 
			if getGlobalStorageValue(ActiveValue) == 1 then
				setGlobalStorageValue(ActiveValue,2)
				doSetItemText(doPlayerAddItem(cid,1984,1),'The results are: Yes: '..getGlobalStorageValue(YesValue)..', No: '..getGlobalStorageValue(NoValue)..'')
				doPlayerSay(cid,'The poll has ended, thanks for your votes.',9)
			else
				doPlayerSendCancel(cid,'There is no poll running.')
			end
		else
			doPlayerSendCancel(cid,'Only Gamemasters can end polls')
		end
	end
end

function EndPoll(cid)
if getGlobalStorageValue(ActiveValue) == 1 then
setGlobalStorageValue(ActiveValue,2)
doPlayerSay(cid,'The poll has ended, thanks for your votes.',9)
if WriteBook == true then
doSetItemText(doPlayerAddItem(cid,1984,1),'The results are: Yes: '..getGlobalStorageValue(YesValue)..', No: '..getGlobalStorageValue(NoValue)..'')
end
print('The results are: Yes = '..getGlobalStorageValue(YesValue)..', No = '..getGlobalStorageValue(NoValue)..'')
else
print('No polls running')
end
end

For The Forgotten Server:
Code:
-- Created by Nikolas1994<>Optimized by Talaturen
-- Visit http://otland.net
-- 22:25 CET >> 2007-08-07
local activeValue = 666 -- Storage value of active poll
local yesValue = 1000 -- Storage value of yes votes
local noValue =  2000 -- Storage value of no votes
local exhaustTime = 6000000 -- Time in minutes that the player will have to wait before gaining ability to vote again (Default: 10 minutes)
local autoEnd = TRUE -- Auto ending poll (TRUE or FALSE)
local toEnd = 1000 * 60 * 10 -- Time until poll will auto end in miliseconds (Default: 10 minutes)
local writeBook = FALSE -- Write a book with the results (TRUE or FALSE)
function onSay(cid, words, param)
	if words == "!makepoll" then
		if getPlayerGroupId(cid) > 3 then
			if getGlobalStorageValue(activeValue) ~= TRUE then
				if param ~= "" then
					broadcastMessage("Poll: " .. param)
					setGlobalStorageValue(yesValue, 0)
					setGlobalStorageValue(noValue, 0)
					setGlobalStorageValue(activeValue, 1)
					if autoEnd == TRUE then
						addEvent(endPoll, toEnd, cid)
					end
				end
			else
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "There is already a poll running.")
			end
		else
			doPlayerSendCancel(cid, "Only gamemasters may create a poll.")
		end
	elseif getGlobalStorageValue(activeValue) == TRUE then
		if words == "!vote" then
			if exhaust(cid, 500, exhaustTime) == TRUE then
				if param == "yes" then
					setGlobalStorageValue(yesValue, getGlobalStorageValue(yesValue) + 1)
					doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Thanks for your vote.")
				elseif param == "no" then
					setGlobalStorageValue(noValue, getGlobalStorageValue(noValue) + 1)
					doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Thanks for your vote.")
				else
					doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Invalid command parameter, use 'yes' or 'no'.")
				end
			end
		elseif getPlayerGroupId(cid) > 3 then
			setGlobalStorageValue(activeValue, 2)
			doSetItemText(doPlayerAddItem(cid, 1984, 1), "The results are...\n\nYes: " .. getGlobalStorageValue(yesValue) .. "\nNo: " .. getGlobalStorageValue(noValue))
			broadcastMessage("The poll has ended, thanks for your votes.")
		else
			doPlayerSendCancel(cid, "Only gamemasters may end running polls.")
		end
	else
		doPlayerSendCancel(cid, "There is no poll running.")
	end
end

function endPoll(cid)
	if getGlobalStorageValue(activeValue) == TRUE then
		setGlobalStorageValue(activeValue, 2)
		broadcastMessage("The poll has ended, thanks for your votes.")
		if writeBook == TRUE then
			doSetItemText(doPlayerAddItem(cid, 1984, 1), "The results are, yes: " .. getGlobalStorageValue(yesValue) .. ", no: " .. getGlobalStorageValue(noValue))
		end
		print("The results are, yes: " .. getGlobalStorageValue(yesValue) .. ", no: " .. getGlobalStorageValue(noValue))
	end
end

And then

in talkactions.xml add the following code


Code:
<talkaction words="!makepoll" script="poll.lua" />
<talkaction words="!vote" script="poll.lua" />
<talkaction words="!endpoll" script="poll.lua" />


Credits:
Evolutions script: Nikolas1994
Forgotten Server Script: Nikolas1994,Talaturen
Comments please :D
 
Last edited by a moderator:
RE: [7.92] Release<>Poll system with talk actions.

Nice for other server then The Forgotten Server because TFS has it already hardcoded:p btw I found a typo : This will make the exhaustion in the script works prfectly
 
RE: [7.92] Release<>Poll system with talk actions.

Thanks for this master-m and thanks gooden too
 
RE: [Talkaction][7.92]Poll system

@NIK...

Nice exausted XDBut is possible fix it to only give exausted if player type the correct command?

EX: Give exausted only if the player type !vote "yes or !vote "no , cause if you type !vote "wrong or only !vote you will get the exasuted without voted :( and you cant will vote again :(

Try fix it plz
 
RE: [Talkaction][7.92]Poll system

<talkaction words="!makepoll" script="poll.lua" />
<talkaction words="!vote" script="poll.lua" />
<talkaction words="!endpoll" script="poll.lua" />

It would be like?:
!makepoll Do you want to eat a cookie?
!vote yes or !vote no?
:S:S
 
RE: [Talkaction][7.92]Poll system

mamon_2 said:
<talkaction words="!makepoll" script="poll.lua" />
<talkaction words="!vote" script="poll.lua" />
<talkaction words="!endpoll" script="poll.lua" />

It would be like?:
!makepoll Do you want to eat a cookie?
!vote yes or !vote no?
:S:S

!makepoll "Do you want to eat a cookie
!vote "Yes
!vote "No
 
RE: [Talkaction][7.92]Poll system

It works for 8.0 too :) Good work!
 
RE: [Talkaction][7.92]Poll system

This isnt perfectly useful, :/ i have a website with it built in.. but if u could make a website.. that saved results.. nd displayed past polls and such (much like Rl tibias)
 
RE: [Talkaction][7.92]Poll system

Nice, simple to vote in game.

Will it work for 8.0 as well?
 
Back
Top