IP [+REP]
#1

Hello i changed my serfer from INI to Database
Now i want to create /aka [IP] to get the accounts of dheese ip
Thank you i need help
Fast
I allso will need something next after will help mee

REMEMBER +REP
Reply
#2

The queries sent to the database can be threaded or non-threaded, there is a different syntax for each one of them. Hoping that you've chosen the threaded ones (mysql_tquery if you're using BlueG's MySQL Plugin), you should take a look at https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_tquery. This wiki page contains all the info you need in order to send a threaded query to the database and process the returned result. In order to extract the parameter of the command, i.e. the IP you are sending with the query, I recommend sscanf. This is the forum page of the sscanf plugin: https://sampforum.blast.hk/showthread.php?tid=120356. This is all you need, it's pretty simple and well explained on the wiki (there, in the example of mysql_tquery).
Reply
#3

I didnt undertand this can you give mee an example with commands ?
Reply
#4

Up
Please someone is good with this help mee
Reply
#5

1. new field in database, preferably in users table called "ip"
2. when the player logs in / registers the ip would be updated to that value
3. make the command with a parameter (zcmd & sscanf is a good way to do that)
4. on the command, use the SELECT to count the amount of rows first
5. retrieve the rows and the other stuff you want to have (score, name, last login etc.)
6. once that's all done add it into a dialog or use SendClientMessage to each one that was found
7. go and test it

I'm not doing it for you, steps are the best way to learn.
Reply
#6

I have already created pIP

But i dont know how to make command
Please DanishHaq Help mee
Reply
#7

We will not script for you, but we will point you in the right direction so you can do it yourself. Firstly you have to understand what you have to do, so this is an interesting tutorial on ZCMD and sscanf: https://sampforum.blast.hk/showthread.php?tid=280476
Don't be lazy and read it from top to bottom. At the end of it, I'm pretty sure that you'll know how to create commands and maybe even more.
Your "script" will look like this:
pawn Код:
forward <your_IP_check_function>;
public <same_function>
{
    //if there are any rows found, go further
    //load the data from the cache
    //use the loaded data
    return 1;
}

CMD:<command_name>(playerid, params[])
{
    //processing the parameters
    //sending the query to sql
    return 1;
}
The ZCMD and sscanf are explained there, in the tutorial that I linked you. For the SQL part, here are the functions you need to know:
- https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_connect - connecting to your SQL database
- https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_tquery - sending the query to sql
- https://sampwiki.blast.hk/wiki/MySQL/R33..._get_row_count or https://sampwiki.blast.hk/wiki/MySQL/R33#cache_get_data - checking if the query produced some results
- https://sampwiki.blast.hk/wiki/MySQL/R33#cache_get_row or https://sampwiki.blast.hk/wiki/MySQL/R33#cache_get_row_int or https://sampwiki.blast.hk/wiki/MySQL/R33..._get_row_float - loading data from cache to local/global variables

These are the pieces of the puzzle, put them together and not only that you'll understand how ZCMD, sscanf and sql works, but you'll also be able to build awesome scripts on your own, using your imagination.
Reply
#8

PHP код:
CMD:searchip(playeridparams[])
{
    if(
pInfo[playerid][pLogged] == 1)
    {
            new 
Query[256];
            if (!
strlen(params)) return SendClientMessage(playerid,-1,""chat" /searchip [IP]");
            
format(Querysizeof(Query), "SELECT * FROM `users` WHERE pIP = '%s'"escstring(params));
            
mysql_query(Query);
            
mysql_store_result();
            if(!
mysql_num_rows())
            {
                new 
string[200];
                
format(stringsizeof(string), ""chat" Nobody account founded with %s IP!"params);
                
mysql_free_result();
                return 
SendClientMessage(playerid,-1,string);
            }
            else if(
mysql_num_rows() != 0)
            {
                
format(Querysizeof(Query), "UPDATE `banlog` SET `pAccountLock` = 0 WHERE Name = '%s'"escstring(params));
                
mysql_query(Query);
                
mysql_store_result();
                new 
string[200];
                
format(stringsizeof(string), ""chat" %s Is founded"params);
                
SendClientMessage(playerid0x66FF33string);
            }
    }
    return 
1;

I created this
It work when the ip dont exist
But i want to show accounts with dhat ip
Reply
#9

Your code gave me cancer... why would you want to unban someone if IPs were found? Wtf? It annoyed me so much I had to do it for you, download sscanf and include it if you don't have it.

pawn Код:
CMD:searchip(playerid, params[])
{
    if(pInfo[playerid][pLogged] != 1) return 1;
    new ip[17];
    if(sscanf(params, "s[17]", ip)) return SendClientMessage(playerid, -1, ""chat" /searchip [IP]");
    new query[70], string[75];
    format(query, sizeof(query), "SELECT `name` FROM `users` WHERE `pIP`='%s'", escstring(ip)); // READ NOTE
    mysql_query(query);
    mysql_store_result();
    if(mysql_num_rows() == 0)
    {
        format(string, sizeof(string), ""chat" Nobody account founded with %s IP!", ip);
        SendClientMessage(playerid, -1, string);
        mysql_free_result();
        return 1;
    }
    else
    {
        format(string, sizeof(string), ""chat" Names found with %s IP:", ip);
        SendClientMessage(playerid, -1, string);
        new count = 1, foundname[MAX_PLAYER_NAME];
        while(mysql_retrieve_row())
        {
            mysql_fetch_field_row(query, "name"); strmid(foundname, query, 0, strlen(query)); // READ NOTE
            format(string, sizeof(string), ""chat" %d: %s", count, foundname);
            SendClientMessage(playerid, -1, string);
            count = count + 1;
        }
    }
    return 1;
}
Where it says READ NOTE, you might have to change where I put `name` and "name" to the field name you have on your database that shows the member's name.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)