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
This will make the exhaustion in the script works perfectly
For evolutions:
save this as poll.lua in data/talkactions/scripts
For The Forgotten Server:
And then
in talkactions.xml add the following code
Credits:
Evolutions script: Nikolas1994
Forgotten Server Script: Nikolas1994,Talaturen
Comments please
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
Last edited by a moderator: