Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AnnouncerInterval <- 120000; // Default interval = 2 minutes.
- AnuncioID <- 1;
- AnnouncerTimmer <- null;
- Announcer_Prefix <- "[#B7C7C0][[#0FF195]Announcer[#B7C7C0]] [#27E79B]"
- Announcer_Status <- false;
- Announcer <- {
- function CreateTable()
- {
- QuerySQL( db, "CREATE TABLE IF NOT EXISTS Announcer ( ID NUMERIC, Message TEXT, Owner TEXT )" );
- }
- function AddAnnounce(Message, Owner)
- {
- local GetID = QuerySQL( db, "SELECT * FROM Announcer ORDER BY ID DESC LIMIT 1"), id = 1;
- if( GetSQLColumnData( GetID, 0 ) ) id = ( id + GetSQLColumnData( GetID, 0 ).tointeger() );
- QuerySQL( db, "INSERT INTO Announcer VALUES ( '"+ id +"','" + Message + "', '" + Owner + "' )" );
- }
- function RemoveAnnouncer(id)
- {
- QuerySQL( db, "DELETE FROM Announcer WHERE ID='" + id + "'" );
- Announcer.ReorganizarIDs();
- }
- function ReorganizarIDs()
- {
- local q = QuerySQL( db, "SELECT * FROM Announcer"), i = 1;
- while( GetSQLColumnData( q, 0 ) )
- {
- QuerySQL( db, "UPDATE Announcer SET ID='" + i + "' WHERE ID='" + GetSQLColumnData( q, 0 ) + "'" );
- i++;
- GetSQLNextRow( q );
- }
- }
- function GetAnnounceList(player)
- {
- local q = QuerySQL( db, "SELECT * FROM Announcer"), ann, i = 1;
- while ( GetSQLColumnData( q, 0 ) )
- {
- if ( GetSQLColumnData( q, 1 ) != null)
- {
- ann = true;
- MessagePlayer("[#FE2E64]ID: "+ GetSQLColumnData( q, 0 ) + " Message: "+ GetSQLColumnData( q, 1 ) +" - Author: "+ GetSQLColumnData( q, 2 ), player);
- }
- i++;
- GetSQLNextRow( q );
- }
- if (!ann) MessagePlayer("There are no ads.", player);
- }
- function UpdateInterval(time) //time = minutes
- {
- time = (time * 60000);
- Announcer.StopTimer();
- AnnouncerInterval = time;
- Announcer.StartTimer();
- }
- function StartTimer()
- {
- AnnouncerTimmer = _Timer.Create(this, Announcer.Say, AnnouncerInterval, 0);
- Announcer_Status = true;
- }
- function StopTimer()
- {
- _Timer.Destroy(AnnouncerTimmer);
- Announcer_Status = false;
- }
- function Say()
- {
- local q = QuerySQL( db, "SELECT * FROM Announcer WHERE ID='" + AnuncioID + "'" );
- if(!GetSQLColumnData( q, 1 ))
- {
- if (AnuncioID != 1)
- {
- AnuncioID = 1;
- Announcer.Say();
- }
- else
- {
- Announcer.StopTimer();
- print("There isn't announcements, so the timer has been deactivated.")
- }
- }
- else
- {
- AnuncioID++;
- Message( Announcer_Prefix + GetSQLColumnData( q, 1 ) );
- }
- }
- function GetInterval()
- {
- return (AnnouncerInterval / 60000);
- }
- function Command(text, player)
- {
- local subcommand = GetTok( text, " ", 1 );
- switch ( subcommand.tolower() )
- {
- case "add":
- local Announce = SearchAndReplace(text, "add ","");
- if(Announce != null)
- {
- if(Announcer_Status == false) MessagePlayer("Your announcer is off, you can turn it on using /announcer on", player);
- Announcer.AddAnnounce(Announce, player);
- MessagePlayer("Announce added!", player);
- }
- else MessagePlayer("/announcer add -message-", player)
- break;
- case "remove":
- case "delete":
- local id = GetTok( text, " ", 2 );
- local q = QuerySQL( db, "SELECT * FROM Announcer WHERE ID='"+ id +"'");
- if( GetSQLColumnData( q, 0 ) )
- {
- Announcer.RemoveAnnouncer(id);
- MessagePlayer("Message: "+ GetSQLColumnData( q, 1 ) +" deleted.", player);
- }
- else MessagePlayer("/announcer remove -ID-", player)
- break;
- case "list":
- Announcer.GetAnnounceList(player);
- break;
- case "interval":
- local time = GetTok( text, " ", 2 ).tointeger();
- if (time == 0) MessagePlayer("You cant set interval 0. Reason: It will generate spam.", player);
- else
- {
- Announcer.UpdateInterval(time);
- MessagePlayer("Interval updated!", player);
- }
- break;
- case "on":
- Announcer.StartTimer();
- MessagePlayer("Announcer actived!", player);
- break;
- case "off":
- Announcer.StopTimer();
- MessagePlayer("Announcer desactived!", player);
- break;
- default:
- MessagePlayer("Sintax: /announcer add/remove/interval/list/off/on", player);
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement