« Sound
Error GetTeam

FinchDon

  • Sr. Member
  • Posts: 252
Error GetTeam
« on September 27th, 2015, 12:02 PM »
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

Code: [Select]
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

Code: [Select]
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

  • VC:MP Beta Tester
  • Posts: 1,688
Re: Error GetTeam
« Reply #1, on September 27th, 2015, 12:34 PM »
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

  • Sr. Member
  • Posts: 252
Re: Error GetTeam
« Reply #2, on September 27th, 2015, 01:13 PM »
Nah it is this
Code: [Select]
::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

  • Hero Member
  • Nicks( Kusanagi, Beztone, RATHORE )
  • Posts: 809
Re: Error GetTeam
« Reply #3, on September 27th, 2015, 01:27 PM »Last edited on September 27th, 2015, 01:54 PM
Quote from FinchDon on September 27th, 2015, 01:13 PM
Nah it is this
Code: [Select]
::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
Code: [Select]
::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

Code: [Select]
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

  • Wiki Contributor
  • Posts: 3,343
Re: Error GetTeam
« Reply #4, on September 27th, 2015, 02: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.
You can contact me using Discord, at Developers.CPP( check off-board to find the invite link )
Github: https://github.com/theKAKAN

Thijn

  • VC:MP Beta Tester
  • Posts: 1,688
Re: Error GetTeam
« Reply #5, on September 27th, 2015, 03:12 PM »
Quote from Kusanagi on September 27th, 2015, 01:27 PM
Quote from FinchDon on September 27th, 2015, 01:13 PM
Nah it is this
Code: [Select]
::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
Code: [Select]
::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

Code: [Select]
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

  • Hero Member
  • Nicks( Kusanagi, Beztone, RATHORE )
  • Posts: 809
Re: Error GetTeam
« Reply #6, on September 27th, 2015, 03:19 PM »
Quote from Thijn on September 27th, 2015, 03:12 PM
Quote from Kusanagi on September 27th, 2015, 01:27 PM
Quote from FinchDon on September 27th, 2015, 01:13 PM
Nah it is this
Code: [Select]
::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
Code: [Select]
::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

Code: [Select]
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

  • Sr. Member
  • Posts: 252
Re: Error GetTeam
« Reply #7, on September 27th, 2015, 03:21 PM »
So What is Error :\
For any help and support Join #s-s at IRC for Help in Scripting
( For Newbies )

Thijn

  • VC:MP Beta Tester
  • Posts: 1,688
Re: Error GetTeam
« Reply #8, on September 27th, 2015, 04:28 PM »
Do a print on that command.
You really have no clue how to debug stuff, do you? ...

FinchDon

  • Sr. Member
  • Posts: 252
Re: Error GetTeam
« Reply #9, on September 28th, 2015, 11:25 AM »
Ya I use That
Code: [Select]
if ( cmd == "a")
{
PrivMessage( player, " ahh " + GetTeam( player ) + ".");
}

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

Code: [Select]
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

  • Wiki Contributor
  • Posts: 930
Re: Error GetTeam
« Reply #10, on September 28th, 2015, 01:31 PM »
Post your table creating line.
VU Full Member | VCCNR Developer | KTB Developer | EAD Ex-Scripter

FinchDon

  • Sr. Member
  • Posts: 252
Re: Error GetTeam
« Reply #11, on September 28th, 2015, 02:03 PM »
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

  • Wiki Contributor
  • Posts: 3,343
Re: Error GetTeam
« Reply #12, on September 28th, 2015, 03:18 PM »
POST your CREATE TABLE IF NOT EXISTS FUNCTION
You can contact me using Discord, at Developers.CPP( check off-board to find the invite link )
Github: https://github.com/theKAKAN

FinchDon

  • Sr. Member
  • Posts: 252
Re: Error GetTeam
« Reply #13, on September 28th, 2015, 03:20 PM »
I dont have that function
For any help and support Join #s-s at IRC for Help in Scripting
( For Newbies )

MacTavish

  • Hero Member
  • Nicks( Kusanagi, Beztone, RATHORE )
  • Posts: 809

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

Retired VC:MP Player/Scripter :P