ID:155500
 
//a new data type, representing a vote
vote
//number of vote datums that have been created
var/global/numvotes = 0
//id of this vote, to ensure old links don't work
var/id
//whether or not votes are announced:
var/secret = 0
//list containing the valid options for voting:
var/list/options = list()
//associative list of keys who have voted, along with their votes
var/list/votes = list()

//initialize the vote object properly
New()
..()
//we need to keep track of which vote this is, as old links will point to new votes
id = "[numvotes]"
numvotes++

//this is the proc that will handle link clicks
Topic(href, href_list[])
//ensure the id of the link and this vote object match
if(href_list["id"] != id)
return
//get the key of the client who is voting
var/voter = usr.key
//get their vote
var/vote = href_list["vote"]
//ensure that it's a valid vote
if(!(vote in options))
usr << "That is not a valid option!"
return
//(this should only happen if the player is intentionally attempting to mess with the vote)

//check to see if they've already voted
if(votes.Find(voter))
//they've voted the same thing twice
if(vote == votes[voter])
usr << "You've already voted \"[vote]\"!"
//changing vote
else
usr << "You change your vote to \"[vote]\""
if(!secret)
world << "[voter] changed their vote to \"[vote]\""
//new vote
else
usr << "You vote \"[vote]\""
if(!secret)
world << "[voter] votes \"[vote]\""

//register the vote
votes[voter] = vote

//to start the vote:
proc/startVote(var/query, var/list/options, var/duration = 600, var/secret = 0)
src.options = options
src.secret = secret

//announce the vote
world << "A vote has been started:"
//announce the query
world << query
//announce the options
var/n = 0
for(var/option in options)
n++
world << "[n]) <a href='?src=\ref[src];id=[id];vote=[option]'>\"[option]\"</a>"
world << "The vote will end in [duration/10] seconds."

//wait for people to vote
sleep(duration)

//tally the results
var/list/results = options.Copy()
//initialize the list properly
for(var/option in results)
results[option] = 0
//go through the votes
for(var/voter in votes)
//get their vote
var/vote = votes[voter]
//add their vote to the results
results[vote]++

//now we have to loop through the results to find the winner (sigh)
//we'll display the votes as we go along, though
var/winner = ""
var/winningvotes = 0
world << "The vote has ended!"
world << query
for(var/vote in results)
world << "[results[vote]]: \"[vote]\""
//check if it's the winner so far
if(results[vote] > winningvotes)
//note: a tie is resolved by the vote that is presented first winning
winner = vote
winningvotes = results[vote]
world << "The consensus is \"[winner]\""

//finally, return the results of the vote:
return winner

//This proc will create a vote object and use it to start a vote, then return the result of it
proc/startVote(var/query, var/options, var/duration = 600, var/secret = 0)
var/vote/v = new()
var/result = v.startVote(query, options, duration, secret)
del(v)
return result
How about you post a question as well?
In response to Stephen001
u know the question..
In response to Gokussj22
No, I don't. That looks like a system for a few admin functions. Quite thoroughly documented too. What's the question?
In response to Stephen001
i have used that code in my game..and got no compiling error...but the verbs are not usable in the game
In response to Gokussj22
Alright .... and who should be able to access them? How should they be able to access them (verb panel, interface elements, browser control)?

I would've figured if you'd managed to program that code snippet provided, exposing them to a player would not be that difficult for you.
In response to Stephen001
i want it in a tab..actually i wana make an automatic system for my game..in which GM's r not needed so its a fun balanced game
In response to Gokussj22
Those are .... two very different things.

It's pretty apparent you're not going to at least put the effort in on your end to express what you want to do, your capability, and what you currently have. As this is the second such topic from you, I'm banning you for a week to cool off and think about how you approach getting help on these forums.

The other posters here would love to see you make a game. Emphasis on you, there, not them. Do not take advantage of their kindness.