0 Members and 1 Guest are viewing this topic.
Update : added a fix suggested by Mashreq
-You can Add Quotes-You can read quotes using their IDs-You can check quotes made by yourself-You can view a random quote
qCount <- 0;dbQuotes <- ConnectSQL("Databases/quotes.db");QuerySQL( dbQuotes, "CREATE TABLE IF NOT EXISTS Quotes ( ID NUMERIC, Quote TEXT, Creator TEXT )" );LoadQuotes();
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();}
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;}