Approved Escapes (MySQL)

Gameplay Addons
User avatar
Mohamed Alaa
Mod Developer
Mod Developer
Egypt
Posts: 664
Joined: 3 Years Ago
Location: Egypt
Has thanked: 38 times
Been thanked: 52 times
Age: 20
Contact:

Escapes (MySQL)

#1

Post by Mohamed Alaa » 1 Year 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: 664
Joined: 3 Years Ago
Location: Egypt
Has thanked: 38 times
Been thanked: 52 times
Age: 20
Contact:

#2

Post by Mohamed Alaa » 1 Year 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

User avatar
lizoumapper
Mapper
Mapper
Morocco
Posts: 213
Joined: 1 Year Ago
Location: Morocco
Has thanked: 25 times
Been thanked: 18 times
Age: 18
Contact:

#3

Post by lizoumapper » 2 Months Ago

Add nVault
This is my blog : http://lizoumappercs.ga
GoldSource Engine :D

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 2052
Joined: 3 Years Ago
Location: Egypt
Has thanked: 41 times
Been thanked: 126 times
Age: 22
Contact:

#4

Post by Raheem » 1 Month Ago

nVault is bad :confused: and cause lot of issues like resetting many times. Once we switched all things to MySQL everything is OK :ok_hand: .

BandiT
Member
Member
Romania
Posts: 42
Joined: 1 Year Ago
Has thanked: 4 times
Been thanked: 2 times
Contact:

#5

Post by BandiT » 2 Weeks Ago

Cand you add nvault anyway ?

[ Post made via iPhone ]

BandiT
Member
Member
Romania
Posts: 42
Joined: 1 Year Ago
Has thanked: 4 times
Been thanked: 2 times
Contact:

#6

Post by BandiT » 6 Days Ago

Sorry for double post cand you add nvault on this @raheem pleasee ?

[ Post made via iPhone ]

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 2052
Joined: 3 Years Ago
Location: Egypt
Has thanked: 41 times
Been thanked: 126 times
Age: 22
Contact:

#7

Post by Raheem » 6 Days Ago

BandiT wrote:
6 Days Ago
Sorry for double post cand you add nvault on this @raheem pleasee ?
I don't recommend you to use nVault. SQL is better and easier to deal with and have no resetting issues.

Added nVault support:

  1. #include <zombie_escape>
  2.  
  3. new const g_szVaultName[] = "HumanEscapes"
  4.  
  5. // Static (Change it if you need)
  6. new const g_szLogFile[] = "Human_Escapes.log" // MySQL Errors log file
  7.  
  8. // MySQL Table
  9. new const g_szTable[] =
  10. "ALTER TABLE `zombie_escape` ADD IF NOT EXISTS `Escapes` INT(10) NOT NULL DEFAULT '0';"
  11.  
  12. // Variables
  13. new g_iEscapes[33],
  14.     Handle:g_hTuple,
  15.     g_iVaultHandle
  16.  
  17. // Cvars
  18. new g_pCvarDBInfo[4], g_pCvarSaveType
  19.  
  20. // Database
  21. enum
  22. {
  23.     Host = 0,
  24.     User,
  25.     Pass,
  26.     DB
  27. }
  28.  
  29. // Natives
  30. public plugin_natives()
  31. {
  32.     register_native("ze_get_user_escapes", "native_ze_get_user_escapes", 1)
  33.     register_native("ze_set_user_escapes", "native_ze_set_user_escapes", 1)
  34. }
  35.  
  36. public plugin_init()
  37. {
  38.     register_plugin("[ZE] Addons: Escapes (MySQL)", "1.1", "Jack GamePlay")
  39.    
  40.     // Cvars
  41.     g_pCvarSaveType = register_cvar("ze_escapes_save_type", "1") // 0 =  nVault || 1 = MySQL
  42.     g_pCvarDBInfo[Host] = register_cvar("ze_escapes_host", "localhost")
  43.     g_pCvarDBInfo[User] = register_cvar("ze_escapes_user", "user")
  44.     g_pCvarDBInfo[Pass] = register_cvar("ze_escapes_pass", "pass")
  45.     g_pCvarDBInfo[DB] = register_cvar("ze_escapes_dbname", "dbname")
  46.  
  47.     // Initialize MySQL - Delay 0.1 second required so we make sure that our zombie_escape.cfg already executed and cvars values loaded from it
  48.     set_task(0.1, "Delay_MySQL_Init")
  49. }
  50.  
  51. public Delay_MySQL_Init()
  52. {
  53.     MySQL_Init()
  54. }
  55.  
  56. public MySQL_Init()
  57. {
  58.     if (!get_pcvar_num(g_pCvarSaveType))
  59.         return
  60.    
  61.     new szHost[64], szUser[32], szPass[32], szDB[128]
  62.    
  63.     get_pcvar_string(g_pCvarDBInfo[Host], szHost, charsmax(szHost))
  64.     get_pcvar_string(g_pCvarDBInfo[User], szUser, charsmax(szUser))
  65.     get_pcvar_string(g_pCvarDBInfo[Pass], szPass, charsmax(szPass))
  66.     get_pcvar_string(g_pCvarDBInfo[DB], szDB, charsmax(szDB))
  67.    
  68.     g_hTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDB)
  69.    
  70.     // Let's ensure that the g_hTuple will be valid, we will access the database to make sure
  71.     new iErrorCode, szError[512], Handle:hSQLConnection
  72.    
  73.     hSQLConnection = SQL_Connect(g_hTuple, iErrorCode, szError, charsmax(szError))
  74.    
  75.     if(hSQLConnection != Empty_Handle)
  76.     {
  77.         log_amx("[MySQL][ESCAPES] Successfully connected to host: %s (ALL IS OK).", szHost)
  78.         SQL_FreeHandle(hSQLConnection)
  79.     }
  80.     else
  81.     {
  82.         // Disable plugin, and display the error
  83.         set_fail_state("[ESCAPES] Failed to connect to MySQL database: %s", szError)
  84.     }
  85.    
  86.     // Create our table
  87.     SQL_ThreadQuery(g_hTuple, "QueryCreateTable", g_szTable)
  88. }
  89.  
  90. public QueryCreateTable(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
  91. {
  92.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
  93. }
  94.  
  95. public client_putinserver(id)
  96. {
  97.     if (is_user_bot(id) || is_user_hltv(id))
  98.         return
  99.    
  100.     // Just 1 second delay
  101.     set_task(1.0, "DelayLoad", id)
  102. }
  103.  
  104. public DelayLoad(id)
  105. {
  106.     LoadEscapes(id)
  107. }
  108.  
  109. public plugin_end()
  110. {
  111.     if (!get_pcvar_num(g_pCvarSaveType))
  112.         return
  113.    
  114.     if (g_hTuple != Empty_Handle)
  115.     {
  116.         SQL_FreeHandle(g_hTuple)
  117.     }
  118. }
  119.  
  120. public ze_roundend(WinTeam)
  121. {
  122.     if (WinTeam == ZE_TEAM_HUMAN)
  123.     {
  124.         for (new id = 0; id <= get_member_game(m_nMaxPlayers); id++)
  125.         {
  126.             if (!is_user_alive(id) || ze_is_user_zombie(id))
  127.                 continue
  128.  
  129.             g_iEscapes[id] ++
  130.             SaveEscapes(id)
  131.         }
  132.     }
  133. }
  134.  
  135. LoadEscapes(id)
  136. {
  137.     new szAuthID[35]
  138.     get_user_authid(id, szAuthID, charsmax(szAuthID))
  139.    
  140.     if (!get_pcvar_num(g_pCvarSaveType))
  141.     {
  142.         // Open the Vault
  143.         g_iVaultHandle = nvault_open(g_szVaultName)
  144.        
  145.         // Get escapes
  146.         new szEscapes[16], iExists, iTimestamp;
  147.         iExists = nvault_lookup(g_iVaultHandle, szAuthID, szEscapes, charsmax(szEscapes), iTimestamp);
  148.        
  149.         // Close Vault
  150.         nvault_close(g_iVaultHandle)
  151.        
  152.         if (!iExists)
  153.         {
  154.             SaveEscapes(id)
  155.         }
  156.         else
  157.         {
  158.             g_iEscapes[id] = str_to_num(szEscapes)
  159.         }
  160.     }
  161.     else
  162.     {
  163.         new szQuery[128], szData[5]
  164.  
  165.         formatex(szQuery, charsmax(szQuery), "SELECT `Escapes` FROM `zombie_escape` WHERE ( `SteamID` = '%s' );", szAuthID)
  166.         num_to_str(id, szData, charsmax(szData))
  167.         SQL_ThreadQuery(g_hTuple, "QuerySelectData", szQuery, szData, charsmax(szData))
  168.     }
  169. }
  170.  
  171. public QuerySelectData(iFailState, Handle:hQuery, szError[], iError, szData[])
  172. {
  173.     if (SQL_IsFail(iFailState, iError, szError, g_szLogFile))
  174.         return
  175.    
  176.     new id = str_to_num(szData)
  177.    
  178.     // No results for this query means that player not saved before
  179.     if (!SQL_NumResults(hQuery))
  180.     {
  181.         // This is new player
  182.         g_iEscapes[id] = 0
  183.         return
  184.     }
  185.    
  186.     g_iEscapes[id] = SQL_ReadResult(hQuery, SQL_FieldNameToNum(hQuery, "Escapes"))
  187. }
  188.  
  189. SaveEscapes(id)
  190. {
  191.     new szAuthID[35]
  192.     get_user_authid(id, szAuthID, charsmax(szAuthID))
  193.    
  194.     new szData[16]
  195.     num_to_str(g_iEscapes[id], szData, charsmax(szData))
  196.    
  197.     if (!get_pcvar_num(g_pCvarSaveType))
  198.     {
  199.         // Open the Vault
  200.         g_iVaultHandle = nvault_open(g_szVaultName)
  201.  
  202.         // Save His SteamID, Escape Coins
  203.         nvault_set(g_iVaultHandle, szAuthID, szData)
  204.        
  205.         // Close Vault
  206.         nvault_close(g_iVaultHandle)
  207.     }
  208.     else
  209.     {
  210.         new szQuery[128]
  211.        
  212.         formatex(szQuery, charsmax(szQuery), "UPDATE `zombie_escape` SET `Escapes` = '%d' WHERE `SteamID` = '%s';", g_iEscapes[id], szAuthID)
  213.         SQL_ThreadQuery(g_hTuple, "QueryUpdateData", szQuery)
  214.     }
  215. }
  216.  
  217. public QueryInsertData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
  218. {
  219.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
  220. }
  221.  
  222. public QueryUpdateData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
  223. {
  224.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
  225. }
  226.  
  227. // Natives
  228. public native_ze_get_user_escapes(id)
  229. {
  230.     if (!is_user_connected(id))
  231.     {
  232.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  233.         return false
  234.     }
  235.    
  236.     return g_iEscapes[id]
  237. }
  238.  
  239. public native_ze_set_user_escapes(id, iAmount)
  240. {
  241.     if (!is_user_connected(id))
  242.     {
  243.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  244.         return false
  245.     }
  246.    
  247.     g_iEscapes[id] = iAmount
  248.     SaveEscapes(id)
  249.     return true
  250. }
These users thanked the author Raheem for the post:
BandiT (5 Days Ago)

BandiT
Member
Member
Romania
Posts: 42
Joined: 1 Year Ago
Has thanked: 4 times
Been thanked: 2 times
Contact:

#8

Post by BandiT » 5 Days Ago

Raheem wrote:
6 Days Ago
BandiT wrote:
6 Days Ago
Sorry for double post cand you add nvault on this @raheem pleasee ?
I don't recommend you to use nVault. SQL is better and easier to deal with and have no resetting issues.

Added nVault support:

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

no problem, Tahnk you.

Ca you add a HUD TEXT ON SV to be named Human escapes :1 , to sjow you haw many escape you have ?
and if you can just ADD down here where i marked :

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 2052
Joined: 3 Years Ago
Location: Egypt
Has thanked: 41 times
Been thanked: 126 times
Age: 22
Contact:

#9

Post by Raheem » 5 Days Ago


BandiT
Member
Member
Romania
Posts: 42
Joined: 1 Year Ago
Has thanked: 4 times
Been thanked: 2 times
Contact:

#10

Post by BandiT » 5 Days Ago

Yeah, to show hud message on sv, with how many escapes You did

[ Post made via iPhone ]

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests