Approved Infects (MySQL)

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

Infects (MySQL)

#1

Post by Mohamed Alaa » 7 Months Ago

| Description:
  • This plugin is going to be like infects counter for zombies only.

| Cvars:
  • Code: Select all

    ze_infects_host // Host to connect to
    ze_infects_user // User to login with
    ze_infects_pass // Password
    ze_infects_dbname // Database

| Code:
    1. #include <zombie_escape>
    2.  
    3. // Static (Change it if you need)
    4. new const g_szLogFile[] = "Zombie_Infects.log" // MySQL Errors log file
    5.  
    6. // MySQL Table
    7. new const g_szTable[] =
    8. "ALTER TABLE `zombie_escape` ADD IF NOT EXISTS `Infects` INT(10) NOT NULL DEFAULT '0';"
    9.  
    10. // Variables
    11. new g_iInfects[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_infects", "native_ze_get_user_infects", 1)
    30.     register_native("ze_set_user_infects", "native_ze_set_user_infects", 1)
    31. }
    32.  
    33. public plugin_init()
    34. {
    35.     register_plugin("[ZE] Addons: Infects (MySQL)", "1.1", "Jack GamePlay")
    36.    
    37.     // Cvars
    38.     g_pCvarDBInfo[Host] = register_cvar("ze_infects_host", "localhost")
    39.     g_pCvarDBInfo[User] = register_cvar("ze_infects_user", "user")
    40.     g_pCvarDBInfo[Pass] = register_cvar("ze_infects_pass", "pass")
    41.     g_pCvarDBInfo[DB] = register_cvar("ze_infects_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][INFECTS] 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("[INFECTS] 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.     LoadInfects(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_user_infected(iVictim, iInfector)
    111. {
    112.     if (iInfector == 0) // Server ID
    113.         return
    114.  
    115.     g_iInfects[iInfector] ++
    116.     SaveInfects(iInfector)
    117. }
    118.  
    119. LoadInfects(id)
    120. {
    121.     new szAuthID[35], szQuery[128], szData[5]
    122.     get_user_authid(id, szAuthID, charsmax(szAuthID))
    123.     formatex(szQuery, charsmax(szQuery), "SELECT `Infects` FROM `zombie_escape` WHERE ( `SteamID` = '%s' );", szAuthID)
    124.     num_to_str(id, szData, charsmax(szData))
    125.     SQL_ThreadQuery(g_hTuple, "QuerySelectData", szQuery, szData, charsmax(szData))
    126. }
    127.  
    128. public QuerySelectData(iFailState, Handle:hQuery, szError[], iError, szData[])
    129. {
    130.     if (SQL_IsFail(iFailState, iError, szError, g_szLogFile))
    131.         return
    132.    
    133.     new id = str_to_num(szData)
    134.    
    135.     // No results for this query means that player not saved before
    136.     if (!SQL_NumResults(hQuery))
    137.     {
    138.         // This is new player
    139.         g_iInfects[id] = 0
    140.         return
    141.     }
    142.    
    143.     g_iInfects[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "Infects"))
    144. }
    145.  
    146. SaveInfects(id)
    147. {
    148.     new szAuthID[36]
    149.     get_user_authid(id, szAuthID, charsmax(szAuthID))
    150.    
    151.     new szQuery[128]
    152.     formatex(szQuery, charsmax(szQuery), "UPDATE `zombie_escape` SET `Infects` = '%d' WHERE `SteamID` = '%s';", g_iInfects[id], szAuthID)
    153.     SQL_ThreadQuery(g_hTuple, "QueryUpdateData", szQuery)
    154. }
    155.  
    156. public QueryInsertData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
    157. {
    158.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
    159. }
    160.  
    161. public QueryUpdateData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
    162. {
    163.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
    164. }
    165.  
    166. // Natives
    167. public native_ze_get_user_infects(id)
    168. {
    169.     if (!is_user_connected(id))
    170.     {
    171.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    172.         return false
    173.     }
    174.    
    175.     return g_iInfects[id]
    176. }
    177.  
    178. public native_ze_set_user_infects(id, iAmount)
    179. {
    180.     if (!is_user_connected(id))
    181.     {
    182.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    183.         return false
    184.     }
    185.    
    186.     g_iInfects[id] = iAmount
    187.     SaveInfects(id)
    188.     return true
    189. }
Want your own mod edition? PM me.
Accepting web projects.

User avatar
Muhammet20
Veteran Member
Veteran Member
Syria
Posts: 391
Joined: 1 Year Ago
Location: Turkey
Has thanked: 36 times
Been thanked: 5 times
Age: 13
Contact:

#2

Post by Muhammet20 » 7 Months Ago

Great Work Jack
.::Kaya Gaming || Never Give Up || Zombie Escape::. [Server is Under The Work]
https://kaya-gaming.ga/

I just believe in two things, First thing is who i see in the mirror, second thing is who i don't see in the sky.

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

#3

Post by Mohamed Alaa » 3 Weeks 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest