In lines 140 and 145 you\'re missing parentheses.
they should be
if ($istok(%TicketsBought,%Lottery,32)) {
and
if (!$istok(%TicketsBought,%Lottery,32)) {
edit: (it\'s under the alias lotterydraw btw...I just noticed they don\'t have line numbers here xD)
besides from that, everything seems to be working, thanks a lot!