Raised This Month: $51 Target: $400
 12% 

Played Time Money Bonus


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tarsisd2
Veteran Member
Join Date: Feb 2016
Location: brazil
Old 04-21-2019 , 12:02   Played Time Money Bonus
Reply With Quote #1

hi guys, i'm using a plugin which gives all the players on the server money bonus each round for the time played
1hr = 250
2hr = 500
3hr = 1000
4hr = 2000
5hr = 5000

it uses nvault, so even after a mapchange it is supposed to remember

i tested yesterday and a found a bug, i played for a straight 3 hours on the server and i only got 1hr bonus all the time $250, can any one fix this, maybe some code optimization!

PHP Code:
#include <amxmodx>
#include <cstrike>
#include <nvault>

#define MM_HOUR 3600

enum ChatColor
{
    
CHATCOLOR_NORMAL 1,
    
CHATCOLOR_GREEN,
    
CHATCOLOR_TEAM_COLOR,
    
CHATCOLOR_GREY,     
    
CHATCOLOR_RED,         
    
CHATCOLOR_BLUE,     
}

new 
g_TeamName[][] = 
{
    
"",
    
"TERRORIST",
    
"CT",
    
"SPECTATOR"
}

new 
g_msgSayText
new g_msgTeamInfo

new const gNazwaPluginu[] = "Play Time Bonus";
new const 
gWersjaPluginu[] = "0.1";
new const 
gAutorPluginu[] = "MisieQ";

new 
pcvar_ptpcvar_pt_bonuspcvar_pt_bonus_1hpcvar_pt_bonus_2hpcvar_pt_bonus_3hpcvar_pt_bonus_4hpcvar_pt_bonus_5h
new g_Vault

public plugin_init()
{
    
register_plugin(gNazwaPluginugWersjaPluginugAutorPluginu);
    
    
pcvar_pt register_cvar("pt_enabled""1")
    
pcvar_pt_bonus register_cvar("pt_bonus""1")
    
pcvar_pt_bonus_1h register_cvar("pt_bonus_1h""250")
    
pcvar_pt_bonus_2h register_cvar("pt_bonus_2h""500")
    
pcvar_pt_bonus_3h register_cvar("pt_bonus_3h""1000")
    
pcvar_pt_bonus_4h register_cvar("pt_bonus_4h""2000")
    
pcvar_pt_bonus_5h register_cvar("pt_bonus_5h""5000")
    
    
register_event("SendAudio""eventEndRound""a""2=%!MRAD_terwin""2=%!MRAD_ctwin""2=%!MRAD_rounddraw")
    
    
g_msgSayText get_user_msgid("SayText")
    
g_msgTeamInfo get_user_msgid("TeamInfo"
}

public 
plugin_cfg()
{
    if(
get_pcvar_num(pcvar_pt))
    {
        
g_Vault nvault_open("play_time")
    
        if(
g_Vault == INVALID_HANDLE)
        {
            
set_fail_state("Error opening nVault")
        }
        
        
nvault_prune(g_Vault get_systime() - (30 86400 ))
    }
}

public 
plugin_end()
{
    if(
get_pcvar_num(pcvar_pt))
    {
        
nvault_close(g_Vault)
    }
}

public 
client_disconnect(id)
{
    if(
get_pcvar_num(pcvar_pt))
    {
        
played_time(id)
    }
}

public 
eventEndRound()
{
    
time_play_bonus()
}

public 
played_time(id)
{
    new 
szPlayers[32], iNumszKey[32], szData[128], szName[32]
    
    new 
szMinute[5], szHour[5], szDay[5], szMonth[5], szYear[5]
    new 
iMinuteiHouriDayiMonthiYear
        
    format_time
(szMinutesizeof(szMinute) - 1"%M")
    
format_time(szHoursizeof(szHour) - 1"%H")
    
format_time(szDaysizeof(szDay) - 1"%d")
    
format_time(szMonthsizeof(szMonth) - 1"%m")
    
format_time(szYearsizeof(szYear) - 1"%Y")
    
    
iMinute str_to_num(szMinute)
    
iHour str_to_num(szHour)
    
iDay str_to_num(szDay)
    
iMonth str_to_num(szMonth)
    
iYear str_to_num(szYear)
    
    
get_players(szPlayersiNum)
    
    
get_user_name(idszNamesizeof(szName) - 1)
    
formatex(szKeysizeof(szKey) - 1"PLAYED_TIME#%s"szName)
    
    
nvault_get(g_VaultszKeyszDatasizeof(szData) - 1)
    
    new 
iTime str_to_num(szData)
    
    
formatex(szDatasizeof(szData) - 1"%d"iTime + (get_user_time(id)))
    
    
nvault_set(g_Vault szKeyszData
    
    
formatex(szKeysizeof(szKey) - 1"LAST_VISIT#%s"szName)
    
formatex(szDatasizeof(szData) - 1"%d %d %d %d %d"iDayiMonthiYear,iHouriMinute)
    
nvault_set(g_Vault szKeyszData)
    
    
formatex(szKeysizeof(szKey) - 1"TODAY_PLAY#%s"szName)
    
nvault_get(g_VaultszKeyszDatasizeof(szData) - 1)
    
    new 
szToday[5], szTodayPlay[256]
    
parse(szDataszTodaysizeof(szToday), szTodayPlaysizeof(szTodayPlay))
    
    if(
str_to_num(szToday) != iDay)
    {
        
formatex(szDatasizeof(szData) - 1"%d 0"iDay)
        
nvault_set(g_Vault szKeyszData)
    }
    else
    {
        
formatex(szDatasizeof(szData) - 1"%d %d"iDay, (get_user_time(id) + str_to_num(szTodayPlay)))
        
nvault_set(g_Vault szKeyszData)
    }
}

public 
time_play_bonus()
{
    if(!
get_pcvar_num(pcvar_pt_bonus) || !get_pcvar_num(pcvar_pt))
    {
        return 
PLUGIN_HANDLED
    
}
        
    new 
iCashiTmpCashiDayszDay[5]
    new 
szPlayers[32], iNumszName[32]
    new 
szKey[50], szData[128]
    
    new 
iCash_1h get_pcvar_num(pcvar_pt_bonus_1h)
    new 
iCash_2h get_pcvar_num(pcvar_pt_bonus_2h)
    new 
iCash_3h get_pcvar_num(pcvar_pt_bonus_3h)
    new 
iCash_4h get_pcvar_num(pcvar_pt_bonus_4h)
    new 
iCash_5h get_pcvar_num(pcvar_pt_bonus_5h)
        
    
format_time(szDaysizeof(szDay) - 1"%d")
    
iDay str_to_num(szDay)
        
    
get_players(szPlayersiNum)
    for(new 
0iNumi++)
    {
        if(
cs_get_user_team(szPlayers[i]) == CS_TEAM_SPECTATOR)
        {
            continue
        }
        
        
get_user_name(szPlayers[i], szNamesizeof(szName) - 1)
        
formatex(szKeysizeof(szKey) - 1"TODAY_PLAY#%s"szName)
        
nvault_get(g_VaultszKeyszDatasizeof(szData) - 1)
        
        new 
szToday[5], szTodayPlay[256]
        
parse(szDataszTodaysizeof(szToday), szTodayPlaysizeof(szTodayPlay))
                
        if(
iDay != str_to_num(szToday))
        {
            
formatex(szDatasizeof(szData) - 1"%d 0"iDay)
            
nvault_set(g_VaultszKeyszData)
                        
            continue
        }
        
        new 
iTime = (get_user_time(szPlayers[i]) + str_to_num(szTodayPlay)) / MM_HOUR
        
        iCash 
cs_get_user_money(szPlayers[i])

        if(!
iTime)
        {
            continue
        }
        
        if(
iTime == && iCash_1h != 0)
        {        
            if((
iCash iCash_1h) > 16000)
            {
                
cs_set_user_money(szPlayers[i], 16000)
            }
            else
            {
                
cs_set_user_money(szPlayers[i], iCash iCash_1h)
            }
            
iTmpCash iCash_1h
        
}
        
        if(
iTime == && iCash_2h != 0)
        {        
            if((
iCash iCash_2h) > 16000)
            {
                
cs_set_user_money(szPlayers[i], 16000)
            }
            else
            {
                
cs_set_user_money(szPlayers[i], iCash iCash_2h)
            }
            
iTmpCash iCash_2h
        
}
        
        if(
iTime == && iCash_3h != 0)
        {        
            if((
iCash iCash_3h) > 16000)
            {
                
cs_set_user_money(szPlayers[i], 16000)
            }
            else
            {
                
cs_set_user_money(szPlayers[i], iCash iCash_3h)
            }
            
iTmpCash iCash_3h
        
}
        
        if(
iTime == && iCash_4h != 0)
        {        
            if((
iCash iCash_4h) > 16000)
            {
                
cs_set_user_money(szPlayers[i], 16000)
            }
            else
            {
                
cs_set_user_money(szPlayers[i], iCash iCash_4h)
            }
            
iTmpCash iCash_4h
        
}
        
        if(
iTime && iCash_5h != 0)
        {        
            if((
iCash iCash_5h) > 16000)
            {
                
cs_set_user_money(szPlayers[i], 16000)
            }
            else
            {
                
cs_set_user_money(szPlayers[i], iCash iCash_5h)
            }
            
iTmpCash iCash_5h
        
}
        
        
colorChat(szPlayers[i], CHATCOLOR_GREEN"You played $t%d h.$g and got a bonus of $t%d$$g"iTimeiTmpCash)
        
        
    }
    
    return 
PLUGIN_HANDLED
}

colorChat(idChatColor:color, const msg[], {Float,Sql,Result,_}:...)
{
    new 
teamindexMSG_Type
    
new bool:teamChanged false
    
static message[192]
    
    switch(
color)
    {
        case 
CHATCOLOR_NORMAL// Normal
        
{
            
message[0] = 0x01;
        }
        case 
CHATCOLOR_GREEN// Green
        
{
            
message[0] = 0x04;
        }
        default: 
// Grey, Red, Blue
        
{
            
message[0] = 0x03;
        }
    }
    
    
vformat(message[1], 190msg4);
    
replace_all(message190"$g""^x04")
    
replace_all(message190"$n""^x01")
    
replace_all(message190"$t""^x03")
        
    if(
id == 0)
    {
        
index findAnyPlayer();
        
MSG_Type MSG_ALL;
    }
    else
    {
        
index id;
        
MSG_Type MSG_ONE;
    }
    if(
index != 0)
    {
        
team get_user_team(index);    
        if(
color == CHATCOLOR_RED && team != 1)
        {
            
messageTeamInfo(indexMSG_Typeg_TeamName[1])
            
teamChanged true
        
}
        else
        if(
color == CHATCOLOR_BLUE && team != 2)
        {
            
messageTeamInfo(indexMSG_Typeg_TeamName[2])
            
teamChanged true
        
}
        else
        if(
color == CHATCOLOR_GREY && team != 0)
        {
            
messageTeamInfo(indexMSG_Typeg_TeamName[0])
            
teamChanged true
        
}
        
messageSayText(indexMSG_Typemessage);
        if(
teamChanged)
        {
            
messageTeamInfo(indexMSG_Typeg_TeamName[team])
        }
    }
}

messageSayText(idtypemessage[])
{
    
message_begin(typeg_msgSayText_id)
    
write_byte(id)        
    
write_string(message)
    
message_end()
}
    
messageTeamInfo(idtypeteam[])
{
    
message_begin(typeg_msgTeamInfo_id)
    
write_byte(id)
    
write_string(team)
    
message_end()
}

findAnyPlayer()
{
    static 
players[32], inumpid
    
    get_players
(playersinum"ch")
    
    for (new 
0inuma++)
    {
        
pid players[a]
        if(
is_user_connected(pid))
            return 
pid
    
}
    
    return 
0

thanks
tarsisd2 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-21-2019 , 13:19   Re: Played Time Money Bonus
Reply With Quote #2

Is the desire to issue a bonus only for the play time in a given day/connection? It looks like the plugin is saving multiple types of play time but only uses the today play time. Only 1 of each bonus credit per day?
__________________

Last edited by Bugsy; 04-21-2019 at 13:21.
Bugsy is offline
tarsisd2
Veteran Member
Join Date: Feb 2016
Location: brazil
Old 04-21-2019 , 14:29   Re: Played Time Money Bonus
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
Is the desire to issue a bonus only for the play time in a given day/connection? It looks like the plugin is saving multiple types of play time but only uses the today play time. Only 1 of each bonus credit per day?
i want the player to receive money bonus for every connection without leaving, even on map change, if the player is connected for 3 hours straight, he gets $1000 bucks every round, maybe put a 2 minute limit that the player can stay out of the server, but say if the player is on my server for 1 hour and 45 minutes, he is getting $250 each round, but if he leaves my server for more than 2 minutes, when he comes back, start counting from 0

i think you get the point
tarsisd2 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-21-2019 , 15:07   Re: Played Time Money Bonus
Reply With Quote #4

Yup, thanks
__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-21-2019 , 20:51   Re: Played Time Money Bonus
Reply With Quote #5

Untested. Requires nVault Array, if using an ancient AMX-X build, be sure to also download the fixed nVault module.
PHP Code:

#include <amxmodx>
#include <cstrike>
#include <nvault_array>

new const Version[] = "0.1";

enum ChatColor
{
    
CHATCOLOR_NORMAL 1,
    
CHATCOLOR_GREEN,
    
CHATCOLOR_TEAM_COLOR,
    
CHATCOLOR_GREY,     
    
CHATCOLOR_RED,         
    
CHATCOLOR_BLUE,     
}

new 
g_TeamName[][] = 
{
    
"",
    
"TERRORIST",
    
"CT",
    
"SPECTATOR"
};


enum PlayTimeData
{
    
ConnectTime,
    
AuthID34 ],
    
TotalTime,
    
LastDisconnect
}

new 
ptdDataMAX_PLAYERS ][ PlayTimeData ];

new 
g_msgSayText g_msgTeamInfo;
new 
pcvar_ptpcvar_pt_bonus pcvar_pt_bonusDollars] , pcvar_pt_disconnecthreshold;
new 
g_Vault;

public 
plugin_init()
{
    
register_plugin"Play Time Bonus" Version "bugsy" );
    
    
pcvar_pt register_cvar"pt_enabled" "1" );
    
pcvar_pt_bonus register_cvar"pt_bonus""1" );
    
pcvar_pt_bonusDollars] = register_cvar"pt_bonus_1h" "250" );
    
pcvar_pt_bonusDollars] = register_cvar"pt_bonus_2h" "500" );
    
pcvar_pt_bonusDollars] = register_cvar"pt_bonus_3h" "1000" );
    
pcvar_pt_bonusDollars] = register_cvar"pt_bonus_4h" "2000" );
    
pcvar_pt_bonusDollars] = register_cvar"pt_bonus_5h" "5000" );
    
pcvar_pt_disconnecthreshold register_cvar"pt_disconnect_thresholdsecs" "120" );
    
    
register_event"SendAudio" "eventEndRound" "a" "2=%!MRAD_terwin" "2=%!MRAD_ctwin" "2=%!MRAD_rounddraw" );
    
    
g_msgSayText get_user_msgid"SayText" );
    
g_msgTeamInfo get_user_msgid"TeamInfo" );
}

public 
plugin_cfg()
{
    if ( 
get_pcvar_numpcvar_pt ) )
    {
        if ( ( 
g_Vault nvault_open"PlayTimeVault" ) ) == INVALID_HANDLE )
        {
            
set_fail_state"Error opening nVault" );
        }
        
        
nvault_pruneg_Vault get_systime() - ( 30 86400 ) );
    }
}

public 
plugin_end()
{
    if ( 
get_pcvar_numpcvar_pt ) )
    {
        
nvault_closeg_Vault );
    }
}

public 
client_authorizedid )
{
    if ( 
get_pcvar_numpcvar_pt ) && !is_user_botid ) )
    {
        
get_user_authidid ptdDataid ][ AuthID ] , charsmaxptdData[] ) );
        
nvault_get_arrayg_Vault ptdDataid ][ AuthID ] , ptdDataid ][ PlayTimeData:] , sizeofptdData[] ) );
        
        if ( ( 
get_systime() - ptdDataid ][ LastDisconnect ] ) >= get_pcvar_numpcvar_pt_disconnecthreshold ) )
        {
            
ptdDataid ][ TotalTime ] = 0;
        }
        
        
ptdDataid ][ ConnectTime ] = get_systime();
    }
}

public 
client_disconnectedid )
{
    if ( 
get_pcvar_numpcvar_pt ) && !is_user_botid ) )
    {
        
ptdDataid ][ LastDisconnect ] = get_systime();
        
ptdDataid ][ TotalTime ] += ( get_systime() - ptdDataid ][ ConnectTime ] );

        
nvault_set_arrayg_Vault ptdDataid ][ AuthID ] , ptdDataid ][ PlayTimeData:] , sizeofptdData[] ) );
    }
}

public 
eventEndRound()
{
    
IssueBonus();
}

public 
IssueBonus()
{
    if ( !
get_pcvar_numpcvar_pt_bonus ) || !get_pcvar_numpcvar_pt ) )
        return;
        
    new 
iCash iPlayers32 ] , iNum id iBonusDollars iBonus]; 
    
    for ( new 
sizeofiBonus ) ; i++ )
    {
        
iBonus] = get_pcvar_numpcvar_pt_bonusDollars] );
    }
        
    
get_playersiPlayers iNum "c" );
    
    for ( new 
iNum i++ )
    {
        
id iPlayers];
        
        if ( 
CS_TEAM_T <= cs_get_user_teamid ) <= CS_TEAM_CT )
        {
            for ( new 
iHoursIndex iHoursIndex >= iHoursIndex-- )
            {
                if ( ( 
ptdDataid ][ TotalTime ] + ( get_systime() - ptdDataid ][ ConnectTime ] ) ) >= ( ( iHoursIndex ) * 3600 ) )
                {
                    
iCash cs_get_user_moneyid );
                    
                    
iBonusDollars iBonusiHoursIndex ];
            
                    
cs_set_user_moneyid clampiCash iBonusDollars 16000 ) );
                
                    
colorChatid CHATCOLOR_GREEN"You played $t%d h.$g and got a bonus of $t%d$$g"iHoursIndex 1iBonusDollars);
                    break;
                }
            }
        }
    }
}

colorChat(idChatColor:color, const msg[], {Float,Sql,Result,_}:...)
{
    new 
teamindexMSG_Type
    
new bool:teamChanged false
    
static message[192]
    
    switch(
color)
    {
        case 
CHATCOLOR_NORMAL// Normal
        
{
            
message[0] = 0x01;
        }
        case 
CHATCOLOR_GREEN// Green
        
{
            
message[0] = 0x04;
        }
        default: 
// Grey, Red, Blue
        
{
            
message[0] = 0x03;
        }
    }
    
    
vformat(message[1], 190msg4);
    
replace_all(message190"$g""^x04")
    
replace_all(message190"$n""^x01")
    
replace_all(message190"$t""^x03")
        
    if(
id == 0)
    {
        
index findAnyPlayer();
        
MSG_Type MSG_ALL;
    }
    else
    {
        
index id;
        
MSG_Type MSG_ONE;
    }
    if(
index != 0)
    {
        
team get_user_team(index);    
        if(
color == CHATCOLOR_RED && team != 1)
        {
            
messageTeamInfo(indexMSG_Typeg_TeamName[1])
            
teamChanged true
        
}
        else
        if(
color == CHATCOLOR_BLUE && team != 2)
        {
            
messageTeamInfo(indexMSG_Typeg_TeamName[2])
            
teamChanged true
        
}
        else
        if(
color == CHATCOLOR_GREY && team != 0)
        {
            
messageTeamInfo(indexMSG_Typeg_TeamName[0])
            
teamChanged true
        
}
        
        
messageSayText(indexMSG_Typemessage);
        
        if(
teamChanged)
        {
            
messageTeamInfo(indexMSG_Typeg_TeamName[team])
        }
    }
}

messageSayText(idtypemessage[])
{
    
message_begin(typeg_msgSayText_id)
    
write_byte(id)        
    
write_string(message)
    
message_end()
}
    
messageTeamInfo(idtypeteam[])
{
    
message_begin(typeg_msgTeamInfo_id)
    
write_byte(id)
    
write_string(team)
    
message_end()
}

findAnyPlayer()
{
    static 
players[32], inum;
    
    
get_players(playersinum"ch")
    
    return 
playersrandominum ) ];

__________________

Last edited by Bugsy; 04-21-2019 at 20:53.
Bugsy is offline
tarsisd2
Veteran Member
Join Date: Feb 2016
Location: brazil
Old 04-21-2019 , 22:06   Re: Played Time Money Bonus
Reply With Quote #6

i will test it and get back too you, thanks very much

edit: im using amxmodx 1.9, do i have to use nvault fixed version or the one in the new build has been fixed?

Last edited by tarsisd2; 04-21-2019 at 22:07.
tarsisd2 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-21-2019 , 22:17   Re: Played Time Money Bonus
Reply With Quote #7

No, you are good with 1.9, just download the .inc.
__________________
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:40.


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