Raised This Month: $18 Target: $400
 4% 

Need Help Sql !


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
SpliN
Junior Member
Join Date: Jun 2020
Location: Egypt
Old 04-14-2021 , 20:03   Need Help Sql !
Reply With Quote #1

hello is this code will work ?
i am not beside my pc so i hope someone do a favour and test it .
and thanks

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#include <hamsandwich>
#include <ColorChat>

new steamid[35][33],points[33],error[512],Handle:connection
new Handle:g_sqldb,g_error[512]
new 
data[40],permhud

public plugin_init()
{
    
register_plugin("Points System" "1.0" ,  "SpliN")
    
    new 
host[64],user[64],pass[64],db[64]
    
get_cvar_string("amx_sql_host",host,63)
    
get_cvar_string("amx_sql_user",user,63)
    
get_cvar_string("amx_sql_pass",pass,63)
    
get_cvar_string("amx_sql_db",db,63)
    
register_event("DeathMsg","playerdeath_event","a")
    
register_concmd("amx_points","givepoints",ADMIN_IMMUNITY,"Usage: amx_points <player> <points>")
    
g_sqldb SQL_MakeDbTuple(host,user,pass,db)
    
permhud CreateHudSyncObj();
    
SQL_ThreadQuery(g_sqldb,"handle","CREATE TABLE IF NOT EXISTS info (steamid VARCHAR(255),points INT(11);")
}

public 
client_putinserver(id)
{
    
set_task(3.0,"ShowSyncHud",id)
}

public 
ShowSyncHud(id)
{
    
set_hudmessage(0255850.760.9126.012.0)
    
ShowSyncHudMsg(id,permhud,"Points: %s",points)
    
}

public 
plugin_end()
{
    
SQL_FreeHandle(g_sqldb)

}

public 
client_connect(id)
{
    new 
errorcode,connection SQL_Connect(g_sqldb,errorcode,error,511)
    if(
connection == Empty_Handle
    {
    
set_fail_state(error
    }
    new 
cache[100]
    
formatex(cache,99,"SELECT points FROM info WHERE steamid = '%s'",steamid[id])
    new 
Handle:query SQL_PrepareQuery(connection,cache)
    if(!
SQL_Execute(query))
    {
        
SQL_QueryError(query,g_error,511)
        
set_fail_state(g_error)
    }
    new 
data
    
while(SQL_MoreResults(query))
    {
        
data SQL_ReadResult(query,0)
        
SQL_NextRow(query)
    }
    
points[id] = data
    SQL_FreeHandle
(query)
    
SQL_FreeHandle(connection)
}

public 
client_authorized(id)
{
    
get_user_authid(id,steamid[id],charsmax(steamid[]))
}

public 
givepoints(id)
{
    new 
arg1[40],arg2[40],name[50],targetname[50]
    
read_argv(1,arg1,39)
    
read_argv(2,arg2,39)
    
get_user_name(id,name,49)
    new 
target cmd_target(id,arg1)
    
get_user_name(target,targetname,49)
    new 
pts str_to_num(arg2)
    
points[target] += pts
    ColorChat
(0,GREEN,"^x01[ADMIN] %s gave %s %i Points",name,targetname,pts)
}

public 
client_disconnect(id)
{
    new 
cache[100]
    
formatex(cache,charsmax(cache),"INSERT INTO info(steamid,points) VALUES(%s,%i);",steamid[id],points[id])
    
SQL_ThreadQuery(g_sqldb,"handle",cache)
}

public 
playerdeath_event(id)
{
    new 
killer read_data(1)
    new 
victim read_data(2)
    new 
headshot read_data(3)
    new 
weapon get_user_weapon(id)
    if(
headshot)
    {
        
points[killer] += 30
        
    
}
    else if(
headshot && weapon == CSW_AWP)
    {
        
points[killer] += 35
    
}
    else if(
weapon == CSW_AWP)
    {
        
points[killer] += 30
    
}
    else if(
weapon == CSW_KNIFE)
    {
        
points[killer] += 35
    
}
    else if(
weapon == CSW_KNIFE && headshot)
    {
        
points[killer] += 40
    
}
    else
    {
        
points[killer] += 15
    
}
}

public 
handle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_QUERY_FAILED)
    {
        
console_print(0,"Query Failed !")

    }
    if(
FailState == TQUERY_CONNECT_FAILED)
    {
        
console_print(0,"Connection Failed !")
    }

SpliN is offline
 


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

Forum Jump


All times are GMT -4. The time now is 06:14.


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