AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Remove hours (https://forums.alliedmods.net/showthread.php?t=321259)

wicho 02-01-2020 23:48

Remove hours
 
Hello everyone, I found this code that saves the time played by a player, it works fine but I would like to take hours from a specific player (by punishment) for a command, my question is how can I do that? Could you give me an example please? ... Thanks in advance

Code:

PHP Code:

#include <amxmodx>
#include <nvault>

#define PLUGIN "Time Play"
#define VERSION "1.0"
#define AUTHOR "[R]ak"

enum _:UserData {
    
DATA_TOTAL,
    
DATA_YEARS,
    
DATA_MONTHS,
    
DATA_DAYS,
    
DATA_HOURS,
    
DATA_MIN,
    
DATA_SEC
}

new 
g_Vault

new g_UserData[33][UserData]

new 
g_VaultKey[33][35]

public 
plugin_init() {
    
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /time""cmdTime")
    
    
register_clcmd("say /tiempo""cmdTime")
}

public 
plugin_cfg() {
    
    
g_Vault nvault_open("VaultTime")
    
    if(
g_Vault == INVALID_HANDLE)
        
set_fail_state("[R]ak Acme Inc.- Error al abrir el vault")
    
}

public 
client_putinserver(id) {
    
    
get_user_authid(idg_VaultKey[id], charsmax(g_VaultKey[]))
        
    
load_time(id)
    
}

public 
client_disconnect(id)
    
save_time(id)

public 
cmdTime(id) {
    
    
get_time_played((g_UserData[id][DATA_TOTAL] + get_user_time(id)), g_UserData[id][DATA_YEARS], g_UserData[id][DATA_MONTHS], g_UserData[id][DATA_DAYS], 
    
g_UserData[id][DATA_HOURS], g_UserData[id][DATA_MIN], g_UserData[id][DATA_SEC])
    
    
client_print(idprint_chat"Tiempo jugado: %02d/%02d/%02d %02d:%02d:%02d"g_UserData[id][DATA_YEARS], g_UserData[id][DATA_MONTHS], 
    
g_UserData[id][DATA_DAYS], g_UserData[id][DATA_HOURS], g_UserData[id][DATA_MIN], g_UserData[id][DATA_SEC])
    
    return 
PLUGIN_HANDLED    
}

load_time(id)    
    
g_UserData[id][DATA_TOTAL] = nvault_get(g_Vault g_VaultKey[id])

save_time(id) {
    
    new 
Data[30]
    
    
formatex(Datacharsmax(Data), "%d"g_UserData[id][DATA_TOTAL] + get_user_time(id))
    
    
nvault_set(g_Vaultg_VaultKey[id], Data)
    
}

stock get_time_played(iTime, &iYear, &iMonth, &iDay, &iHour, &iMinute, &iSecond) { 
    
    
iTime -= 31536000 * (iYear iTime 31536000
    
iTime -= 2678400 * (iMonth iTime 2678400
    
iTime -= 86400 * (iDay iTime 86400
    
iTime -= 3600 * (iHour iTime 3600
    
iTime -= 60 * (iMinute iTime 60
    
iSecond iTime 
    
    
return 1
}    

public 
plugin_end()
    
nvault_close(g_Vault


Bugsy 02-02-2020 14:50

Re: Remove hours
 
This will take players saved time + current time and subtract X hours. Time will be capped at 0 and not go negative. Not thoroughly tested

PHP Code:

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

#define PLUGIN "Time Play"
#define VERSION "1.0"
#define AUTHOR "[R]ak"

enum _:UserData {
    
DATA_TOTAL,
    
DATA_YEARS,
    
DATA_MONTHS,
    
DATA_DAYS,
    
DATA_HOURS,
    
DATA_MIN,
    
DATA_SEC
}

new 
g_Vault

new g_UserData[33][UserData]
new 
g_TimeRemoved33 ]
new 
g_VaultKey[33][35]

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /time""cmdTime")
    
register_clcmd("say /tiempo""cmdTime")
    
    
register_concmd("removehours" "remove_hours" );
}

public 
plugin_cfg() 
{
    
g_Vault nvault_open("VaultTime")
    
    if(
g_Vault == INVALID_HANDLE)
        
set_fail_state("[R]ak Acme Inc.- Error al abrir el vault")    
}

public 
client_putinserver(id
{
    
get_user_authid(idg_VaultKey[id], charsmax(g_VaultKey[]))
    
g_TimeRemovedid ] = 0;
    
    
load_time(id)
}

public 
client_disconnect(id)
{
    
save_time(id)
}

public 
cmdTime(id
{
    
get_time_played(max( ( g_UserData[id][DATA_TOTAL] + get_user_time(id) ) - g_TimeRemovedid ] , ), g_UserData[id][DATA_YEARS], g_UserData[id][DATA_MONTHS], g_UserData[id][DATA_DAYS], 
    
g_UserData[id][DATA_HOURS], g_UserData[id][DATA_MIN], g_UserData[id][DATA_SEC])
    
    
client_print(idprint_chat"Tiempo jugado: %02d/%02d/%02d %02d:%02d:%02d"g_UserData[id][DATA_YEARS], g_UserData[id][DATA_MONTHS], 
    
g_UserData[id][DATA_DAYS], g_UserData[id][DATA_HOURS], g_UserData[id][DATA_MIN], g_UserData[id][DATA_SEC])
    
    return 
PLUGIN_HANDLED    
}

load_time(id)    
{
    
g_UserData[id][DATA_TOTAL] = nvault_get(g_Vault g_VaultKey[id])
}

save_time(id
{
    new 
Data14 ]
    
    
num_to_strmax( ( g_UserData[id][DATA_TOTAL] + get_user_time(id) ) - g_TimeRemovedid ] , ) , Data charsmaxData ) );
    
nvault_set(g_Vaultg_VaultKey[id], Data)
}

public 
remove_hoursid )
{
    new 
szPlayer33 ] , szVal] , iHours;
    
    
read_argvszPlayer charsmaxszPlayer ) );
    
read_argvszVal charsmaxszVal ) );
    
    if ( !
szPlayer] || !szVal] )
    {
        
console_printid "* Must specify player name and number of hours: removehours [name] [# hours]" );
        return 
PLUGIN_HANDLED;
    }
    
    new 
iTarget cmd_targetid szPlayer );
        
    if ( 
iTarget )
    {
        
iHours str_to_numszVal );
        
get_user_nameiTarget szPlayer charsmaxszPlayer ) );
        
g_TimeRemovediTarget ] += ( iHours 3600 );
        
console_printid "* Removed %d hours from %s. Total removed %d hours." iHours szPlayer g_TimeRemovediTarget ] );
    }
    else
    {
        
console_printid "* Player with that name not found or has immunity." );
    }
    
    return 
PLUGIN_HANDLED;
}

stock get_time_played(iTime, &iYear, &iMonth, &iDay, &iHour, &iMinute, &iSecond

    
iTime -= 31536000 * (iYear iTime 31536000
    
iTime -= 2678400 * (iMonth iTime 2678400
    
iTime -= 86400 * (iDay iTime 86400
    
iTime -= 3600 * (iHour iTime 3600
    
iTime -= 60 * (iMinute iTime 60
    
iSecond iTime 
    
    
return 1
}    

public 
plugin_end()
{
    
nvault_close(g_Vault)



wicho 02-04-2020 18:29

Re: Remove hours
 
I tested your code works but have a problem, the first time I wrote the command work fine take the time off of the player but when I write it again the command the time does not go down, just take it off the first time.

Bugsy 02-04-2020 20:39

Re: Remove hours
 
Changed above code to allow multiple time removals.

Also updated this console line:

* Removed 3 hours from bugsy. Total removed 3 hours.
* Removed 2 hours from bugsy. Total removed 5 hours.

wicho 02-08-2020 15:44

Re: Remove hours
 
Thanks it works, another question I try to adapt that code to a barter menu for zombie plague, I mean, you can change hours for ammo packs, the problem is that when I choose an option (any) does not reduce the time, Could you tell me what is the problem please? .. thanks for your help

PHP Code:

#include <amxmisc>
#include <nvault>
#include <zp50_ammopacks>

#define PLUGIN "Barter System"
#define VERSION "1.0"
#define AUTHOR "kha"

enum 

         DEFAULT, 
         
RED
         
BLUE
         
GRAY
         
GREEN 


enum _:tDataBarter
{
         
tInfo[64],
         
tTime,
         
tReduce,
         
tPts,
         
tItem
}

enum _:UserData 
{
         
DATA_TOTAL,
         
DATA_YEARS,
         
DATA_MONTHS,
         
DATA_DAYS,
         
DATA_HOURS,
         
DATA_MIN,
         
DATA_SEC
}

new const 
tBarter[][tDataBarter] = 
{
         
/* Descripcion                      Hours         Reduce      Ammo Packs     #Item*/
         
"1 Hour = 15 Ammo Packs",            1,            3600,        15,            },
         { 
"2 Hours = 30 Ammo Packs",           2,            3600,        30,            },
         { 
"3 Hours = 45 Ammo Packs",           3,            3600,        45,            },
         { 
"4 Hours = 60 Ammo Packs",           4,            3600,        60,            },
         { 
"5 Hours = 75 Ammo Packs",           5,            3600,        75,            },
         { 
"6 Hours = 90 Ammo Packs",           6,            3600,        90,            },
         { 
"7 Hours = 105 Ammo Packs",          7,            3600,        105,           },
         { 
"8 Hours = 120 Ammo Packs",          8,            3600,        120,           },
         { 
"9 Hours = 135 Ammo Packs",          9,            3600,        135,           },
         { 
"10 Hours = 150 Ammo Packs",         10,           10 3600,       150,           10 }
}

new 
tPoints[33]

new 
g_Vault

new g_UserData[33][UserData]

new 
g_VaultKey[33][35]

public 
plugin_init() 
{
         
register_plugin(PLUGINVERSIONAUTHOR)
    
         
register_clcmd("say /barter""clcmd_barter")
}

public 
plugin_cfg() 
{   
         
g_Vault nvault_open("VaultTime")
    
         if(
g_Vault == INVALID_HANDLE)
                  
set_fail_state("Error opening vault")   
}

public 
client_putinserver(id)
{
    
get_user_authid(idg_VaultKey[id], charsmax(g_VaultKey[]))
        
         
tLoad(id)
}

public 
client_disconnect(id)
{
         
tSave(id)
}

public 
tLoad(id)
{     
    
g_UserData[id][DATA_TOTAL] = nvault_get(g_Vault g_VaultKey[id])
}

public 
tSave(id)
{
         new 
Data[30]
     
    
num_to_str(max((g_UserData[id][DATA_TOTAL] + get_user_time(id)) - tBarter[id][tReduce], 0), Datacharsmax(Data))
         
nvault_set(g_Vaultg_VaultKey[id], Data)
}

public 
clcmd_barter(id)
{         
    
get_time_played(max((g_UserData[id][DATA_TOTAL] + get_user_time(id)) - tBarter[id][tReduce], 0), g_UserData[id][DATA_YEARS], g_UserData[id][DATA_MONTHS], g_UserData[id][DATA_DAYS], 
         
g_UserData[id][DATA_HOURS], g_UserData[id][DATA_MIN], g_UserData[id][DATA_SEC])
     
         new 
tText[64], menu
         formatex
(tTextcharsmax(tText), "\rZP | Barter Menu^n\rTime played: \d%02d/%02d/%02d %02d:%02d:%02d"g_UserData[id][DATA_YEARS], g_UserData[id][DATA_MONTHS], g_UserData[id][DATA_DAYS], g_UserData[id][DATA_HOURS], g_UserData[id][DATA_MIN], g_UserData[id][DATA_SEC])
         
menu menu_create(tText"opc_menu")
    
         static 
i
         
for(0sizeof tBarteri++)
         {
                  if(
g_UserData[id][DATA_HOURS] >= tBarter[i][tTime])
                           
formatex(tTextcharsmax(tText), "\w%s"tBarter[i][tInfo])
                  else
                           
formatex(tTextcharsmax(tText), "\d%s"tBarter[i][tInfo])
        
                  
menu_additem(menutTexttBarter[i][tItem])
         }
     
         
menu_setprop(menuMPROP_NEXTNAME"\wNext")
         
menu_setprop(menuMPROP_BACKNAME"\wBack")
         
menu_setprop(menuMPROP_EXITNAME"\wExit")
    
         
menu_display(idmenu0)
         return 
PLUGIN_HANDLED
}

public 
opc_menu(idmenuitem)
{
         if(
item == MENU_EXIT
         {
                  
menu_destroy(menu)
                  return 
PLUGIN_HANDLED
         
}
    
         if(
g_UserData[id][DATA_HOURS] >= tBarter[item][tTime])
         {
        
g_UserData[id][DATA_HOURS] -= tBarter[item][tReduce]
        
tPoints[id] += zp_ammopacks_set(idzp_ammopacks_get(id) + tBarter[item][tPts])
        
printf(id, DEFAULT, "^x04 ZP | ^x01You have bartered ^x04 %d Hours^x01 for ^x04 %d Ammo Packs"tBarter[item][tTime], tBarter[item][tPts])
         }
         else
             
printf(id, DEFAULT, "^x04 ZP | ^x01You don't have enough hours for this barter!")
    
         
menu_destroy(menu)
         return 
PLUGIN_HANDLED


stock get_time_played(iTime, &iYear, &iMonth, &iDay, &iHour, &iMinute, &iSecond
{    
         
iTime -= 31536000 * (iYear iTime 31536000
         
iTime -= 2678400 * (iMonth iTime 2678400
         
iTime -= 86400 * (iDay iTime 86400
         
iTime -= 3600 * (iHour iTime 3600
         
iTime -= 60 * (iMinute iTime 60
         
iSecond iTime 
    
         
return 1
}     

public 
plugin_end()
{
         
nvault_close(g_Vault
}

stock printf(idcolor, const msg[], any:...) {
    
    static 
Buffer[192], MsgSayTextMsgTeamInfoTeam[32]
    
    if(!
MsgSayText) {
        
        
MsgTeamInfo get_user_msgid("TeamInfo")       
        
MsgSayText get_user_msgid("SayText")
        
    }
    
    
vformat(Buffer[1], charsmax(Buffer) - 1msg4)
    
    static const 
Teams[2][10] = {
        
"TERRORIST",
        
"CT"
    
}
    
    switch (
color) {
        
        case DEFAULT: {
            
            
Buffer[0] = 0x01
            
            printf_do
(idid id 33BufferMsgSayText)
        }
        
        case 
GREEN: {
            
            
Buffer[0] = 0x04
            
            printf_do
(idid id 33BufferMsgSayText)           
        }
        
        case 
GRAY: {
            
            
Buffer[0] = 0x03            
            printf_do
(id33BufferMsgSayText)           
        }
        
        case 
REDBLUE: {
            
            
Buffer[0] = 0x03
            
            
if (id) {
                
                if (
get_user_team(idTeamcharsmax(Team)) == color) {
                    
                    
printf_do(ididBufferMsgSayText)                    
                }
                else {
                    
                    
printf_do(ididTeams[color-1], MsgTeamInfo)                   
                    
printf_do(ididBufferMsgSayText)
                    
printf_do(ididTeamMsgTeamInfo)                   
                }            
            }
            
            else {
                
                static 
Num;
                
                
get_players(TeamNum"e"Teams[color-1]);
                
                if (
Num) {
                    
                    
printf_do(idTeam[0], BufferMsgSayText)                    
                }
                else {
                    
                    
get_players(TeamNum"h");
                    
                    if (!
Num) {
                        
                        return;                        
                    }
                    
                    
Num Team[0];
                    
                    
get_user_team(NumTeamcharsmax(Team));                   
                    
printf_do(NumNumTeams[color-1], MsgTeamInfo)        
                    
printf_do(idNumBufferMsgSayText)        
                    
printf_do(NumNumTeamMsgTeamInfo)                    
                }                
            }            
        }       
    }
}

printf_do(idsender, const data[], MsgID
{    
     
message_begin(id MSG_ONE_UNRELIABLE MSG_BROADCASTMsgID_id)         
     
write_byte(sender)        
     
write_string(data)          
     
message_end()    



Bugsy 02-08-2020 16:19

Re: Remove hours
 
You need to add a variable, or DATA_REMOVED in your enum, to store the players total reduction time, as I have in my code. Be sure to set this to 0 when needed as I have in my code

Then replace

g_UserData[id][DATA_HOURS] -= tBarter[item][tReduce]

with

iTimeRemoved[ id ] += tBarter[item][tReduce];

Then
PHP Code:

public tSave(id)
{
         new 
Data[30]
     
         
num_to_str(max((g_UserData[id][DATA_TOTAL] + get_user_time(id)) - iTimeRemovedid ], 0), Datacharsmax(Data))
         
nvault_set(g_Vaultg_VaultKey[id], Data)



wicho 02-09-2020 21:24

Re: Remove hours
 
Thanks, last question how can I do to dont count the player's time when they are in spectator (since many players do that to win time)? only when the player is in spectator, but if the player chooses a team his time remains normal.

Bugsy 02-09-2020 21:34

Re: Remove hours
 
https://forums.alliedmods.net/showthread.php?t=320027

wicho 02-10-2020 00:23

Re: Remove hours
 
Is this part right?

PHP Code:

public EntityThinkiEntity )
{
    static 
iPlayers32 ] , iNumPlayers iPlayerID i;
    
    if ( 
iEntity == g_Entity 
    {
        
get_playersiPlayers iNumPlayers "ch" );
        
        for ( 
iNumPlayers i++ )
        {
            
iPlayerID iPlayers];
            
            if ( 
CS_TEAM_T <= cs_get_user_teamiPlayerID ) <= CS_TEAM_CT )
                
g_PlayTimeiPlayerID ]++;
        }
        
        
entity_set_floatg_Entity EV_FL_nextthink , ( get_gametime() + 1.0 ) );
    }



wicho 11-29-2020 00:13

Re: Remove hours
 
Sorry for reviving but I added that part to not save the hours to the players who are in spectator but it does not work


All times are GMT -4. The time now is 21:52.

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