Your initial script has some oddities (regarding variable scope). Hmm, I see a few things you'd probably to worry about with the proposed solution:
A player can do multiple auto announces.
There is no way of tracking the active announcements.
Once the auto announce is bought, it is fully detached from the player and cannot be linked back to him.
The announces will get lost on script reload/server reboots. You'd probably want to use global arrays and have the announces displayed with a OnTimer1000 checks instead.
With that being said, the following is probably what you're looking for. I personally prefer to have the loop on a separate event, but the end result is very similar in this case.
prontera,187,210,3 script Broadcaster#1::BC 894,{
.@npcname$ = "^FF9300 Broadcaster ^000000";
.@header$ = "[^0000ff" + .@npcname$ + "^000000]";
mes .@header$;
mes "Hi, I'm the Broadcaster.";
mes "I can Broadcast a message for you.";
mes " ";
mes " ";
mes " ";
mes "It costs ^ff0000" + .broadcastfee + "^000000 zeny.";
next;
mes .@header$;
mes "Would you like to Broadcast?";
next;
switch (select("Yes:Nevermind:Auto-broadcast")) {
case 1:
if (Broadcast > gettimetick(2)) {
mes .@header$;
mes "Sorry you have to wait for 1 min.";
close;
}
if (Zeny < .broadcastfee) {
goto L_NotEnoughZeny;
}
mes .@header$;
mes "Please input your message.";
next;
input .@broadcast$;
Zeny -= .broadcastfee;
announce "Shout from " + strcharinfo(0) + ": " + .@broadcast$ + "", 0, 0x5AFF00; // Edit 5AFF00 for color code HTML Color Code
Broadcast = gettimetick(2) + 60; //Timer 60 = 1 minute/s
dispbottom "Broadcaster: Please wait for 1min until next broadcast to avoid flooding.";
end;
case 2:
mes .@header$;
mes "Suit yourself.";
close;
case 3:
mes .@header$;
mes "Hi, I can automatically broadcast messages for you!";
mes "It will cost you ^ff0000" + .auto_broadcastfee + "^000000 zeny per broadcast.";
next;
switch(select("Proceed:Check status:Exit")) {
case 1:
mes .@header$;
mes "Please input your message.";
next;
input .@broadcast$;
mes .@header$;
mes "How many times do you want to broadcast?";
mes "Min: 1";
mes "Max: 100";
next;
input .@repeat, 1, 100;
if (.@repeat < 1 || .@repeat > 100) {
mes .@header$;
mes "Suit yourself.";
close;
}
.@cost = .auto_broadcastfee * .@repeat;
mes .@header$;
mes "You want to broadcast:";
mes "^ff0000" + .@broadcast$ + "^000000";
mes "Every 3 minutes for ^00ff00" + .@repeat + "^000000 time(s)?";
mes "It will cost you a total of ^ff0000" + .@cost + "^000000 zeny.";
next;
switch(select("Proceed:Cancel")) {
case 2:
mes .@header$;
mes "Suit yourself.";
close;
}
if (Zeny < .@cost) {
goto L_NotEnoughZeny;
}
Zeny -= .@cost;
$@bc_announce$ = "Shout from " + strcharinfo(0) + ": " + .@broadcast$;
$@repeat = .@repeat;
donpcevent strnpcinfo(3) + "::OnAutoAnnounce";
close;
case 2:
// ??
end;
case 3:
mes .@header$;
mes "Suit yourself.";
close;
}
close;
}
end;
L_NotEnoughZeny:
mes .@header$;
mes "You don't have enough zeny.";
close;
OnAutoAnnounce:
.@repeat = $@repeat;
.@broadcast$ = $@bc_announce$;
while (.@repeat > 0) {
announce .@broadcast$, 0, 0x5AFF00; // Edit 5AFF00 for color code HTML Color Code
sleep 180000;
.@repeat--;
}
end;
OnInit:
.broadcastfee = 3000000;
.auto_broadcastfee = 500000;
end;
}