AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Fast, please. How to get player id? (https://forums.alliedmods.net/showthread.php?t=89352)

DaxProxy 04-05-2009 08:41

[HELP] Fast, please. How to get player id?
 
PHP Code:

public QueryVip(iFailStateHandle:hQueryszError[], iErrnumcData[], iSizeFloat:fQueueTime)
{
    if( 
iFailState != TQUERY_SUCCESS )
    {
        return 
log_amx("[Kz-Arg] SQL: SQL Error #%d - %s"iErrnumszError)
    }
    
    if( 
SQL_MoreResults(hQuery) )
    {
        new 
resultado[2][192]
        new 
punktid
        SQL_ReadResult
(hQuery0resultado[0], 191)
        
SQL_ReadResult(hQuery1resultado[1], 191)
        
punktid str_to_num(resultado[0]) 
    if (
punktid >= 50)
    {
        
client_print(0print_chat"Punktide arv: %s!"resultado[0]) 
        
client_print(0print_chat"Sa ostsid 50 punkti eest endale VIPi!"resultado[0]) 
     }
    else
    {
        
client_print(0print_chat"Sul ei ole piisavalt punkte (%s)!"resultado[0]) 
     }
    }
    return 
PLUGIN_CONTINUE    


QueryVip(iFailState, Handle:hQuery, szError[], iErrnum, cData[], iSize, Float:fQueueTime, id)

If i put ID in there, i get ID=0 Which is not right. Now, resultado[1] is user's name...so is there any way i can get user id from user's name?

fysiks 04-05-2009 08:52

Re: [HELP] Fast, please. How to get player id?
 
cmd_target()

One 04-05-2009 08:58

Re: [HELP] Fast, please. How to get player id?
 
Quote:

Originally Posted by fysiks (Post 797921)

lol? idk why i deleted my post :-))) the same

alan_el_more 04-05-2009 09:41

Re: [HELP] Fast, please. How to get player id?
 
get_user_authid

Bugsy 04-05-2009 09:45

Re: [HELP] Fast, please. How to get player id?
 
Written by |PJ| Shorty
PHP Code:

stock select_user_db(id
{
    new 
data[1]
    
data[0]=id
    formatex
(g_Cache,1023,SEARCH_STEAMID,g_authid[id]);
    
SQL_ThreadQuery(dbc,"SelectHandle",g_Cache,data,sizeof data);
    
server_print"Search for player in db");
}

public 
SelectHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
        return 
set_fail_state("Could not connect to SQL database.");
    else if(
FailState == TQUERY_QUERY_FAILED)
        return 
set_fail_state("SQL Query failed.");
    if(
Errcode)
        return 
log_amx("SQL Error on query: %s",Error);
    
    new 
id=Data[0]
    if(!
SQL_MoreResults(Query)) {
        
//steamid doesn´t exists in db, insert it with status=0 and current timestamp
        
insert_user_db(id,0,get_systime())
        
        return 
PLUGIN_CONTINUE
    
}
    
g_DBstatus[id]=SQL_ReadResult(Query,0)
    
g_DBtimestamp[id]=SQL_ReadResult(Query,1)
    
    
// player is in db, do what you want with the info now
    // values from db stored in "g_DBstatus" and "g_DBtimestamp" vars
    /*
    ...
    //after your code, update the db entry
    update_user_db(id,status,timestamp)
    */
    
    
return PLUGIN_CONTINUE;



DaxProxy 04-05-2009 13:51

Re: [HELP] Fast, please. How to get player id?
 
PHP Code:

#include <amxmodx>
#include <sqlx>
#include <cstrike>
#include <core>
#include <amxmisc>

new Handle:g_SqlTuple
new Handle:SqlConnection
new g_Error[512]

public 
plugin_init() 

    
register_plugin("SMS""SQL""ReymonARG")
    
register_clcmd("say /punkte""func_get_punkte")
    
register_clcmd("say /ostavip""func_get_vip")
    
    
set_task(0.2"plugin_sql")
}

public 
plugin_sql()
{
    new 
host[64], user[64], pass[64], db[64]
    
    
get_cvar_string("amx_sql_host"host63)
    
get_cvar_string("amx_sql_user"user63)
    
get_cvar_string("amx_sql_pass"pass63)
    
get_cvar_string("amx_sql_db"db63)
    
    
g_SqlTuple SQL_MakeDbTuple("Fr546e""frie456a""sa567a""friee45632a")
    
    new 
ErrorCode
    SqlConnection 
SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
    
    if(!
SqlConnection
    {
        
server_print("[Kz-Arg] SQL: Could not connect to SQL database.!")
        
log_amx("[Kz-Arg] SQL: Could not connect to SQL database.")
        return 
pause("a")
    }
    
    
set_task(300.0"func_get_punkte"54564__"b")
    
set_task(300.0"func_get_vip"54564__"b")
    
    return 
PLUGIN_CONTINUE
}

public 
func_get_punkte(id)
{
    new 
createinto[1001]
    new 
name[32]
    
get_user_info(id"name"name,31)
     
formatex(createinto1000"SELECT `punktid`, `name` FROM `ur_users` WHERE `name`='%s'",name)
    
SQL_ThreadQuery(g_SqlTuple"QueryHandler"createinto)
}



public 
QueryHandler(iFailStateHandle:hQueryszError[], iErrnumcData[], iSizeFloat:fQueueTime)
{
    if( 
iFailState != TQUERY_SUCCESS )
    {
        return 
log_amx("[Kz-Arg] SQL: SQL Error #%d - %s"iErrnumszError)
    }
    
    if( 
SQL_MoreResults(hQuery) )
    {
        new 
resultado[2][192]
        
SQL_ReadResult(hQuery0resultado[0], 191)
        
SQL_ReadResult(hQuery1resultado[1], 191)
        
        
client_print(0print_chat"Sul on %s punkti!"resultado[0]) 
    }
    
    return 
PLUGIN_CONTINUE    


public 
func_get_vip(id)
{
    new 
createinto[1001]
    new 
name[32]
    
get_user_info(id"name"name,31)
     
formatex(createinto1000"SELECT `punktid`, `name` FROM `ur_users` WHERE `name`='%s'",name)
    
SQL_ThreadQuery(g_SqlTuple"QueryVip"createinto)
}

public 
QueryVip(iFailStateHandle:hQueryszError[], iErrnumcData[], iSizeFloat:fQueueTime)
{
        new 
resultado[2][192]
        new 
punktid
    
if( iFailState != TQUERY_SUCCESS )
    {
        return 
log_amx("[Kz-Arg] SQL: SQL Error #%d - %s"iErrnumszError)
    }
    
    if( 
SQL_MoreResults(hQuery) )
    {
        
read_argv(1arg31)
        
SQL_ReadResult(hQuery0resultado[0], 191)
        
SQL_ReadResult(hQuery1resultado[1], 191)
        
punktid str_to_num(resultado[0]) 
    if (
punktid >= 50)
    {
        
client_print(0print_chat"Idip: %i"id)
        
client_print(0print_chat"ArgS: %s"id)
        
client_print(0print_chat"ArgD: %d"id)
        
client_print(0print_chat"Punktide arv: %s!"resultado[0]) 
        
client_print(0print_chat"Sa ostsid 50 punkti eest endale VIPi!"resultado[0]) 


        
cs_set_user_vip(1)
HereI need to define USERID in cs_set_user_vip...but HOWHow can i get current user's id?

     }
    else
    {
        client_print(0, print_chat, "Sul ei ole piisavalt punkte (%s)!", resultado[0]) 
     }
    }
    return PLUGIN_CONTINUE    



Bugsy 04-05-2009 14:01

Re: [HELP] Fast, please. How to get player id?
 
Before addressing that, you need to look at your 2 functions that are called with set_task: func_get_punkte and func_get_vip

Neither of these functions are passed a players ID so there is no way to pass a player id to the SQL handler.

You are also using the same task id for both tasks. Make them different, 54564 and 54565 would work.

DaxProxy 04-05-2009 14:08

Re: [HELP] Fast, please. How to get player id?
 
Wait, so there is no way to pass player's ID to SQL handler?

I am new at Pawn...ive programmed VB, PHP, Delphi...but this Pawn...it's killin me.

Bugsy 04-05-2009 14:28

Re: [HELP] Fast, please. How to get player id?
 
I'm not 100% sure of the logic behind your plugin but to get which player is VIP you can use the below. You will need to include cstrike module.

PHP Code:

g_MaxPlayers get_maxplayers();

public 
GetVIP()
{
    for ( new 
<= g_MaxPlayers i++ )
    {
        if ( 
cs_get_user_vip(i) )
        {
            return 
i;
        }
    }
    
    return 
0;



|PJ| Shorty 04-05-2009 14:32

Re: [HELP] Fast, please. How to get player id?
 
sure it is possible

PHP Code:

set_task(300.0"func_get_punkte"id__"b")
...
public 
func_get_punkte(id)
{
    new 
Data[2]
    
Data[0]=id
    
...
     
formatex(createinto1000"SELECT `punktid`, `name` FROM `ur_users` WHERE `name`='%s'",name)
    
SQL_ThreadQuery(g_SqlTuple"QueryHandler"createinto,Data,1)
}
...
public 
QueryVip(iFailStateHandle:hQueryszError[], iErrnumcData[], iSizeFloat:fQueueTime)
{
        new 
id=cData[0]
     
... 




All times are GMT -4. The time now is 02:15.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.