Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: FinchDon on Sep 27, 2015, 11:02 AM

Title: Error GetTeam
Post by: FinchDon on Sep 27, 2015, 11:02 AM
I add this onScriptLoad

random <- [ 1, 2, 3, 4 ];

and add this on Player Register

local team = random[rand()% random.len()]
      ::QuerySQL( dbGlobal, "INSERT INTO Accounts VALUES( '" + team + "' )" );

and this is Command

if ( cmd == "myteam")
{
if ( GetTeam( player ) == 1 ) MessagePlayer( "[#FF0000]MaaKi", player );
if ( GetTeam( player ) == 2 ) MessagePlayer( "[#66FF33]Fabular", player );
if ( GetTeam( player ) == 3 ) MessagePlayer( "[#6666FF]Cmon Master", player );
if ( GetTeam( player ) == 4 ) MessagePlayer( "[#FFFF00]You are noob", player );
}

Releated Functions

function SetTeam( player, amount )
{
      QuerySQL(sqliteDB, "UPDATE Accounts SET Group='" +  amount + "' WHERE Name='" + player.Name + "'");   
}

function GetTeam( player )
{
   local lvl1 =  GetSQLColumnData( QuerySQL( sqliteDB, "SELECT Group FROM Accounts WHERE Name='" + player.Name+"'" ), 0 );
   if ( lvl1 ) return lvl1;
   else return 0;
}

Now When i Registered and check in database it show Group Random sometime 1 or 2 or 3 But when i do /myteam it show nothing i add this on Command

if ( GetTeam( player ) == 0 ) PrivMessage( player, "xD" );

then it show that message but in database it was team 2
      
Title: Re: Error GetTeam
Post by: Thijn on Sep 27, 2015, 11:34 AM
Ouch. 4 queries each time you to do /myteam. That's gonna lag like shit when abused.

That insert query makes no sense. Do you really only have 1 column in your Accounts table?
Title: Re: Error GetTeam
Post by: FinchDon on Sep 27, 2015, 12:13 PM
Nah it is this
::QuerySQL( dbGlobal, "INSERT INTO Accounts VALUES('" + player.Name + "', '" + player.Name.tolower() + "', '" + ( password ) + "', 0, 0, 0, 0, 1, '" + player.IP + "', '" + team + "' )" );
Title: Re: Error GetTeam
Post by: MacTavish on Sep 27, 2015, 12:27 PM
Quote from: FinchDon on Sep 27, 2015, 12:13 PMNah it is this
::QuerySQL( dbGlobal, "INSERT INTO Accounts VALUES('" + player.Name + "', '" + player.Name.tolower() + "', '" + ( password ) + "', 0, 0, 0, 0, 1, '" + player.IP + "', '" + team + "' )" );

Invalid Query

actually it would have to be like this
::QuerySQL( dbGlobal, "INSERT INTO Accounts (Name, NameTolower, Password, thingone, thingtwo, thingthree, thingfour, thingfive, IP, Group ) VALUES('" + player.Name + "', '" + player.Name.tolower() + "', '" + ( password ) + "', 0, 0, 0, 0, 1, '" + player.IP + "', '" + team + "' )" );


And second thing your myteam cmd is wrong,

You using

if
if

This prevents operation to check next condition
Actually it should be like this

if ( cmd == "myteam")
 {
 if ( GetTeam( player ) == 1 ) MessagePlayer( "[#FF0000]MaaKi", player );
else if ( GetTeam( player ) == 2 ) MessagePlayer( "[#66FF33]Fabular", player );
else if ( GetTeam( player ) == 3 ) MessagePlayer( "[#6666FF]Cmon Master", player );
 else if ( GetTeam( player ) == 4 ) MessagePlayer( "[#FFFF00]You are noob", player );
 }
Title: Re: Error GetTeam
Post by: KAKAN on Sep 27, 2015, 01:48 PM
It's better to use array for it instead of using Query each time, I mean you can save it in DB, but load it on an array onplayerjoin, you can see FAS for more details.
Title: Re: Error GetTeam
Post by: Thijn on Sep 27, 2015, 02:12 PM
Quote from: Kusanagi on Sep 27, 2015, 12:27 PM
Quote from: FinchDon on Sep 27, 2015, 12:13 PMNah it is this
::QuerySQL( dbGlobal, "INSERT INTO Accounts VALUES('" + player.Name + "', '" + player.Name.tolower() + "', '" + ( password ) + "', 0, 0, 0, 0, 1, '" + player.IP + "', '" + team + "' )" );

Invalid Query

actually it would have to be like this
::QuerySQL( dbGlobal, "INSERT INTO Accounts (Name, NameTolower, Password, thingone, thingtwo, thingthree, thingfour, thingfive, IP, Group ) VALUES('" + player.Name + "', '" + player.Name.tolower() + "', '" + ( password ) + "', 0, 0, 0, 0, 1, '" + player.IP + "', '" + team + "' )" );


And second thing your myteam cmd is wrong,

You using

if
if

This prevents operation to check next condition
Actually it should be like this

if ( cmd == "myteam")
 {
 if ( GetTeam( player ) == 1 ) MessagePlayer( "[#FF0000]MaaKi", player );
else if ( GetTeam( player ) == 2 ) MessagePlayer( "[#66FF33]Fabular", player );
else if ( GetTeam( player ) == 3 ) MessagePlayer( "[#6666FF]Cmon Master", player );
 else if ( GetTeam( player ) == 4 ) MessagePlayer( "[#FFFF00]You are noob", player );
 }
You're wrong in both occasions. That query is perfectly valid, as long as he defines each column.
And while not using else if, but just if is inefficient, it certainly works.
Title: Re: Error GetTeam
Post by: MacTavish on Sep 27, 2015, 02:19 PM
Quote from: Thijn on Sep 27, 2015, 02:12 PM
Quote from: Kusanagi on Sep 27, 2015, 12:27 PM
Quote from: FinchDon on Sep 27, 2015, 12:13 PMNah it is this
::QuerySQL( dbGlobal, "INSERT INTO Accounts VALUES('" + player.Name + "', '" + player.Name.tolower() + "', '" + ( password ) + "', 0, 0, 0, 0, 1, '" + player.IP + "', '" + team + "' )" );

Invalid Query

actually it would have to be like this
::QuerySQL( dbGlobal, "INSERT INTO Accounts (Name, NameTolower, Password, thingone, thingtwo, thingthree, thingfour, thingfive, IP, Group ) VALUES('" + player.Name + "', '" + player.Name.tolower() + "', '" + ( password ) + "', 0, 0, 0, 0, 1, '" + player.IP + "', '" + team + "' )" );


And second thing your myteam cmd is wrong,

You using

if
if

This prevents operation to check next condition
Actually it should be like this

if ( cmd == "myteam")
 {
 if ( GetTeam( player ) == 1 ) MessagePlayer( "[#FF0000]MaaKi", player );
else if ( GetTeam( player ) == 2 ) MessagePlayer( "[#66FF33]Fabular", player );
else if ( GetTeam( player ) == 3 ) MessagePlayer( "[#6666FF]Cmon Master", player );
 else if ( GetTeam( player ) == 4 ) MessagePlayer( "[#FFFF00]You are noob", player );
 }
You're wrong in both occasions. That query is perfectly valid, as long as he defines each column.
And while not using else if, but just if is inefficient, it certainly works.

Really? i never tested those ways thats why i thought that
Title: Re: Error GetTeam
Post by: FinchDon on Sep 27, 2015, 02:21 PM
So What is Error :\
Title: Re: Error GetTeam
Post by: Thijn on Sep 27, 2015, 03:28 PM
Do a print on that command.
You really have no clue how to debug stuff, do you? ...
Title: Re: Error GetTeam
Post by: FinchDon on Sep 28, 2015, 10:25 AM
Ya I use That
if ( cmd == "a")
{
PrivMessage( player, " ahh " + GetTeam( player ) + ".");
}

But it too show Group 0 Where it is 2 in Database

function GetTeam( player )
{
   local lvl1 =  GetSQLColumnData( QuerySQL( sqliteDB, "SELECT Group FROM Accounts WHERE Name='" + player.Name+"'" ), 0 );
   if ( lvl1 ) return lvl1;
   else return 0;
}
Title: Re: Error GetTeam
Post by: Xmair on Sep 28, 2015, 12:31 PM
Post your table creating line.
Title: Re: Error GetTeam
Post by: FinchDon on Sep 28, 2015, 01:03 PM
I Create Table By Opening Database I open Database and edit Accounts table and add There. Group NUMERIC
Title: Re: Error GetTeam
Post by: KAKAN on Sep 28, 2015, 02:18 PM
POST your CREATE TABLE IF NOT EXISTS FUNCTION
Title: Re: Error GetTeam
Post by: FinchDon on Sep 28, 2015, 02:20 PM
I dont have that function
Title: Re: Error GetTeam
Post by: MacTavish on Sep 28, 2015, 02:20 PM
Quote from: KAKAN on Sep 28, 2015, 02:18 PMPOST your CREATE TABLE IF NOT EXISTS FUNCTION

He created that column manually by db browser, not by the function
Title: Re: Error GetTeam
Post by: KAKAN on Sep 28, 2015, 02:26 PM
Then this one can be his problem:-
He uses dbGlobal at 1st, then he uses sqliteDB, wth is that?
Title: Re: Error GetTeam
Post by: FinchDon on Sep 28, 2015, 02:29 PM
Wow I used sqliteDB in many places thats works but why not this?
Title: Re: Error GetTeam
Post by: KAKAN on Sep 28, 2015, 02:32 PM
Then why are you using dbGlobal there?
That means you are connecting dbGlobal and sqliteDB to the same db file, which won't work I guess
Title: Re: Error GetTeam
Post by: KAKAN on Sep 28, 2015, 02:32 PM
Its better paste the whole function here
Title: Re: Error GetTeam
Post by: FinchDon on Sep 28, 2015, 02:35 PM
Bhai Ye Fuzzie se baat kr iske bare me
Title: Re: Error GetTeam
Post by: KAKAN on Sep 28, 2015, 02:37 PM
Oh! You can tell that too. He is using functions.
Now post all the functions regarding to your random group system.
And I suggest you to use an array for doing it.
PM me the playerclass, and the DB tables, if u want an array for doing it.
Title: Re: Error GetTeam
Post by: FinchDon on Sep 28, 2015, 02:46 PM
:/ Genius I want in DB!!!!!!! No Array
Title: Re: Error GetTeam
Post by: KAKAN on Sep 28, 2015, 02:52 PM
LoL!
Load it onto the array, save it in the DB, just as Fuziee Account System
Title: Re: Error GetTeam
Post by: FinchDon on Sep 28, 2015, 02:55 PM
Genius Tell me what is the problem i am facing!!!!!!!!
Title: Re: Error GetTeam
Post by: Xmair on Sep 28, 2015, 03:57 PM
What the....
Title: Re: Error GetTeam
Post by: KAKAN on Sep 28, 2015, 04:16 PM
Quote from: Xmair on Sep 28, 2015, 03:57 PMWhat the....
WHat you mean?
Did I say something wrong? If so, what?
Title: Re: Error GetTeam
Post by: Xmair on Sep 28, 2015, 04:27 PM
I am not talking about you, I am talking about the person who is told what is the solution still doesn't knows it.
Title: Re: Error GetTeam
Post by: KAKAN on Sep 28, 2015, 05:03 PM
And now, he can never know about it too.
Anyways, I would like to request @Thijn or any other dev to lock the topic.