Vice City: Multiplayer

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

Title: VIP
Post by: FinchDon on Sep 19, 2015, 11:13 AM
I made this function

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

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

And This Command

if ( cmd == "buyvip")
{
if ( pstats[ player.ID ].Logged == false ) PrivMessage( player, "You are not logged in");
    else if ( GetCoins( player ) <= 1000 ) PrivMessage( player, "You need to have atleast 1000 BFME Coints for VIP");
else
{
QuerySQL(sqliteDB, "UPDATE Accounts SET VIP= 'true' WHERE Name='" + player.Name + "'");   
SetCoins( player, GetCoins( player ) - 1000 );
PrivMessage( player, "Congratulation You Become New VIP");
Message( " " + player.Name + "has become New VIP of a Server");
}
}

when i type !buyvip  i have everything coins and get logged in it show last PRIVMESSAGE and when i go to database it show True

but when i type !vip

It Show no VIP Online

else if ( ( cmd == "vip" ) || ( cmd == "vip" ) )
{
local plr, b;
for( local i = 0; i < GetMaxPlayers(); i++ )
{
    plr = FindPlayer( i );
if ( ( plr ) && ( GetVIP( plr ) == true ) )
    {
if ( b ) b = b + ", " + plr.Name + " "
else b = plr.Name + " "
    }
}
if ( b ) Message( "**In Game[ VIP Online: [ " + b + " ] ]" );
else Message( "** In Game [ No VIP Online ]." );
}

and also use this

function onPlayerSpawn( player )
{
if ( GetVIP( player ) == true ) player.Health = 0;
}

But when i spawn It is True in db  VIP but It Didn't kill me Why?

Title: Re: VIP
Post by: FinchDon on Sep 19, 2015, 11:41 AM
reply?
Title: Re: VIP
Post by: KAKAN on Sep 19, 2015, 12:03 PM
Atleast have a common sense
Take a look at your code:-
function GetVIP( player )
{
   local lvl1 =  GetSQLColumnData( QuerySQL( sqliteDB, "SELECT VIP FROM Accounts WHERE Name='" + player.Name+"'" ), 0 );
   if ( lvl1 ) return lvl1;
   else return 0;
}

It'll return lvl1
Use something like this:-
function GetVIP( player )
{
   local lvl1 =  GetSQLColumnData( QuerySQL( sqliteDB, "SELECT VIP FROM Accounts WHERE Name='" + player.Name+"'" ), 0 );
   if ( lvl1 == true ) return true;
   else return false;
}
Title: Re: VIP
Post by: FinchDon on Sep 19, 2015, 12:32 PM
Solved i change true/false to 0/1
Title: Re: VIP
Post by: Thijn on Sep 19, 2015, 12:37 PM
I would like to add that this will lag the shit out of your server. I can spam !vip and it will do a query for each online player. Ouch.
Title: Re: VIP
Post by: FinchDon on Sep 19, 2015, 01:03 PM
try spam @Thijn It will give you a great kick anyway  test it.
It show all players who have VIP Greater than 0
Title: Re: VIP
Post by: MacTavish on Sep 19, 2015, 01:13 PM
Better use array intsead query

I mean
onLogin functions
{
stats[player.ID].VIP = GetSQLColumnData( QuerySQL( sqliteDB, "SELECT VIP FROM Accounts WHERE Name='" + player.Name+"'" ), 0 );
}
And cmd
else if ( ( cmd == "vip" ) || ( cmd == "vip" ) )
 {
  local plr, b;
  for( local i = 0; i < GetMaxPlayers(); i++ )
  {
     plr = FindPlayer( i );
  if ( ( plr ) && ( stats[plr.ID].VIP == true ) )
     {
  if ( b ) b = b + ", " + plr.Name + " "
  else b = plr.Name + " "
     }
  }
  if ( b ) Message( "**In Game[ VIP Online: [ " + b + " ] ]" );
  else Message( "** In Game [ No VIP Online ]." );
 }

Since we are just doing query once when they login so this wont have to lag like before @Thijn
Title: Re: VIP
Post by: FinchDon on Sep 19, 2015, 01:17 PM
k i will try thàt @Kusanagi
Title: Re: VIP
Post by: KAKAN on Sep 19, 2015, 01:36 PM
Add that on playerclass
and the rest, think about it.