Raised This Month: $ Target: $400
 0% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-05-2009 , 09:45   Re: [HELP] Fast, please. How to get player id?
Reply With Quote #1

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;

__________________

Last edited by Bugsy; 04-05-2009 at 10:48.
Bugsy is offline
DaxProxy
Senior Member
Join Date: Sep 2007
Old 04-05-2009 , 13:51   Re: [HELP] Fast, please. How to get player id?
Reply With Quote #2

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    


Last edited by DaxProxy; 04-05-2009 at 14:10.
DaxProxy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-05-2009 , 14:01   Re: [HELP] Fast, please. How to get player id?
Reply With Quote #3

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.
__________________
Bugsy is offline
Reply



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

Forum Jump


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


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