Basic Quote System.

Started by Inferno, Oct 27, 2020, 02:17 AM

Previous topic - Next topic

Inferno

 

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
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

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
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)

Update: Added a fix suggested by Mashreq



Viva la VU
VFS Developer
VCCNR Administrator

Rupinder





how to fix this error??
Vice City Servers
https://bit.ly/2Uw2usM

Inferno

#2
Quote from: Rupinder on Nov 17, 2020, 05:47 PM



if you have put these commands on top in OnPlayerCommand,
Make sure that you have first command starting with if instead of else if.

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;
}

And if you are getting "+RED+" error
Then put

const RED = "[#ff77ff]";
Or replace it with any colour code you want to. Like [#ffffff] for white.
Viva la VU
VFS Developer
VCCNR Administrator

Rupinder

Vice City Servers
https://bit.ly/2Uw2usM

Inferno

Do you have this command on top of script?
And whats the console error
Viva la VU
VFS Developer
VCCNR Administrator

Rupinder






can you make  video tutorial?? how to add

Vice City Servers
https://bit.ly/2Uw2usM

Rupinder

#6



Now show error on line 45

[spoiler]QuerySQL( dbQuotes, "CREATE TABLE IF NOT EXISTS Quotes ( ID NUMERIC, Quote TEXT, Creator TEXT )" );
[/spoiler]
Vice City Servers
https://bit.ly/2Uw2usM

Inferno

#7
Yellow arrow is to show that the onscriptload event has ended there


{
// stuff

}

And you have pasted the other defined variables after the event ended.

Red marked are the arguments.

Make sure to move them within
function OnScriptLoad()
{

// here

}







Quote from: Rupinder on Nov 18, 2020, 05:56 PM




can you make  video tutorial?? how to add



Its a done and dusted snippet.
All you have to do is to paste it correctly and it will work.
Viva la VU
VFS Developer
VCCNR Administrator

Rupinder



now not show any error but when i tried in server nothing happen ?? trying  cmd /addquote but nothing show
Vice City Servers
https://bit.ly/2Uw2usM

Inferno

Quote from: Rupinder on Nov 19, 2020, 04:05 AM

now not show any error but when i tried in server nothing happen ?? trying  cmd /addquote but nothing show

You basically either dont have
local RED = "[#ff0000]";
Or isNum function.
Is there any console error you are getting? Try all 4 cmds and show console.

Make sure u added cmds in OnPlayerCommand
Viva la VU
VFS Developer
VCCNR Administrator

Rupinder

Quote from: Inferno on Nov 19, 2020, 04:11 AM
Quote from: Rupinder on Nov 19, 2020, 04:05 AM

now not show any error but when i tried in server nothing happen ?? trying  cmd /addquote but nothing show

You basically either dont have
local RED = "[#ff0000]";
Or isNum function.
Is there any console error you are getting? Try all 4 cmds and show console.

Make sure u added cmds in OnPlayerCommand

i will paste there but still show error
Vice City Servers
https://bit.ly/2Uw2usM

Inferno

#11
Quote from: Rupinder on Nov 19, 2020, 04:12 AM
Quote from: Inferno on Nov 19, 2020, 04:11 AM
Quote from: Rupinder on Nov 19, 2020, 04:05 AM

now not show any error but when i tried in server nothing happen ?? trying  cmd /addquote but nothing show

You basically either dont have
local RED = "[#ff0000]";
Or isNum function.
Is there any console error you are getting? Try all 4 cmds and show console.

Make sure u added cmds in OnPlayerCommand

i will paste there but still show error


:facepalm:
You cannot even copy paste given snippets correctly :facepalm:


I told you to paste it within onscript load
And u first pasted it after it openly and now with brackets ;-;

Here is the last time i am telling you where to add it -_-
I know you are a newbie but atleast don't be so dumb to paste it wrong despite everything explained
 

Viva la VU
VFS Developer
VCCNR Administrator

Rupinder





fix but show one more bug please check
Vice City Servers
https://bit.ly/2Uw2usM

Inferno

#13
This snippet contains less number of alphabets than the errors you are getting. More like intentionally coming up with errors.

Make sure if you have posted it just after

onplayercommand
{
It should start with if(
Instead of else if.

Also show the cmd before this one, that might be causing the error



I still doubt if you have posted it all correctly.



Viva la VU
VFS Developer
VCCNR Administrator

gta

#14
Quote from: Rupinder on Nov 17, 2020, 05:47 PM



how to fix this error??
do you even know where to add this?