//-------------------------- /////
////Voting System - by ClouD /////
//--------------------------

[DEFNAME voting_sys]
voting_locked_msg @04ea Voting locked.
voting_finished_msg @04ea,3 Poll : Voting finished.

[ITEMDEF i_enquete_stone]
NAME=Polls
ID=i_gravestone_7
TYPE=t_normal

ON=@Create
TAG.ENQUETE.UID=0
tag.ultimovoto=[nobody]
TAG.ENQUETE.TRANCADA=1
TAG.ULTIMODIA=0
COLOR=0556
ATTR=attr_static|attr_decay

ON=@Dclick
IF (<SRC.ISGM>)
SDIALOG d_votacao 1
ELSE
IF (<TAG0.ENQUETE.TRANCADA>)
SRC.SYSMESSAGE <def.voting_locked_msg>
ELIF (<SRC.ACCOUNT.TAG0.ENQUETE.UID>==<TAG0.ENQUETE.UID>)
SDIALOG d_votacao 4
ELSE
SDIALOG d_votacao 3
ENDIF
ENDIF
RETURN 1

ON=@TIMER
IF (<RTIME.DAY>==<TAG0.ULTIMODIA>)
local.1=<EVAL <MORE1>*100>
local.2=<eval <MORE1>+<MORE2>>
local.3=<eval <MORE2>*100>
SERV.B <def.voting_finished_msg>
IF (<MORE1> > <MORE2>)
SERV.B @04ea,3 Winner : <TAG0.RESP1> (<EVAL <MORE1>> votos)
VAR.ENQUETE.PAGE1=Winner : <TAG0.RESP1> (<EVAL <MORE1>> [<EVAL <local.1>/<local.2>>%] votes)
ELIF (<MORE2> > <MORE1>)
SERV.B @04ea,3 Winner : <TAG0.RESP2> (<EVAL <MORE2>> votos)
VAR.ENQUETE.PAGE1=Winner : <TAG0.RESP2> (<EVAL <MORE2>> [<EVAL <local.3>/<local.2>>%] votes)
ELIF (<MORE2>==<MORE1>)
SERV.B @04ea,3 Draw! Each one with <dMORE1> votes.
VAR.ENQUETE.PAGE1=Draw! Each one with <dMORE1> votes.
ENDIF
VAR.ENQUETE.PAGE2=<TAG0.ENQUETE>
TAG.RESP1=0
TAG.RESP2=0
TAG.ULTIMODIA=0
TAG.ENQUETE.TRANCADA=1
tag.ultimovoto=[nobody]
MORE1=0
MORE2=0
ELSE
TIMER=10
ENDIF
RETURN 1

[DIALOG d_votacao]
200,120
SRC.CLOSEALLDIALOGS
PAGE 1
resizepic 20 0 5054 500 363
gumppictiled 29 10 481 20 2624
gumppictiled 29 38 481 120 2624
gumppictiled 29 335 481 20 2624
gumppictiled 47 245 443 75 2624
checkertrans 29 10 481 345
dtext 33 10 1152 Poll system - <SERV.SERVNAME> Shard
dhtmlgump 108 335 481 120 0 0 <DEF.BFONT_lGRAY> <SERV.RTIME><DEF.BONTE>
dhtmlgump 35 38 475 120 0 1 <DEF.BFONT_SIZE7><DEF.CENTER>Current Poll<DEF.CENTERE><DEF.BR><DEF.BFONT_SIZE4><DEF.BFONT_lGRAY><TAG0.ENQUETE><DEF.BRE>
local.1=<EVAL <MORE1>*100>
local.2=<eval <MORE1>+<MORE2>>
local.3=<eval <MORE2>*100>
IF (<MORE1>!=0)
dtext 40 160 1152 Answer 1: <EVAL <local.1>/<local.2>>% (<dMORE1> votes)
ELSE
dtext 40 160 1152 Answer 1: 0% (<dMORE1> votes)
ENDIF
IF (<MORE2>!=0)
dtext 40 180 1152 Answer 2: <EVAL <local.3>/<local.2>>% (<dMORE2> votes)
ELSE
dtext 40 180 1152 Answer 2: 0% (<dMORE2> votes)
ENDIF
dtext 270 160 1152 Poll ends on day: <dTAG0.ULTIMODIA>
dtext 270 180 1152 Last vote by <tag0.ultimovoto>
dtext 40 200 1152 Total votes: <EVAL <MORE1>+<MORE2>>
dtext 270 200 1152 Total polls ever made: <dtag0.enquete.uid>
button 33 230 093A 0939 1 0 2
IF !(<TAG0.ENQUETE.TRANCADA>)
dhtmlgump 51 225 400 50 0 0 <DEF.BFONT_WHITE>Lock the poll, prohibit players to vote.
ELSE
dhtmlgump 51 225 400 50 0 0 <DEF.BFONT_WHITE>Unlock the poll, players will be able to vote normally.
ENDIF
button 33 250 093A 0939 1 0 1
dtextentry 51 245 435 75 1000 0 Put the new poll here.

PAGE 2
resizepic 20 0 5054 500 383
gumppictiled 29 10 481 20 2624
gumppictiled 29 38 481 120 2624
gumppictiled 29 355 481 20 2624
gumppictiled 47 165 443 75 2624
gumppictiled 47 245 443 75 2624
gumppictiled 160 325 30 20 2624
checkertrans 29 10 481 365
dtext 33 10 1152 Poll system - <SERV.SERVNAME> Shard
dhtmlgump 108 245 481 120 0 0 <DEF.BFONT_lGRAY> <SERV.RTIME><DEF.BONTE>
dhtmlgump 35 38 475 120 0 1 <DEF.BFONT_SIZE7><DEF.CENTER>Poll text<DEF.CENTERE><DEF.BR><DEF.BFONT_SIZE4><DEF.BFONT_lGRAY><TAG0.ENQUETE><DEF.BRE>
dtextentry 51 165 435 75 1000 1 Put answer 1 here.
dtextentry 51 245 435 75 1000 2 Put answer 2 here.
dtext 33 325 1152 Poll ends on day:
dtextentry 163 325 20 15 1000 3
button 415 328 02eec 02eed 1 0 3

PAGE 3
resizepic 20 0 5054 500 335
gumppictiled 29 10 481 20 2624
gumppictiled 29 38 481 120 2624
gumppictiled 29 166 236 110 2624
gumppictiled 29 280 236 16 2624
gumppictiled 274 166 236 110 2624
gumppictiled 274 280 236 16 2624
gumppictiled 29 305 481 20 2624
checkertrans 29 10 481 315
dtext 33 10 1152 Poll system - <SERV.SERVNAME> Shard
dhtmlgump 108 305 481 120 0 0 <DEF.BFONT_lGRAY> <SERV.RTIME><DEF.BONTE>
dhtmlgump 35 38 475 120 0 1 <DEF.BFONT_SIZE7><DEF.CENTER>Current Poll<DEF.CENTERE><DEF.BR><DEF.BFONT_SIZE4><DEF.BFONT_lGRAY><TAG0.ENQUETE><DEF.BRE>
dhtmlgump 35 166 230 110 0 1 <DEF.BFONT_lGRAY><TAG0.RESP1>
dhtmlgump 280 166 230 110 0 1 <DEF.BFONT_lGRAY><TAG0.RESP2>
button 100 282 093A 0939 1 0 4
dtext 115 277 1152 Answer 1
button 350 282 093A 0939 1 0 5
dtext 365 277 1152 Answer 2

PAGE 4
resizepic 20 0 5054 500 275
gumppictiled 29 10 481 20 2624
gumppictiled 29 38 481 120 2624
gumppictiled 29 245 481 20 2624
checkertrans 29 10 481 255
dtext 33 10 1152 Poll system - <SERV.SERVNAME> Shard
dhtmlgump 108 245 481 120 0 0 <DEF.BFONT_lGRAY> <SERV.RTIME><DEF.BONTE>
dhtmlgump 35 38 475 120 0 1 <DEF.BFONT_SIZE7><DEF.CENTER>Current Poll<DEF.CENTERE><DEF.BR><DEF.BFONT_SIZE4><DEF.BFONT_lGRAY><TAG0.ENQUETE><DEF.BRE>
dtext 40 160 1152 You have already voted on this poll:
local.1=<EVAL <MORE1>*100>
local.2=<eval <MORE1>+<MORE2>>
local.3=<eval <MORE2>*100>
IF (<MORE1>!=0)
dtext 40 180 1152 Answer 1: <EVAL <local.1>/<local.2>>% (<dMORE1> votes)
ELSE
dtext 40 180 1152 Answer 1: 0% (<dMORE1> votes)
ENDIF
IF (<MORE2>!=0)
dtext 40 200 1152 Answer 2: <EVAL <local.3>/<local.2>>% (<dMORE2> votes)
ELSE
dtext 40 200 1152 Answer 2: 0% (<dMORE2> votes)
ENDIF
dtext 270 180 1152 Poll ends on day: <EVAL <TAG0.ULTIMODIA>>
dtext 270 200 1152 Last vote by <tag0.ultimovoto>
dtext 40 220 1152 Total votes: <EVAL <MORE1>+<MORE2>>
dtext 270 220 1152 Total polls ever made: <dtag0.enquete.uid>

[DIALOG d_votacao BUTTON]
ON=1
TAG.ENQUETE.TRANCADA=1
TAG.ENQUETE=<STRSUB 0 1500 <ARGTXT[0]>>
MORE1=0
MORE2=0
tag.ultimovoto=[nobody]
var.enquete.lastvote=[nobody]
TAG.RESP1=0
TAG.RESP2=0
SDIALOG d_votacao 2
VAR.ENQUETE.PAGE2=<TAG0.ENQUETE>

ON=2
IF !(<TAG0.ENQUETE.TRANCADA>)
TAG.ENQUETE.TRANCADA=1
ELSE
TAG.ENQUETE.TRANCADA=0
ENDIF

ON=3
IF !(<ISNUM <ARGTXT[3]>>) || (<ARGTXT[3]> > 31) || (<ARGTXT[3]>==<RTIME.DAY>)
SRC.SYSMESSAGE @0481 You must type a valid number.
SDIALOG d_votacao 2
ELSE
TAG.RESP1=<STRSUB 0 1200 <ARGTXT[1]>>
TAG.RESP2=<STRSUB 0 1200 <ARGTXT[2]>>
TAG.ULTIMODIA=<STRSUB 0 2 <ARGTXT[3]>>
TAG0.ENQUETE.UID ++
TAG.ENQUETE.TRANCADA=0
MORE1=0
MORE2=0
TIMER=10
VAR.ENQUETE.RESP1=<TAG0.RESP1> (0) (0%)
VAR.ENQUETE.RESP2=<TAG0.RESP2> (0) (0%)
VAR.ENQUETE.LASTDAY=dia <EVAL <TAG.ULTIMODIA>>
ENDIF

ON=4
MORE1 ++
local.1=<EVAL <MORE1>*100>
local.2=<eval <MORE1>+<MORE2>>
VAR.ENQUETE.RESP1=<TAG0.RESP1> (<EVAL <MORE1>>) (<EVAL <local.1>/<local.2>>%)
TAG.ULTIMOVOTO=<SRC.NAME>
var.enquete.lastvote=<SRC.NAME>
SRC.ACCOUNT.TAG.ENQUETE.UID=<TAG0.ENQUETE.UID>

ON=5
MORE2 ++
local.1=<EVAL <MORE2>*100>
local.2=<eval <MORE1>+<MORE2>>
VAR.ENQUETE.RESP2=<TAG0.RESP2> (<EVAL <MORE2>>) (<EVAL <local.1>/<local.2>>%)
TAG.ULTIMOVOTO=<SRC.NAME>
var.enquete.lastvote=<SRC.NAME>
SRC.ACCOUNT.TAG.ENQUETE.UID=<TAG0.ENQUETE.UID>

[EOF]