General Played Time

Gameplay Addons
Post Reply
User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1720
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 78 times
Age: 21
Contact:

Played Time

#1

Post by Raheem » 3 Months 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 minutes.
Natives:
  • ze_get_played_time(id) - Will return player time played in seconds. id is the player index to get his time played.
Code:
    1. #include <zombie_escape>
    2. #include <nvault>
    3.  
    4. #define PLAYED_TIME_TASK 9100
    5.  
    6. new const g_szVault_Name[] = "Played_Time"
    7.  
    8. new g_iPlayedTime[33], g_iVaultHandler
    9.  
    10. public plugin_natives()
    11. {
    12.     // Native to return played time in seconds, plugin will save using nVault
    13.     register_native("ze_get_played_time", "native_ze_get_played_time", 1)
    14. }
    15.  
    16. public plugin_init()
    17. {
    18.     register_plugin("Played Time", "1.0", "Raheem")
    19.    
    20.     // Commands
    21.     register_clcmd("say /played", "ShowPlayedTime")
    22.     register_clcmd("say_team /played", "ShowPlayedTime")
    23. }
    24.  
    25. public ShowPlayedTime(id)
    26. {
    27.     ze_colored_print(id, "!tYour played time!y: !g%i !tMinutes!y!", g_iPlayedTime[id]/60)
    28. }
    29.  
    30. public client_putinserver(id)
    31. {
    32.     if(is_user_hltv(id) || is_user_bot(id))
    33.         return
    34.    
    35.     // Just 1 second delay
    36.     set_task(0.5, "DelayLoad", id)
    37.    
    38.     // Save played seconds
    39.     set_task(1.0, "IncreaseTimePlayed", id+PLAYED_TIME_TASK, _, _, "b")
    40. }
    41.  
    42. public DelayLoad(id)
    43. {
    44.     // Load his time played
    45.     LoadPlayedTime(id)
    46. }
    47.  
    48. public IncreaseTimePlayed(taskid)
    49. {
    50.     new id = taskid - PLAYED_TIME_TASK
    51.    
    52.     g_iPlayedTime[id]++
    53. }
    54.  
    55. public client_disconnected(id)
    56. {
    57.     if(is_user_hltv(id) || is_user_bot(id))
    58.         return
    59.    
    60.     // Save played time
    61.     SavePlayedTime(id)
    62.    
    63.     remove_task(id+PLAYED_TIME_TASK)
    64.     remove_task(id)
    65.     g_iPlayedTime[id] = 0
    66. }
    67.  
    68. public SavePlayedTime(id)
    69. {
    70.     new szAuthID[35]
    71.     get_user_authid(id, szAuthID, charsmax(szAuthID))
    72.    
    73.     new szData[128]
    74.     num_to_str(g_iPlayedTime[id], szData, charsmax(szData))
    75.    
    76.     // Open the Vaults
    77.     g_iVaultHandler = nvault_open(g_szVault_Name)
    78.    
    79.     // Saves His Data
    80.     nvault_set(g_iVaultHandler, szAuthID, szData)
    81.    
    82.     // Close Vaults
    83.     nvault_close(g_iVaultHandler)
    84. }
    85.  
    86. public LoadPlayedTime(id)
    87. {
    88.     new szData[128], szAuthID[35]
    89.    
    90.     get_user_authid(id, szAuthID, charsmax(szAuthID))
    91.    
    92.     // Useless Variable
    93.     new iTimestamp, iExists
    94.    
    95.     // Open the Vault
    96.     g_iVaultHandler = nvault_open(g_szVault_Name)
    97.    
    98.     iExists = nvault_lookup(g_iVaultHandler, szAuthID, szData, charsmax(szData), iTimestamp)
    99.    
    100.     // Close Vault
    101.     nvault_close(g_iVaultHandler)
    102.    
    103.     if (!iExists)
    104.     {
    105.         g_iPlayedTime[id] = 0
    106.         SavePlayedTime(id)
    107.     }
    108.     else
    109.     {
    110.         g_iPlayedTime[id] = str_to_num(szData)
    111.     }
    112. }
    113.  
    114. public native_ze_get_played_time(id)
    115. {
    116.     if(!is_user_connected(id))
    117.     {
    118.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    119.         return -1;
    120.     }
    121.    
    122.     return g_iPlayedTime[id]
    123. }
Screenshots:
  • played_time.png
These users thanked the author Raheem for the post:
DarkZombie (3 Months Ago)
You don't know? Learn and you will know.

User avatar
SexY DeviL CJ
Mod Tester
Mod Tester
Posts: 73
Joined: 1 Year Ago
Has thanked: 1 time
Been thanked: 10 times
Contact:

#2

Post by SexY DeviL CJ » 3 Months Ago

viewtopic.php?f=15&t=3378

Already done in this Raheem :p

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

User avatar
Jack GamePlay
Mod Developer
Mod Developer
Egypt
Posts: 532
Joined: 1 Year Ago
Location: Egypt
Has thanked: 31 times
Been thanked: 42 times
Age: 19
Contact:

#3

Post by Jack GamePlay » 3 Months Ago

Add SQL support.
Image

User avatar
sPe3doN
Senior Member
Senior Member
Bosnia & Herzegovina
Posts: 151
Joined: 1 Year Ago
Has thanked: 12 times
Been thanked: 3 times
Age: 20
Contact:

#4

Post by sPe3doN » 3 Months Ago

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

[ Post made via Android ]

Rain1153
Senior Member
Senior Member
India
Posts: 275
Joined: 1 Year Ago
Has thanked: 2 times
Been thanked: 1 time
Age: 18
Contact:

#5

Post by Rain1153 » 3 Months Ago

sPe3doN wrote:
3 Months 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
Egypt
Posts: 1720
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 78 times
Age: 21
Contact:

#6

Post by Raheem » 3 Months Ago

SexY DeviL CJ wrote:
3 Months 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:
3 Months Ago
Add SQL support.
Most users did not use SQL.
sPe3doN wrote:
3 Months 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 (3 Months Ago)
You don't know? Learn and you will know.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest