SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 20/03/2013, 10:04 AM   #1
LiamM
Huge Clucker
 
LiamM's Avatar
 
Join Date: Oct 2010
Location: Edinburgh, Scotland
Posts: 324
Reputation: 36
Question Help with MySQL queries

Hey guys, well I've been scripting for a year or two now but I stopped for a while and have decided to go back to it now.. Problem is with these new 'threaded queries' as 'unthreaded queries' are not supported any longer.

I'm gradually understanding how threaded queries work but there is still is a few dark spots that i'm trying to understand, so possibly someone here could answer this for me.

When a player registers on my server it checks to see if they are banned... now this all worked previously but with these new threaded queries it's a little more complex it would seem.. Before i'd just simply do a query to the server as they connect to check if they were banned. Like such below:

pawn Code:
public OnPlayerConnect(playerid)
{
    TogglePlayerClock(playerid, 1);
    new query[200], Message[256];

    new ip[16];
    GetPlayerIp(playerid, ip, sizeof(ip));

    format(query, sizeof(query), "SELECT * FROM `Banned` WHERE IP = '%s'", ip);
    mysql_query(query);
    mysql_store_result();


    if(mysql_num_rows() >= 1)
    {
        SCM(playerid, COLOR_RED, "You are banned from this server.");
        Kick(playerid);
    }
    mysql_free_result();


How ever, now it needs something in the scope such as a public call and forward... or is that necessary? Trying to understand the way the new threaded queries work is a bit hard for me to grasp. For example... This part

pawn Code:
mysql_function_query(dbHandle, query, true (This is the equivalent to mysql_store_result, right?) , "What Would Go Here?", "i - Would I need a player ID here to check if they are banned?", playerid);


In the that code above I have marked a few parts that I am just... finding hard to understand, someone with knowledge on threaded queries could really help! Thanks

~Liam
__________________
If I helped you at any point! Make sure to rep me by clicking the symbol on the left < Thanks guys!
LiamM is offline   Reply With Quote
Old 20/03/2013, 10:23 AM   #2
shady001
Big Clucker
 
Join Date: Sep 2011
Location: Europe
Posts: 89
Reputation: 0
Default Re: Help with MySQL queries

I know that when you use SELECT you must use a forward and public to be able to work with selected content like :

This:
pawn Code:
public OnPlayerConnect(playerid)
{
    TogglePlayerClock(playerid, 1);
    new query[200], Message[256];

    new ip[16];
    GetPlayerIp(playerid, ip, sizeof(ip));

    format(query, sizeof(query), "SELECT * FROM `Banned` WHERE IP = '%s'", ip);
    mysql_query(query);
    mysql_store_result();


    if(mysql_num_rows() >= 1)
    {
        SCM(playerid, COLOR_RED, "You are banned from this server.");
        Kick(playerid);
    }
    mysql_free_result();
will be:
pawn Code:
public OnPlayerConnect(playerid)
{
    TogglePlayerClock(playerid, 1);
    new query[200], Message[256];

    new ip[16];
    GetPlayerIp(playerid, ip, sizeof(ip));

    format(query, sizeof(query), "SELECT * FROM `Banned` WHERE IP = '%s'", ip);
    mysql_function_query(dbHandel,query,true,"BanResult","i",playerid);
pawn Code:
forward BanResult(playerid);
public BanResult(playerid)
{
 new rows, fields;
 cache_get_data(rows, fields, dbHandle);
  if(rows >= 1)
    {
        SCM(playerid, COLOR_RED, "You are banned from this server.");
        Kick(playerid);
    }
return 1;
}


And BTW you should use a timer to kick player , if you don't he will not recieve the message since 0.3x
shady001 is offline   Reply With Quote
Old 20/03/2013, 10:28 AM   #3
LiamM
Huge Clucker
 
LiamM's Avatar
 
Join Date: Oct 2010
Location: Edinburgh, Scotland
Posts: 324
Reputation: 36
Default Re: Help with MySQL queries

Quote:
Originally Posted by shady001 View Post
I know that when you use SELECT you must use a forward and public to be able to work with selected content like :

This:
pawn Code:
public OnPlayerConnect(playerid)
{
    TogglePlayerClock(playerid, 1);
    new query[200], Message[256];

    new ip[16];
    GetPlayerIp(playerid, ip, sizeof(ip));

    format(query, sizeof(query), "SELECT * FROM `Banned` WHERE IP = '%s'", ip);
    mysql_query(query);
    mysql_store_result();


    if(mysql_num_rows() >= 1)
    {
        SCM(playerid, COLOR_RED, "You are banned from this server.");
        Kick(playerid);
    }
    mysql_free_result();
will be:
pawn Code:
public OnPlayerConnect(playerid)
{
    TogglePlayerClock(playerid, 1);
    new query[200], Message[256];

    new ip[16];
    GetPlayerIp(playerid, ip, sizeof(ip));

    format(query, sizeof(query), "SELECT * FROM `Banned` WHERE IP = '%s'", ip);
    mysql_function_query(dbHandel,query,true,"BanResult","i",playerid);
pawn Code:
forward BanResult(playerid);
public BanResult(playerid)
{
 new rows, fields;
 cache_get_data(rows, fields, dbHandle);
  if(rows >= 1)
    {
        SCM(playerid, COLOR_RED, "You are banned from this server.");
        Kick(playerid);
    }
return 1;
}


And BTW you should use a timer to kick player , if you don't he will not recieve the message since 0.3x
That makes more sense to me, you see... Thanks for that! And with the message and 0.3x.. I stopped scripting at 0.3d so a lot needs updated, how come they will not receive the message?
__________________
If I helped you at any point! Make sure to rep me by clicking the symbol on the left < Thanks guys!
LiamM is offline   Reply With Quote
Old 20/03/2013, 10:29 AM   #4
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,828
Reputation: 1401
Default Re: Help with MySQL queries

pawn Code:
public OnPlayerConnect( playerid )
{
    TogglePlayerClock( playerid, 1 );
    new
        query[ 200 ],
        Message[ 256 ],
        ip[ 16 ]
    ;
    GetPlayerIp( playerid, ip, sizeof( ip ) );

    format( uery, sizeof( query ), "SELECT * FROM `Banned` WHERE IP = '%s'", ip );
    mysql_function_query( Handle, query, true, "OnBanCheck", "d", playerid );
    // Handle = mysql_connect( .. );
}

forward OnBanCheck( playerid );
public OnBanCheck( playerid )
{
    new
        rows,
        fields
    ;
    cache_get_data( rows, fields, Handle );

    if( rows )
    {
        SCM( playerid, COLOR_RED, "You are banned from this server." );
        SetTimerEx( "KickBannedPlayer", 500, false, "i", playerid );
    }
    else
    {
        // goto for register;
    }
    return 1;
}

forward KickBannedPlayer( playerid );
public KickBannedPlayer( playerid )
{
    return Kick( playerid );
}

pawn Code:
mysql_function_query(connectionHandle, query[], bool:cache, callback[], format[], {Float,_}:...);

EDIT: Too late.
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos is offline   Reply With Quote
Old 20/03/2013, 10:37 AM   #5
shady001
Big Clucker
 
Join Date: Sep 2011
Location: Europe
Posts: 89
Reputation: 0
Default Re: Help with MySQL queries

pawn Code:
SetTimerEx("KickPlayer",500,false,"i",playerid);// Kicks player in 500ms

}
forward KickPlayer(playerid);
public KickPlayer(playerid)
{
    Kick(playerid);
    return 1;
}

Any code placed before Kick() will not be executed because Kick() have priority above all other comands...

This is why you have to use timer if you want the client to recieve any messages

Edit : and more about mysql(from where i've learned) : http://forum.sa-mp.com/showthread.php?t=337810
shady001 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Many mySQL queries MP2 Scripting Help 9 09/04/2013 12:49 AM
mysql queries executed - no effect fordawinzz Scripting Help 0 28/01/2013 05:08 PM
MySQL Threaded Queries CONTROLA Scripting Help 4 25/11/2012 03:02 PM
MySQL queries, many or one and huge ? actiwe Help Archive 5 01/09/2010 06:40 PM
Counting with mysql queries actiwe Help Archive 2 26/02/2010 02:36 PM


All times are GMT. The time now is 07:42 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.