April 27, 2024, 09:17:05 am

Author Topic: Basic Quote System.  (Read 610 times)

0 Members and 1 Guest are viewing this topic.

Inferno69

  • Vice Underdog
  • Crazy Man
  • *
  • *
  • *
  • Posts: 761
  • Country: pk
  • 👀
    • View Profile
    • VFS
Basic Quote System.
« on: October 27, 2020, 02:46:36 am »
 

Quote
Update : added a fix suggested by Mashreq

Features
Quote
-You can Add Quotes
-You can read quotes using their IDs
-You can check quotes made by yourself
-You can view a random quote


OnScriptLoad
Code: [Select]
qCount <- 0;

dbQuotes <- ConnectSQL("Databases/quotes.db");
QuerySQL( dbQuotes, "CREATE TABLE IF NOT EXISTS Quotes ( ID NUMERIC, Quote TEXT, Creator TEXT )" );

LoadQuotes();

Anywhere in main.nut

Code: [Select]
function LoadQuotes()
{
local q = QuerySQL( dbQuotes, "SELECT * FROM Quotes" ), i = 0;
while( GetSQLColumnData( q, 0 ) )
{
GetSQLNextRow( q );
i++;
}
print("Quotes Count ("+i+")");
qCount = i;
     FreeSQLQuery(q);
}

function random( min, max ) // incase you don't have the random(a,b) function
{
        if ( min < max )
                return rand() % (max - min + 1) + min.tointeger();
        else if ( min > max )
                return rand() % (min - max + 1) + max.tointeger();
        else if ( min == max )
                return min.tointeger();
}

 

OnPlayerCommand
Code: [Select]
else if(cmd == "randomquote") {
if(qCount == 0) return MessagePlayer(""+RED+" There are no quotes in the database ",player);
else if(text) return 0;
else {
local rr = random(1,qCount);
 local gg = QuerySQL(dbQuotes, "SELECT * FROM Quotes WHERE ID='" + rr + "'");
local tq = GetSQLColumnData( gg, 1 );
local tc = GetSQLColumnData( gg, 2 );

Message("[#ffff00]"+player.Name+" [#ffffff]has viewed a random quote ID :[#ffff00]["+rr+"],[#ffffff] Quote:[#ffff00] [ "+tq+" ], [#ffffff]Creator:[#ffff00][ "+tc+" ] ");
}
return 0;
}

else if ( cmd == "myquotes" )
{
 local q = QuerySQL(dbQuotes, "SELECT * FROM Quotes WHERE Creator='" + player.Name + "'"), i = 0;
if(q) {
MessagePlayer("[#ffffff]Your "+ORANGE+"[Quotes]: ", player);
while (GetSQLColumnData(q, 2) == player.Name) {
MessagePlayer(""+ORANGE+"ID:[#ffffff]["+GetSQLColumnData( q , 0)+"], "+ORANGE+"Quote:[#ffffff]["+GetSQLColumnData( q, 1 )+"] ",player);       
GetSQLNextRow(q);
i++;
}
}
else if(!q) {

MessagePlayer("[#ffffff][Your] "+ORANGE+"[Quotes]:[#ffffff] None ", player);

}



     FreeSQLQuery(q);
return 0;
}

  else if (cmd == "addquote")
{
if(!text) return MessagePlayer(""+RED+"/addquote [message]",player);
else {
qCount++;
QuerySQL( dbQuotes, "INSERT INTO Quotes ( ID, Quote, Creator ) VALUES ( '" + qCount + "', '"+text+"', '"+player.Name+"' )" );
MessagePlayer("[#ffff00]You have added a quote ID : "+qCount+" ",player);

}
return 0;
}

  else if (cmd == "quote")
{
if(!text) return MessagePlayer(""+RED+"/quote [id]",player);
else if(!IsNum(text)) return MessagePlayer(""+RED+"Use numbers for IDs",player);
else {
 local ak = QuerySQL(dbQuotes, "SELECT * FROM Quotes WHERE ID='" + text.tointeger() + "'");
if(!ak) return MessagePlayer(""+RED+" Invalid Quote ID ",player);
local aqw = GetSQLColumnData( ak, 1 );
local ao = GetSQLColumnData( ak, 2 );

Message("[#ffffff] "+player.Name+" "+RED+"has viewed a quote ID:[#ffffff]["+text.tointeger()+"], "+RED+"Creator:[#ffffff][ "+ao+" ] , "+RED+"Context:[#ffffff][ "+aqw+" ] ");
}
return 0;
}

else if(cmd == "quotecmds") {
MessagePlayer("[#ffff00] ~ Quote Commands ~ ",player);
MessagePlayer("[#ffff00] ~ /randomquote, /quote, /addquote, /myquotes ~ ",player);
return 0;
}




Commands

/addquote
(to add a quote)
/quote [id](to check a quote)
/randomquote(to view a random quote)
/myquotes(to view the quotes written by yourself)





« Last Edit: October 27, 2020, 06:25:35 pm by Inferno69 »
Winner Winner x 1 Informative Informative x 1 Useful Useful x 3 (list)
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor