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

TFS 1.2 vote system

Metal Mouth

Developer
Joined
Oct 7, 2015
Messages
55
Reaction score
7
Hello, I am looking for working voting system for TFS 1.2:
/vote question
!yes
!no

Or similiar one.
I'm looking for your help!
 
I won't write the entire system, simply because I can't test it, but I will make an attempt to start it off with a talk action
Code:
local votes = { yes = 19000, no = 19001 }
local hasVoted = 19002

local function msgContains(msg, lookfor)
    for word in msg:gmatch('%a+') do
        if word == lookfor then
            return true
        end
    end
    return false
end

function onSay(player, words, param)
    if player:getStorageValue(hasVoted) < 0 then
        if msgContains(param, 'yes') then
            Game.setStorageValue(votes['yes'], Game.getStorageValue(votes['yes']) + 1)
            player:setStorageValue(hasVoted, 1)
        elseif msgContains(param, 'no') then
            Game.setStorageValue(votes['no'], Game.getStorageValue(votes['no']) + 1)
            player:setStorageValue(hasVoted, 1)
        else
            player:sendTextMessage(MESSAGE_STATUS_WARNING, 'That isn\'t a valid voting option.')
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_WARNING, 'Sorry, you are only allowed to vote once.')
    end
end
Code:
<talkaction words="!vote" separator=" " script="vote.lua" />

Using 1 script you can accomplish either vote, !vote yes or !vote no
 
Last edited:
Back
Top