Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: Inferno on Oct 27, 2020, 02:17 AM

Title: Basic Quote System.
Post by: Inferno on Oct 27, 2020, 02:17 AM
 

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



Title: Re: Basic Quote System.
Post by: Rupinder on Nov 17, 2020, 05:47 PM
(https://i.ibb.co/5TQ7R31/g7.png)

(https://i.ibb.co/vHzJD1g/b8.png)

how to fix this error??
Title: Re: Basic Quote System.
Post by: Inferno on Nov 17, 2020, 06:50 PM
Quote from: Rupinder on Nov 17, 2020, 05:47 PM(https://i.ibb.co/5TQ7R31/g7.png)



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;
}
(https://i.ibb.co/vHzJD1g/b8.png)
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.
Title: Re: Basic Quote System.
Post by: Rupinder on Nov 18, 2020, 03:47 AM
(https://i.ibb.co/JqHg1Gs/vu.png)

still not working??
Title: Re: Basic Quote System.
Post by: Inferno on Nov 18, 2020, 03:51 PM
Do you have this command on top of script?
And whats the console error
Title: Re: Basic Quote System.
Post by: Rupinder on Nov 18, 2020, 05:56 PM
(https://i.ibb.co/R7Xb9Ly/vbn.png)


(https://i.ibb.co/Z86SNnZ/89.png)

can you make  video tutorial?? how to add

Title: Re: Basic Quote System.
Post by: Rupinder on Nov 18, 2020, 06:17 PM
(https://i.ibb.co/tsmdJT1/rt.png)


Now show error on line 45

[spoiler]QuerySQL( dbQuotes, "CREATE TABLE IF NOT EXISTS Quotes ( ID NUMERIC, Quote TEXT, Creator TEXT )" );
[/spoiler]
Title: Re: Basic Quote System.
Post by: Inferno on Nov 18, 2020, 08:45 PM
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

}


(https://i.ibb.co/d2vwQLP/Screenshot-20201119-013652.png) (https://ibb.co/6PS741H)




Quote from: Rupinder on Nov 18, 2020, 05:56 PM(https://i.ibb.co/R7Xb9Ly/vbn.png)


(https://i.ibb.co/Z86SNnZ/89.png)

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.
Title: Re: Basic Quote System.
Post by: Rupinder on Nov 19, 2020, 04:05 AM
(https://i.ibb.co/TbvMkdn/h.png)

now not show any error but when i tried in server nothing happen ?? trying  cmd /addquote but nothing show
Title: Re: Basic Quote System.
Post by: Inferno on Nov 19, 2020, 04:11 AM
Quote from: Rupinder on Nov 19, 2020, 04:05 AM(https://i.ibb.co/TbvMkdn/h.png)

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
Title: Re: Basic Quote System.
Post by: 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(https://i.ibb.co/TbvMkdn/h.png)

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
(https://i.ibb.co/bJgWPTN/gyi.png)
Title: Re: Basic Quote System.
Post by: Inferno on Nov 19, 2020, 04:22 AM
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(https://i.ibb.co/TbvMkdn/h.png)

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
(https://i.ibb.co/bJgWPTN/gyi.png)

: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
 
(https://i.ibb.co/6rVBVXX/Screenshot-20201119-091231.png) (https://ibb.co/FmNVNHH)
Title: Re: Basic Quote System.
Post by: Rupinder on Nov 19, 2020, 05:13 AM
(https://i.ibb.co/VLLyy3b/bll.png)

(https://i.ibb.co/kqgb0nP/g.png)

fix but show one more bug please check
Title: Re: Basic Quote System.
Post by: Inferno on Nov 19, 2020, 05:50 AM
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.



Title: Re: Basic Quote System.
Post by: gta on Jul 31, 2021, 01:31 AM
Quote from: Rupinder on Nov 17, 2020, 05:47 PM(https://i.ibb.co/5TQ7R31/g7.png)

(https://i.ibb.co/vHzJD1g/b8.png)

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