AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Played Time Counter (https://forums.alliedmods.net/showthread.php?t=338621)

BerkayF 07-17-2022 13:37

Played Time Counter
 
Played Time Counter
by Berk - BK TEAM


Hi friends
This plugin I have

Increasing Ping on the Server
There are also 5 YapB bots on the Server


PHP Code:

/*
| =============================
| Generated by Berk
| Made in Turkey
| Keep It Ready
| =============================
*/

#include <amxmodx>
#include <amxmisc>
#include <zombieplague>
#include <nvault>

#define PLUGIN "Played Timer"
#define VERSION "BK TEAM - 4.0"
#define AUTHOR "Berk"

new played_time_second[33]
new 
played_time_minute[33]
new 
played_time_hour[33]
new 
played_time_day[33]

new 
p_Vault

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
}

public 
plugin_cfg()
{
    
p_Vault nvault_open("played_time")

    if ( 
p_Vault == INVALID_HANDLE )
        
set_fail_state"Error opening played_time nVault, file does not exist!" )
}

public 
played_time(id)
{
    
set_task(1.0"played_time"id__"b")
    
// It Will Be 1 Minute
    
if(played_time_second[id] != 60)
    {
        
played_time_second[id]++
    }
    
    
// It's Been 1 Minute
    
if(played_time_second[id] == 60)
    {
        
played_time_second[id] = 0
        played_time_minute
[id]++
    }
    
    
// It Will Be 1 Hour
    
if(played_time_minute[id] == 60)
    {
        
played_time_minute[id] = 0
        played_time_hour
[id]++
    }
    
    
// It Will Be 1 Day
    
if(played_time_hour[id] == 24)
    {
        
played_time_hour[id] = 0
        played_time_day
[id]++
    }
}

public 
played_hud(id)
{
    if(
is_user_alive(id))
    
set_task(1.0"played_hud"id__"b")
    
set_hudmessage(802551500.010.1900.51.00.50.5)
    
show_hudmessage(id"[ Played Time System ]^n| Day: %i^n| Hour: %i^n| Minute: %i^n| Second: %i^n[ %s ]"played_time_day[id], played_time_hour[id], played_time_minute[id], played_time_second[id], VERSION)
}

public 
client_putinserver(id)
{
    
set_task(1.0"played_hud"id)
    
set_task(1.0"played_time"id)
}

public 
client_disconnect(id)
{
    
SavePlayed(id)
    
    
played_time_day[id] = 0
    played_time_hour
[id] = 0
    played_time_minute
[id] = 0
    played_time_second
[id] = 0
}

public 
client_connect(id)
{
    
LoadPlayed(id)
}

SavePlayed(id)
{
    new 
szAuth[33];
    new 
szKey[64];
    
    
get_user_authid(id szAuth charsmax(szAuth))
    
formatex(szKey 63 "%s-ID" szAuth)
    
    new 
szData[256]
        
    
formatex(szData 255 "%i#%i#%i#%i" played_time_second[id], played_time_minute[id], played_time_hour[id], played_time_day[id])
    
    
nvault_pset(p_Vault szKey szData)
}

LoadPlayed(id)
{
    new 
szAuth[33];
    new 
szKey[40];
    
    
get_user_authid(id szAuth charsmax(szAuth))
    
formatex(szKey 63 "%s-ID" szAuth)
    
    new 
szData[256];
    
    
formatex(szData 255 "%i#%i#%i#%i" played_time_second[id], played_time_minute[id], played_time_hour[id], played_time_day[id])
    
    
nvault_get(p_VaultszKeyszData255)
    
    
replace_all(szData 255"#"" ")
    new 
day[32], hour[32], minute[32], second[32]
    
parse(szDataday31hour31minute31second31)
    
played_time_day[id] = str_to_num(day)
    
played_time_hour[id] = str_to_num(hour)
    
played_time_minute[id] = str_to_num(minute)
    
played_time_second[id] = str_to_num(second)


I will thank the friend who solved the problem

lexzor 07-17-2022 13:40

Re: Played Time Counter
 
PHP Code:

public client_disconnect(id)
{
    
SavePlayed(id)
    
    
played_time_day[id] = 0
    played_time_hour
[id] = 0
    played_time_minute
[id] = 0
    played_time_second
[id] = 0


to
PHP Code:

#if AMXX_VERSION_NUM < 183
public client_disconnect(id)
#else 
public client_disconnected(id)
#endif
{
    
SavePlayed(id)
    
    
played_time_day[id] = 0
    played_time_hour
[id] = 0
    played_time_minute
[id] = 0
    played_time_second
[id] = 0
    remove_task
(id);


anyways the plugin is really bad

BerkayF 07-18-2022 16:15

Re: Played Time Counter
 
Quote:

Originally Posted by lexzor (Post 2783988)
PHP Code:

public client_disconnect(id)
{
    
SavePlayed(id)
    
    
played_time_day[id] = 0
    played_time_hour
[id] = 0
    played_time_minute
[id] = 0
    played_time_second
[id] = 0


to
PHP Code:

#if AMXX_VERSION_NUM < 183
public client_disconnect(id)
#else 
public client_disconnected(id)
#endif
{
    
SavePlayed(id)
    
    
played_time_day[id] = 0
    played_time_hour
[id] = 0
    played_time_minute
[id] = 0
    played_time_second
[id] = 0
    remove_task
(id);


anyways the plugin is really bad


Thank you, but it's bad that you call my plugin bad >:(

lexzor 07-19-2022 09:39

Re: Played Time Counter
 
you can use a variable for stacking seconds and then converting that seconds in minutes/hour/days. also you could use nvault_lookup instead of nvault_get

fysiks 07-19-2022 22:49

Re: Played Time Counter
 
I have a feeling that you are creating a huge recursion issue here:

PHP Code:

public played_time(id)
{
    
set_task(1.0"played_time"id__"b"

You're setting a repeating task every time played_time() is called inside of played_time(). Basically, you're creating an infinite number of repeating tasks. Not sure if it's ultimately internally limited but clearly it's enough to cause an issue.

Simply move:

PHP Code:

set_task(1.0"played_time"id__"b"

into client_putinserver(). It looks like you do this same thing for player_hud() so fix it the same way.

Also, you should only keep track of the number of seconds and then derive the subsequent time units only as needed i.e. when you display them.

Quote:

Originally Posted by fysiks (Post 2680437)
Use the following code for calculating hours, minutes, and seconds:
Code:

iSeconds = 12345 // your time source in seconds
iHours = iSeconds / 3600
iMinutes = iSeconds % 3600 / 60
iSeconds = iSeconds % 60


Then, to get days:

PHP Code:

iDays iHours 24
iHours 
iHours 24 

Doing this will reduce a whole bunch of your code making it simpler and easier to maintain.


All times are GMT -4. The time now is 15:36.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.