General Played Time v1.1

Gameplay Addons
Post Reply
User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2213
Joined: 6 Years Ago
Has thanked: 57 times
Been thanked: 176 times
Age: 26
Contact:

Played Time v1.1

#1

Post by Raheem » 5 Years Ago

Played Time

Description:
  • This plugin will save players played time using nVault. Player can see his played time using a chat command. Also you can get player played time using a native. Saving will be based on player SteamID.
Commands:
  • say /played or say_team /played Chat message will appear to player with his played time in hours, minutes, seconds.
Natives:
  • ze_get_played_time(id) - Will return player time played in seconds. id is the player index to get his time played.
Code: Screenshots:
  • screen.jpg
    ScreenShot
Last edited by z0h1r-LK on 03 Dec 2022, 18:22, edited 3 times in total.
Reason: Update ZIP file
These users thanked the author Raheem for the post (total 2):
DarkZombie (5 Years Ago) • z0h1r-LK (1 Year Ago)
He who fails to plan is planning to fail

User avatar
SexY DeviL CJ
Mod Tester
Mod Tester
Posts: 73
Joined: 5 Years Ago
Has thanked: 1 time
Been thanked: 12 times
Contact:

#2

Post by SexY DeviL CJ » 5 Years Ago

viewtopic.php?f=15&t=3378

Already done in this Raheem :p

[ Post made via Android ]
......Devil Was Here......

User avatar
Night Fury
Mod Developer
Mod Developer
Posts: 677
Joined: 6 Years Ago
Has thanked: 39 times
Been thanked: 58 times
Age: 23
Contact:

#3

Post by Night Fury » 5 Years Ago

Add SQL support.
Want your own mod edition? PM me.
Accepting private projects.
Discord: Fury#7469
Image

User avatar
sPe3doN
Senior Member
Senior Member
Algeria
Posts: 257
Joined: 6 Years Ago
Has thanked: 17 times
Been thanked: 21 times
Age: 24
Contact:

#4

Post by sPe3doN » 5 Years Ago

Can you add free vip time "player who play 50 hour he get VIP for 10 day's" :D

[ Post made via Android ]
Image

Rain1153
Senior Member
Senior Member
India
Posts: 278
Joined: 5 Years Ago
Has thanked: 2 times
Been thanked: 1 time
Age: 23
Contact:

#5

Post by Rain1153 » 5 Years Ago

sPe3doN wrote:
5 Years Ago
Can you add free vip time "player who play 50 hour he get VIP for 10 day's" :D
Use the native in ur vip plugin

[ Post made via Android ]
LOL

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2213
Joined: 6 Years Ago
Has thanked: 57 times
Been thanked: 176 times
Age: 26
Contact:

#6

Post by Raheem » 5 Years Ago

SexY DeviL CJ wrote:
5 Years Ago
viewtopic.php?f=15&t=3378

Already done in this Raheem :p
OH, i don't see it. Anyway no problem i'll keep this.
Jack GamePlay wrote:
5 Years Ago
Add SQL support.
Most users did not use SQL.
sPe3doN wrote:
5 Years Ago
Can you add free vip time "player who play 50 hour he get VIP for 10 day's" :D
To be auto removed, we will need to use something like buy vip plugin.

If he will not removed after 10 days we can do it like:
    1. if (ze_get_played_time(id)/60 >= 50)
    2. {
    3.     ze_set_vip_flags(id, read_flags("abcde"))
    4. }
EDIT:

OK maybe when i get time i'll add a native to add vip to our ze_vips.ini so it can be used so users removed automatically. Will be available next version of VIP system.
Last edited by Raheem on 28 Sep 2018, 10:38, edited 1 time in total.
Reason: More information added
These users thanked the author Raheem for the post:
sPe3doN (5 Years Ago)
He who fails to plan is planning to fail

User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 641
Joined: 6 Years Ago
Location: Tunisia
Has thanked: 15 times
Been thanked: 7 times
Age: 23
Contact:

#7

Post by Spir0x » 4 Years Ago

Guys, exemple i'm the owner of the server and players who play 50 hours will get free vip with this plugin i can see their player time with this native or not ? ze_get_played_time(id)

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2213
Joined: 6 Years Ago
Has thanked: 57 times
Been thanked: 176 times
Age: 26
Contact:

#8

Post by Raheem » 4 Years Ago

Yes you can, but player should be inside the server so you check his played time.
He who fails to plan is planning to fail

User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 641
Joined: 6 Years Ago
Location: Tunisia
Has thanked: 15 times
Been thanked: 7 times
Age: 23
Contact:

#9

Post by Spir0x » 4 Years Ago

Yes raheem, like spe3don said, we need to make this plugin with vip system so player who play +50 hours get free vip with flags we want to add.

fadi
Member
Member
Jordan
Posts: 17
Joined: 3 Years Ago
Has thanked: 1 time
Been thanked: 2 times
Contact:

#10

Post by fadi » 3 Years Ago

i have problem with played time

when I close the server ( shut down ) the played time will reset to 0

why this happen?

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2213
Joined: 6 Years Ago
Has thanked: 57 times
Been thanked: 176 times
Age: 26
Contact:

#11

Post by Raheem » 3 Years Ago

fadi wrote:
3 Years Ago
i have problem with played time

when I close the server ( shut down ) the played time will reset to 0

why this happen?
This occurs mostly because of I'm using nVault, I must turn to MySQL. If you still need it I'll convert it to MySQL to prevent resetting.
He who fails to plan is planning to fail

fadi
Member
Member
Jordan
Posts: 17
Joined: 3 Years Ago
Has thanked: 1 time
Been thanked: 2 times
Contact:

#12

Post by fadi » 3 Years Ago

Raheem wrote:
3 Years Ago
This occurs mostly because of I'm using nVault, I must turn to MySQL. If you still need it I'll convert it to MySQL to prevent resetting.
yeah please do it

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2213
Joined: 6 Years Ago
Has thanked: 57 times
Been thanked: 176 times
Age: 26
Contact:

#13

Post by Raheem » 3 Years Ago

fadi wrote:
3 Years Ago
Raheem wrote:
3 Years Ago
This occurs mostly because of I'm using nVault, I must turn to MySQL. If you still need it I'll convert it to MySQL to prevent resetting.
yeah please do it
Try and let me know if it's working good or not:

  1. #include <zombie_escape>
  2. #include <nvault>
  3.  
  4. new const g_szLogFile[] = "PlayedTime.log" // MySQL Errors log file
  5.  
  6. // MySQL Table
  7. new const g_szTable[] =
  8. " \
  9.    CREATE TABLE IF NOT EXISTS `time_played` \
  10.    ( \
  11.        `SteamID` varchar(34) NOT NULL, \
  12.        `PlayedTime` int(16) NOT NULL, \
  13.        PRIMARY KEY (`SteamID`) \
  14.    ); \
  15. "
  16.  
  17. #define PLAYED_TIME_TASK 9100
  18.  
  19. new const g_szVault_Name[] = "Played_Time"
  20.  
  21. new g_iPlayedTime[33], g_iVaultHandler, Handle:g_hTupleHandler
  22.  
  23. new g_pCvarSaveType, g_pCvarDBInfo[4]
  24.  
  25. // Database
  26. enum
  27. {
  28.     Host = 0,
  29.     User,
  30.     Pass,
  31.     DB
  32. }
  33.  
  34. public plugin_natives()
  35. {
  36.     // Native to return played time in seconds, plugin will save using nVault
  37.     register_native("ze_get_played_time", "native_ze_get_played_time", 1)
  38. }
  39.  
  40. public plugin_init()
  41. {
  42.     register_plugin("Played Time", "1.0", "Raheem")
  43.    
  44.     // Cvars
  45.     g_pCvarSaveType = register_cvar("ze_played_time_save_type", "1") // 0 = nVault, 1 = SQL
  46.     g_pCvarDBInfo[Host] = register_cvar("ze_played_time_host", "localhost")
  47.     g_pCvarDBInfo[User] = register_cvar("ze_played_time_user", "user")
  48.     g_pCvarDBInfo[Pass] = register_cvar("ze_played_time_pass", "pass")
  49.     g_pCvarDBInfo[DB] = register_cvar("ze_played_time_dbname", "dbname")
  50.    
  51.     // Commands
  52.     register_clcmd("say /played", "ShowPlayedTime")
  53.     register_clcmd("say_team /played", "ShowPlayedTime")
  54.    
  55.     // Initialize MySQL - Delay 0.1 second required so we make sure that our zombie_escape.cfg already executed and cvars values loaded from it
  56.     set_task(0.1, "Delay_MySQL_Init")
  57. }
  58.  
  59. public Delay_MySQL_Init()
  60. {
  61.     MySQL_Init()
  62. }
  63.  
  64. public MySQL_Init()
  65. {
  66.     if (!get_pcvar_num(g_pCvarSaveType))
  67.         return
  68.    
  69.     new szHost[64], szUser[32], szPass[32], szDB[128]
  70.    
  71.     get_pcvar_string(g_pCvarDBInfo[Host], szHost, charsmax(szHost))
  72.     get_pcvar_string(g_pCvarDBInfo[User], szUser, charsmax(szUser))
  73.     get_pcvar_string(g_pCvarDBInfo[Pass], szPass, charsmax(szPass))
  74.     get_pcvar_string(g_pCvarDBInfo[DB], szDB, charsmax(szDB))
  75.    
  76.     g_hTupleHandler = SQL_MakeDbTuple(szHost, szUser, szPass, szDB)
  77.    
  78.     // Let's ensure that the g_hTupleHandler will be valid, we will access the database to make sure
  79.     new iErrorCode, szError[512], Handle:hSQLConnection
  80.    
  81.     hSQLConnection = SQL_Connect(g_hTupleHandler, iErrorCode, szError, charsmax(szError))
  82.    
  83.     if(hSQLConnection != Empty_Handle)
  84.     {
  85.         log_amx("[MySQL] Successfully connected to host: %s (ALL IS OK).", szHost)
  86.         SQL_FreeHandle(hSQLConnection)
  87.     }
  88.     else
  89.     {
  90.         // Disable plugin, and display the error
  91.         set_fail_state("Failed to connect to MySQL database: %s", szError)
  92.     }
  93.    
  94.     // Create our table
  95.     SQL_ThreadQuery(g_hTupleHandler, "QueryCreateTable", g_szTable)
  96. }
  97.  
  98. public QueryCreateTable(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
  99. {
  100.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
  101. }
  102.  
  103. public ShowPlayedTime(id)
  104. {
  105.     ze_colored_print(id, "!tYour played time!y: !g%i !tMinutes!y!", g_iPlayedTime[id]/60)
  106. }
  107.  
  108. public client_putinserver(id)
  109. {
  110.     if(is_user_hltv(id) || is_user_bot(id))
  111.         return
  112.    
  113.     // Just 1 second delay
  114.     set_task(0.5, "DelayLoad", id)
  115.    
  116.     // Save played seconds
  117.     set_task(1.0, "IncreaseTimePlayed", id+PLAYED_TIME_TASK, _, _, "b")
  118. }
  119.  
  120. public DelayLoad(id)
  121. {
  122.     // Load his time played
  123.     LoadPlayedTime(id)
  124. }
  125.  
  126. public IncreaseTimePlayed(taskid)
  127. {
  128.     new id = taskid - PLAYED_TIME_TASK
  129.    
  130.     g_iPlayedTime[id]++
  131. }
  132.  
  133. public client_disconnected(id)
  134. {
  135.     if(is_user_hltv(id) || is_user_bot(id))
  136.         return
  137.    
  138.     // Save played time
  139.     SavePlayedTime(id)
  140.    
  141.     remove_task(id+PLAYED_TIME_TASK)
  142.     remove_task(id)
  143.     g_iPlayedTime[id] = 0
  144. }
  145.  
  146. SavePlayedTime(id)
  147. {
  148.     new szAuthID[35]
  149.     get_user_authid(id, szAuthID, charsmax(szAuthID))
  150.    
  151.     new szData[128]
  152.     num_to_str(g_iPlayedTime[id], szData, charsmax(szData))
  153.    
  154.     if (!get_pcvar_num(g_pCvarSaveType))
  155.     {
  156.         // Open the Vaults
  157.         g_iVaultHandler = nvault_open(g_szVault_Name)
  158.    
  159.         // Saves His Data
  160.         nvault_set(g_iVaultHandler, szAuthID, szData)
  161.    
  162.         // Close Vaults
  163.         nvault_close(g_iVaultHandler)
  164.     }
  165.     else
  166.     {
  167.         new szQuery[128]
  168.         formatex(szQuery, charsmax(szQuery), "UPDATE `time_played` SET `PlayedTime` = '%d' WHERE `SteamID` = '%s';", g_iPlayedTime[id], szAuthID)
  169.         SQL_ThreadQuery(g_hTupleHandler, "QueryUpdateData", szQuery)
  170.     }
  171. }
  172.  
  173. public plugin_end()
  174. {
  175.     if (get_pcvar_num(g_pCvarSaveType))
  176.     {
  177.         if (g_hTupleHandler != Empty_Handle)
  178.         {
  179.             SQL_FreeHandle(g_hTupleHandler)
  180.         }
  181.     }
  182. }
  183.  
  184. public QueryUpdateData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
  185. {
  186.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
  187. }
  188.  
  189. LoadPlayedTime(id)
  190. {
  191.     new szData[128], szAuthID[35]
  192.    
  193.     get_user_authid(id, szAuthID, charsmax(szAuthID))
  194.    
  195.     if (!get_pcvar_num(g_pCvarSaveType))
  196.     {
  197.         // Useless Variable
  198.         new iTimestamp, iExists
  199.        
  200.         // Open the Vault
  201.         g_iVaultHandler = nvault_open(g_szVault_Name)
  202.        
  203.         iExists = nvault_lookup(g_iVaultHandler, szAuthID, szData, charsmax(szData), iTimestamp)
  204.        
  205.         // Close Vault
  206.         nvault_close(g_iVaultHandler)
  207.        
  208.         if (!iExists)
  209.         {
  210.             g_iPlayedTime[id] = 0
  211.             SavePlayedTime(id)
  212.         }
  213.         else
  214.         {
  215.             g_iPlayedTime[id] = str_to_num(szData)
  216.         }
  217.     }
  218.     else
  219.     {
  220.         new szQuery[128], szData[5]
  221.         formatex(szQuery, charsmax(szQuery), "SELECT `PlayedTime` FROM `time_played` WHERE ( `SteamID` = '%s' );", szAuthID)
  222.      
  223.         num_to_str(id, szData, charsmax(szData))
  224.         SQL_ThreadQuery(g_hTupleHandler, "QuerySelectData", szQuery, szData, charsmax(szData))
  225.     }
  226. }
  227.  
  228. public QuerySelectData(iFailState, Handle:hQuery, szError[], iError, szData[])
  229. {
  230.     if(SQL_IsFail(iFailState, iError, szError, g_szLogFile))
  231.         return
  232.    
  233.     new id = str_to_num(szData)
  234.    
  235.     // No results for this query means that player not saved before
  236.     if(!SQL_NumResults(hQuery))
  237.     {
  238.         // This is new player
  239.         g_iPlayedTime[id] = 0
  240.        
  241.         // Get user steamid
  242.         new szAuthID[36]
  243.         get_user_authid(id, szAuthID, charsmax(szAuthID))
  244.        
  245.         // Insert his data to our database
  246.         new szQuery[128]
  247.        
  248.         formatex(szQuery, charsmax(szQuery), "INSERT INTO `time_played` (`SteamID`, `PlayedTime`) VALUES ('%s', '%d');", szAuthID, g_iPlayedTime[id])
  249.         SQL_ThreadQuery(g_hTupleHandler, "QueryInsertData", szQuery)
  250.        
  251.         return
  252.     }
  253.    
  254.     new iPlayedTimeColumn = SQL_FieldNameToNum(hQuery, "PlayedTime")
  255.    
  256.     // Read the played time for this player
  257.     g_iPlayedTime[id] = SQL_ReadResult(hQuery, iPlayedTimeColumn)
  258. }
  259.  
  260. public QueryInsertData(iFailState, Handle:hQuery, szError[], iError, szData[], iSize, Float:flQueueTime)
  261. {
  262.     SQL_IsFail(iFailState, iError, szError, g_szLogFile)
  263. }
  264.  
  265. public native_ze_get_played_time(id)
  266. {
  267.     if(!is_user_connected(id))
  268.     {
  269.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  270.         return -1;
  271.     }
  272.    
  273.     return g_iPlayedTime[id]
  274. }
Last edited by Raheem on 10 Oct 2020, 11:20, edited 1 time in total.
Reason: Forget plugin_end(), UPDATED.
These users thanked the author Raheem for the post (total 2):
fadi (2 Years Ago) • z0h1r-LK (1 Year Ago)
He who fails to plan is planning to fail

User avatar
z0h1r-LK
Mod Developer
Mod Developer
Morocco
Posts: 447
Joined: 4 Years Ago
Location: Morocco
Has thanked: 139 times
Been thanked: 48 times
Age: 21
Contact:

#14

Post by z0h1r-LK » 1 Year Ago

Updated to v1.1
  • Optimized Codes.
  • Displays played as seconds, minutes, hours.
Last edited by z0h1r-LK on 03 Dec 2022, 18:07, edited 1 time in total.
Reason: We back set_task method :|

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 600
Joined: 6 Years Ago
Has thanked: 22 times
Been thanked: 17 times
Contact:

#15

Post by czirimbolo » 1 Year Ago

the time resets on every map = useless
Image

User avatar
z0h1r-LK
Mod Developer
Mod Developer
Morocco
Posts: 447
Joined: 4 Years Ago
Location: Morocco
Has thanked: 139 times
Been thanked: 48 times
Age: 21
Contact:

#16

Post by z0h1r-LK » 1 Year Ago

czirimbolo wrote:
1 Year Ago
the time resets on every map = useless
I've tried that before post it !!

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 600
Joined: 6 Years Ago
Has thanked: 22 times
Been thanked: 17 times
Contact:

#17

Post by czirimbolo » 1 Year Ago

z0h1r-LK wrote:
1 Year Ago
czirimbolo wrote:
1 Year Ago
the time resets on every map = useless
I've tried that before post it !!
and? Its not working good
These users thanked the author czirimbolo for the post:
z0h1r-LK (1 Year Ago)
Image

User avatar
z0h1r-LK
Mod Developer
Mod Developer
Morocco
Posts: 447
Joined: 4 Years Ago
Location: Morocco
Has thanked: 139 times
Been thanked: 48 times
Age: 21
Contact:

#18

Post by z0h1r-LK » 1 Year Ago

@czirimbolo Check PM!

Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Who is online

Users browsing this forum: No registered users and 4 guests