Advertisement
Guest User

Announcer System (VCMP)

a guest
Sep 17th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.02 KB | None | 0 0
  1. AnnouncerInterval <- 120000; // Default interval = 2 minutes.
  2. AnuncioID <- 1;
  3. AnnouncerTimmer <- null;
  4. Announcer_Prefix <- "[#B7C7C0][[#0FF195]Announcer[#B7C7C0]] [#27E79B]"
  5. Announcer_Status <- false;
  6.  
  7. Announcer <- {
  8.  
  9.     function CreateTable()
  10.     {
  11.         QuerySQL( db, "CREATE TABLE IF NOT EXISTS Announcer ( ID NUMERIC, Message TEXT, Owner TEXT )" );
  12.     }
  13.  
  14.     function AddAnnounce(Message, Owner)
  15.     {
  16.         local GetID = QuerySQL( db, "SELECT * FROM Announcer ORDER BY ID DESC LIMIT 1"), id = 1;
  17.  
  18.         if( GetSQLColumnData( GetID, 0 ) ) id = ( id + GetSQLColumnData( GetID, 0 ).tointeger() );
  19.         QuerySQL( db, "INSERT INTO Announcer VALUES ( '"+ id +"','" + Message + "', '" + Owner + "' )" );
  20.     }
  21.  
  22.     function RemoveAnnouncer(id)
  23.     {
  24.         QuerySQL( db, "DELETE FROM Announcer WHERE ID='" + id + "'" );
  25.         Announcer.ReorganizarIDs();
  26.     }
  27.  
  28.     function ReorganizarIDs()
  29.     {
  30.         local q = QuerySQL( db, "SELECT * FROM Announcer"), i = 1;
  31.         while( GetSQLColumnData( q, 0 ) )
  32.         {
  33.             QuerySQL( db, "UPDATE Announcer SET ID='" + i + "' WHERE ID='" + GetSQLColumnData( q, 0 ) + "'" );
  34.             i++;
  35.             GetSQLNextRow( q );
  36.         }
  37.     }
  38.  
  39.  
  40.     function GetAnnounceList(player)
  41.     {
  42.         local q = QuerySQL( db, "SELECT * FROM Announcer"), ann, i = 1;
  43.  
  44.         while ( GetSQLColumnData( q, 0 ) )
  45.         {
  46.             if ( GetSQLColumnData( q, 1 ) != null)
  47.             {
  48.                 ann = true;
  49.                 MessagePlayer("[#FE2E64]ID: "+ GetSQLColumnData( q, 0 ) + " Message: "+ GetSQLColumnData( q, 1 ) +" - Author: "+ GetSQLColumnData( q, 2 ), player);
  50.             }
  51.             i++;
  52.             GetSQLNextRow( q );
  53.         }
  54.         if (!ann) MessagePlayer("There are no ads.", player);
  55.     }
  56.  
  57.     function UpdateInterval(time) //time = minutes
  58.     {
  59.         time = (time * 60000);
  60.         Announcer.StopTimer();
  61.         AnnouncerInterval = time;
  62.         Announcer.StartTimer();
  63.     }
  64.  
  65.     function StartTimer()
  66.     {
  67.         AnnouncerTimmer = _Timer.Create(this, Announcer.Say, AnnouncerInterval, 0);
  68.         Announcer_Status = true;
  69.     }
  70.  
  71.     function StopTimer()
  72.     {
  73.         _Timer.Destroy(AnnouncerTimmer);
  74.         Announcer_Status = false;
  75.     }
  76.  
  77.     function Say()
  78.     {
  79.         local q = QuerySQL( db, "SELECT * FROM Announcer WHERE ID='" + AnuncioID + "'" );
  80.  
  81.         if(!GetSQLColumnData( q, 1 ))
  82.         {
  83.  
  84.             if (AnuncioID != 1)
  85.             {
  86.                 AnuncioID = 1;
  87.                 Announcer.Say();
  88.                
  89.             }
  90.             else
  91.             {
  92.                 Announcer.StopTimer();
  93.                 print("There isn't announcements, so the timer has been deactivated.")
  94.             }
  95.            
  96.         }
  97.         else
  98.         {
  99.            AnuncioID++;
  100.            Message( Announcer_Prefix + GetSQLColumnData( q, 1 ) );
  101.         }
  102.     }
  103.  
  104.     function GetInterval()
  105.     {
  106.         return (AnnouncerInterval / 60000);
  107.     }
  108.  
  109.  
  110.     function Command(text, player)
  111.     {
  112.         local subcommand = GetTok( text, " ", 1 );
  113.         switch ( subcommand.tolower() )
  114.         {
  115.             case "add":
  116.             local Announce = SearchAndReplace(text, "add ","");
  117.             if(Announce != null)
  118.             {
  119.                 if(Announcer_Status == false) MessagePlayer("Your announcer is off, you can turn it on using /announcer on", player);
  120.                
  121.                 Announcer.AddAnnounce(Announce, player);
  122.                 MessagePlayer("Announce added!", player);
  123.             }
  124.             else MessagePlayer("/announcer add -message-", player)
  125.             break;
  126.  
  127.             case "remove":
  128.             case "delete":
  129.             local id = GetTok( text, " ", 2 );
  130.             local q = QuerySQL( db, "SELECT * FROM Announcer WHERE ID='"+ id +"'");
  131.  
  132.             if( GetSQLColumnData( q, 0 ) )
  133.             {
  134.                 Announcer.RemoveAnnouncer(id);
  135.                 MessagePlayer("Message: "+ GetSQLColumnData( q, 1 ) +" deleted.", player);
  136.             }
  137.             else MessagePlayer("/announcer remove -ID-", player)
  138.  
  139.             break;
  140.  
  141.             case "list":
  142.             Announcer.GetAnnounceList(player);
  143.             break;
  144.  
  145.             case "interval":
  146.             local time = GetTok( text, " ", 2 ).tointeger();
  147.  
  148.             if (time == 0) MessagePlayer("You cant set interval 0. Reason: It will generate spam.", player);
  149.             else
  150.             {
  151.                 Announcer.UpdateInterval(time);
  152.                 MessagePlayer("Interval updated!", player);
  153.             }
  154.             break;
  155.  
  156.             case "on":
  157.             Announcer.StartTimer();
  158.             MessagePlayer("Announcer actived!", player);
  159.             break;
  160.  
  161.             case "off":
  162.             Announcer.StopTimer();
  163.             MessagePlayer("Announcer desactived!", player);
  164.             break;
  165.  
  166.             default:
  167.             MessagePlayer("Sintax: /announcer add/remove/interval/list/off/on", player);
  168.         }
  169.     }
  170. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement