Skocz do zawartości

Witamy w Nieoficjalnym polskim support'cie AMX Mod X

Witamy w Nieoficjalnym polskim support'cie AMX Mod X, jak w większości społeczności internetowych musisz się zarejestrować aby móc odpowiadać lub zakładać nowe tematy, ale nie bój się to jest prosty proces w którym wymagamy minimalnych informacji.
  • Rozpoczynaj nowe tematy i odpowiedaj na inne
  • Zapisz się do tematów i for, aby otrzymywać automatyczne uaktualnienia
  • Dodawaj wydarzenia do kalendarza społecznościowego
  • Stwórz swój własny profil i zdobywaj nowych znajomych
  • Zdobywaj nowe doświadczenia

Dołączona grafika Dołączona grafika

Guest Message by DevFuse
 

Wklejka 13lf8uhliaw0o dodana przez Kawon, 20.08.2012 22:23
Typ:



1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
#include <amxmodx>
#include <sqlx>
 
#define PLUGIN "Tutorial"
#define VERSION "1.0"
#define AUTHOR "Grim"
 
// Ur Mysql Information
new Host[]     = "localhost"
new User[]    = "root"
new Pass[]     = ""
new Db[]     = "fragtrade"
 
 
new Handle:g_SqlTuple
new g_Error[512]
 
 
new iExp[33]
 
 
public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
 
    register_event("DeathMsg", "Event_DeathMsg", "a") // Register death event
 
 
 
 
    set_task(1.0, "MySql_Init") // set a task to activate the mysql_init
}
 
public MySql_Init()
{
    // we tell the API that this is the information we want to connect to,
    // just not yet. basically it's like storing it in global variables
    g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db)
 
    // ok, we're ready to connect
    new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
    if(SqlConnection == Empty_Handle)
        // stop the plugin with an error message
        set_fail_state(g_Error)
 
    new Handle:Queries
    // we must now prepare some random queries
    Queries = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS tutorial (steamid varchar(32),exp INT(11))")
 
    if(!SQL_Execute(Queries))
    {
        // if there were any problems
        SQL_QueryError(Queries,g_Error,charsmax(g_Error))
        set_fail_state(g_Error)
 
    }
 
    // close the handle
    SQL_FreeHandle(Queries)
 
    // you free everything with SQL_FreeHandle
    SQL_FreeHandle(SqlConnection)   
}
 
public plugin_end()
{
    // free the tuple - note that this does not close the connection,
    // since it wasn't connected in the first place
    SQL_FreeHandle(g_SqlTuple)
}
 
public Load_MySql(id)
{
    new szName[32], szTemp[512]
    get_user_name(id, szName, 31)
 
    new Data[1]
    Data[0] = id
 
    //we will now select from the table `tutorial` where the steamid match
    format(szTemp,charsmax(szTemp),"SELECT * FROM `users` WHERE (`users`.`Nick` = '%s')", szName)
    SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
}
 
public register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(FailState == TQUERY_CONNECT_FAILED)
    {
        log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
    }
    else if(FailState == TQUERY_QUERY_FAILED)
    {
        log_amx("Load Query failed. [%d] %s", Errcode, Error)
    }
 
    new id
    id = Data[0]
 
    if(SQL_NumResults(Query) < 1) 
    {
        //.if there are no results found
 
        new szName[32]
        get_user_name(id, szName, 31)
 
        //  if its still pending we can't do anything with it
        if (equal(szName,"ID_PENDING"))
            return PLUGIN_HANDLED
 
        new szTemp[512]
 
        // now we will insturt the values into our table.
        format(szTemp,charsmax(szTemp),"INSERT INTO `users` ( `Nick` , `gotowka`)VALUES ('%s','0');",szName)
        SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
    } 
    else 
    {
        // if there are results found
        iExp[id]         = SQL_ReadResult(Query, 1)
    }
 
    return PLUGIN_HANDLED
}
 
public Save_MySql(id)
{
    new szName[32], szTemp[512]
    get_user_name(id, szName, 31)
 
    // Here we will update the user hes information in the database where the steamid matches.
    format(szTemp,charsmax(szTemp),"UPDATE `users` SET `gotowka` = '%i' WHERE `users`.`Nick` = '%s';",iExp[id], szName)
    SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}
 
public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    SQL_FreeHandle(Query)
 
    return PLUGIN_HANDLED
}
 
public client_putinserver(id)
{
    Load_MySql(id)
}
 
public client_disconnect(id)
{
    Save_MySql(id)
}
 
public Event_DeathMsg()
{
    new iKiller = read_data(1) // read the data to get the killer and victim
    new iVictim = read_data(2)
 
    if(is_user_alive(iKiller)) // Check if the killer is alive in case he killed himself
    {
        if(read_data(3))
        {
            iExp[iKiller] += 0.05 // Add the amount of the Pcvar to iExp
        }
        else
        {
            iExp[iKiller] += 0.05
        }
    }
    iExp[iVictim] -= 0.06 // Decrease the amount of the Pcvar from iExp
}  

Dodanych wklejek: 4031
Powered By (Pav32) Pastebin © 2011