Error GetTeam

Started by FinchDon, Sep 27, 2015, 11:02 AM

Previous topic - Next topic

FinchDon

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
      
For any help and support Join #s-s at IRC for Help in Scripting
( For Newbies )

Thijn

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?

FinchDon

Nah it is this
::QuerySQL( dbGlobal, "INSERT INTO Accounts VALUES('" + player.Name + "', '" + player.Name.tolower() + "', '" + ( password ) + "', 0, 0, 0, 0, 1, '" + player.IP + "', '" + team + "' )" );
For any help and support Join #s-s at IRC for Help in Scripting
( For Newbies )

MacTavish

#3
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 );
 }

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

KAKAN

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.
oh no

Thijn

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.

MacTavish

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

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

FinchDon

So What is Error :\
For any help and support Join #s-s at IRC for Help in Scripting
( For Newbies )

Thijn

Do a print on that command.
You really have no clue how to debug stuff, do you? ...

FinchDon

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;
}
For any help and support Join #s-s at IRC for Help in Scripting
( For Newbies )

Xmair

Post your table creating line.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

FinchDon

I Create Table By Opening Database I open Database and edit Accounts table and add There. Group NUMERIC
For any help and support Join #s-s at IRC for Help in Scripting
( For Newbies )

KAKAN

POST your CREATE TABLE IF NOT EXISTS FUNCTION
oh no

FinchDon

I dont have that function
For any help and support Join #s-s at IRC for Help in Scripting
( For Newbies )

MacTavish

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

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P