Hi i need help putting a limit on how many tickets a user can buy. For ex. they buy 10 tickets but they can continue to use the command to buy more i need it so that 10 tickets is the maximum tickets they can buy. thanks in advance
on *:TEXT:!buytickets &:#:{
if (%raffle == 1) {
if ($2 > 10) {
msg $chan Sorry $nick but you can only buy up to 10 tickets. }
if ($2 < 11) {
var %i = 0
var %ticket = $2
var %topic = $+(#,.,$nick)
var %user = $readini(Points.ini,%topic,Points)
var %end = 10 * %ticket
var %delete = %user - %end
if (%delete > 0) {
writeini -n Points.ini %topic Points %delete
while (%i < %ticket) {
write Raffle.txt $nick
%i = %i + 1
}
msg $chan $nick you have bought %ticket tickets with %end points!
}
}
}
if (%raffle == 0) {
msg $chan $nick tickets are unavailable!
}
}
on *:TEXT:!raffle &:#:{
if ($nick == HeyThatsMatthew) {
if ($2 == open) {
msg $chan Raffle is now open use !buytickets (amount) to purchase raffle tickets!!
set %raffle 1
write -c Raffle.txt
}
if ($2 == close) {
msg $chan Thanks for Participating in the Raffle! Congrats to the Winner!
set %raffle 0
write -c Raffle.txt
}
}
}
on *:TEXT:!winner:#:{
if ($nick == HeyThatsMatthew) {
if (%raffle == 1) {
var %user = $read(Raffle.txt, n)
msg $chan Winner is being chosen, Good Luck!!
.timerOne 1 1 msg $chan /me 3!
.timerTow 1 2 msg $chan /me 2!
.timerThree 1 3 msg $chan /me 1!
.timerFour 1 4 msg $chan And the Winner is...
.timerFive 1 5 msg $chan %user
set %raffle 0
write -c Raffle.txt
}
}
}
Well there are two ways to approach this. The first is to create a variable or line in a text file which will keep track of the number of tickets per nick or address. So for instance, if I buy 5 the first time, you create a variable or line in a file of "Martyr2 5" and then when I come and again (let's say 10 this time), you read the line for my given nick, read in the 5, subtract it from 10 and see that I can't buy 10 because that would be over the limit. Now if I bought only 2 the second time, you would read in the five, add the 2, see that is below my 10 limit and add the 2 to my nick in the file making it "Martyr2 7". Now obviously if the person changes their nick or address they would be allowed to buy more again.
A second less efficient choice would be to write my nick/address to a file 5 times. If I go to buy more again I would just count the number of times my nick is in your raffle.txt and subtract that from 10 to know if I can buy more.
Either way, you have to keep a running sum for each nick/address of how many tickets they have bought and are trying to buy now. That is all there is to it. :)
I know its late but thank you for offering your help so where and how would i put the calc function