Approved Escapes (MySQL)

Gameplay Addons
Post Reply
User avatar
Mohamed Alaa
Mod Developer
Mod Developer
Egypt
Posts: 622
Joined: 2 Years Ago
Location: Egypt
Has thanked: 34 times
Been thanked: 48 times
Age: 19
Contact:

Escapes (MySQL)

#1

Post by Mohamed Alaa » 8 Months Ago

| Description:
  • This plugin is going to be like escapes counter for humans only.

| Cvars:
  • Code: Select all

    ze_escapes_host // Host to connect to
    ze_escapes_user // User to login with
    ze_escapes_pass // Password
    ze_escapes_dbname // Database

| Code:
    1. #include <zombie_escape>
    2.  
    3. // Static (Change it if you need)
    4. new const g_szLogFile[] = "Human_Escapes.log" // MySQL Errors log file
    5.  
    6. // MySQL Table
    7. new const g_szTable[] =
    8. "ALTER TABLE `zombie_escape` ADD IF NOT EXISTS `Escapes` INT(10) NOT NULL DEFAULT '0';"
    9.  
    10. // Variables
    11. new g_iEscapes[33],
    12.     Handle:g_hTuple
    13.  
    14. // Cvars
    15. new g_pCvarDBInfo[4]
    16.  
    17. // Database
    18. enum
    19. {
    20.     Host = 0,
    21.     User,
    22.     Pass,
    23.     DB
    24. }
    25.  
    26. // Natives
    27. public plugin_natives()
    28. {
    29.     register_native("ze_get_user_escapes", "native_ze_get_user_escapes", 1)
    30.     register_native("ze_set_user_escapes", "native_ze_set_user_escapes", 1)
    31. }
    32.  
    33. public plugin_init()
    34. {
    35.     register_plugin("[ZE] Addons: Escapes (MySQL)", "1.1", "Jack GamePlay")
    36.    
    37.     // Cvars
    38.     g_pCvarDBInfo[Host] = register_cvar("ze_escapes_host", "localhost")
    39.     g_pCvarDBInfo[User] = register_cvar("ze_escapes_user", "user")
    40.     g_pCvarDBInfo[Pass] = register_cvar("ze_escapes_pass", "pass")
    41.     g_pCvarDBInfo[DB] = register_cvar("ze_escapes_dbname", "dbname")
    42.  
    43.     // Initialize MySQL - Delay 0.1 second required so we make sure that our zombie_escape.cfg already executed and cvars values loaded from it
    44.     set_task(0.1, "Delay_MySQL_Init")
    45. }
    46.  
    47. public Delay_MySQL_Init()
    48. {
    49.     MySQL_Init()
    50. }
    51.  
    52. public MySQL_Init()
    53. {
    54.     new szHost[64], szUser[32], szPass[32], szDB[128]
    55.    
    56.     get_pcvar_string(g_pCvarDBInfo[Host], szHost, charsmax(szHost))
    57.     get_pcvar_string(g_pCvarDBInfo[User], szUser, charsmax(szUser))
    58.     get_pcvar_string(g_pCvarDBInfo[Pass], szPass, charsmax(szPass))
    59.     get_pcvar_string(g_pCvarDBInfo[DB], szDB, charsmax(szDB))
    60.    
    61.     g_hTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDB)
    62.    
    63.     // Let's ensure that the g_hTuple will be valid, we will access the database to make sure
    64.     new iErrorCode, szError[512], Handle:hSQLConnection
    65.    
    66.     hSQLConnection = SQL_Connect(g_hTuple, iErrorCode, szError, charsmax(szError))
    67.    
    68.     if(hSQLConnection != Empty_Handle)
    69.     {
    70.         log_amx("[MySQL][ESCAPES] Successfully connected to host: %s (ALL IS OK).", szHost)
    71.         SQL_FreeHandle(hSQLConnection)
    72.     }
    73.     else
    74.     {
    75.         // Disable plugin, and display the error
    76.         set_fail_state("[ESCAPES] Failed to connect to MySQL database: %s", szError)
    77.     }
    78.    
    79.     // Create our table
    80.     SQL_ThreadQuery(g_hTuple, "QueryCreateTable", g_szTable)
    81. }
    82.  
    83. public QueryCreateTable(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
    84. {
    85.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
    86. }
    87.  
    88. public client_putinserver(id)
    89. {
    90.     if (is_user_bot(id) || is_user_hltv(id))
    91.         return
    92.    
    93.     // Just 1 second delay
    94.     set_task(1.0, "DelayLoad", id)
    95. }
    96.  
    97. public DelayLoad(id)
    98. {
    99.     LoadEscapes(id)
    100. }
    101.  
    102. public plugin_end()
    103. {
    104.     if (g_hTuple != Empty_Handle)
    105.     {
    106.         SQL_FreeHandle(g_hTuple)
    107.     }
    108. }
    109.  
    110. public ze_roundend(WinTeam)
    111. {
    112.     if (WinTeam == ZE_TEAM_HUMAN)
    113.     {
    114.         for (new id = 0; id <= get_member_game(m_nMaxPlayers); id++)
    115.         {
    116.             if (!is_user_alive(id) || ze_is_user_zombie(id))
    117.                 continue
    118.  
    119.             g_iEscapes[id] ++
    120.             SaveEscapes(id)
    121.         }
    122.     }
    123. }
    124.  
    125. LoadEscapes(id)
    126. {
    127.     new szAuthID[35], szQuery[128], szData[5]
    128.     get_user_authid(id, szAuthID, charsmax(szAuthID))
    129.     formatex(szQuery, charsmax(szQuery), "SELECT `Escapes` FROM `zombie_escape` WHERE ( `SteamID` = '%s' );", szAuthID)
    130.     num_to_str(id, szData, charsmax(szData))
    131.     SQL_ThreadQuery(g_hTuple, "QuerySelectData", szQuery, szData, charsmax(szData))
    132. }
    133.  
    134. public QuerySelectData(iFailState, Handle:hQuery, szError[], iError, szData[])
    135. {
    136.     if (SQL_IsFail(iFailState, iError, szError, g_szLogFile))
    137.         return
    138.    
    139.     new id = str_to_num(szData)
    140.    
    141.     // No results for this query means that player not saved before
    142.     if (!SQL_NumResults(hQuery))
    143.     {
    144.         // This is new player
    145.         g_iEscapes[id] = 0
    146.         return
    147.     }
    148.    
    149.     g_iEscapes[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "Escapes"))
    150. }
    151.  
    152. SaveEscapes(id)
    153. {
    154.     new szAuthID[36], szQuery[128]
    155.     get_user_authid(id, szAuthID, charsmax(szAuthID))
    156.     formatex(szQuery, charsmax(szQuery), "UPDATE `zombie_escape` SET `Escapes` = '%d' WHERE `SteamID` = '%s';", g_iEscapes[id], szAuthID)
    157.     SQL_ThreadQuery(g_hTuple, "QueryUpdateData", szQuery)
    158. }
    159.  
    160. public QueryInsertData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
    161. {
    162.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
    163. }
    164.  
    165. public QueryUpdateData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
    166. {
    167.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
    168. }
    169.  
    170. // Natives
    171. public native_ze_get_user_escapes(id)
    172. {
    173.     if (!is_user_connected(id))
    174.     {
    175.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    176.         return false
    177.     }
    178.    
    179.     return g_iEscapes[id]
    180. }
    181.  
    182. public native_ze_set_user_escapes(id, iAmount)
    183. {
    184.     if (!is_user_connected(id))
    185.     {
    186.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    187.         return false
    188.     }
    189.    
    190.     g_iEscapes[id] = iAmount
    191.     SaveEscapes(id)
    192.     return true
    193. }
Want your own mod edition? PM me.
Accepting web projects.
CS 1.6 hosting: powergamingtech.com

User avatar
Mohamed Alaa
Mod Developer
Mod Developer
Egypt
Posts: 622
Joined: 2 Years Ago
Location: Egypt
Has thanked: 34 times
Been thanked: 48 times
Age: 19
Contact:

#2

Post by Mohamed Alaa » 1 Month Ago

Updated:
  • Updated plugin so all MySQL information will not be stored in several, instead will be stored in 1 column created by Escape Coins
Want your own mod edition? PM me.
Accepting web projects.
CS 1.6 hosting: powergamingtech.com

Post Reply

Who is online

Users browsing this forum: BandiT and 5 guests