AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Thank you supre ;3 (https://forums.alliedmods.net/showthread.php?t=327553)

Magicher0ex 09-25-2020 20:59

Thank you supre ;3
 
Hey guys, can anyone edit this to use SteamID time counting not by name
Code:

#include <amxmodx>
#include <colorchat>
#include <nvault>
#include <time>

#define MAX_PLAYERS 32

new g_iVault

new g_szName[MAX_PLAYERS+1][32]
new g_iLastPlayedTime[MAX_PLAYERS+1]

public plugin_init()
{
        register_plugin("Time", "0.1", "ConnorMcLeod")
        register_dictionary("time.txt")

        g_iVault = nvault_open("played_time")

        register_clcmd("say /time", "ClientCommand_PlayedTime")
}

public plugin_end() nvault_close( g_iVault )
 

public client_authorized( id )
{
        new szTime[32]
        get_user_name(id, g_szName[id], charsmax(g_szName[]))
        nvault_get(g_iVault, g_szName[id], szTime, charsmax(szTime))
        g_iLastPlayedTime[id] = str_to_num(szTime)
}

get_user_total_playtime( id )
{
        return g_iLastPlayedTime[id] + get_user_time(id)
}

public ClientCommand_PlayedTime( id )
{
    new szTime[128]
    new szName[32]
    get_time_length(id, get_user_total_playtime( id ), timeunit_seconds, szTime, charsmax(szTime))
    get_user_name(id, szName, charsmax(szName))
    ColorChat( id, GREEN, "^x04%s^x01's Time:^x04 %s", szName, szTime)
}

public client_disconnect( id )
{
        new szTime[32]
        formatex(szTime, charsmax(szTime), "%d", get_user_total_playtime( id ))
        nvault_set(g_iVault, g_szName[id], szTime)
}


Magicher0ex 09-25-2020 21:07

Re: STEAMID played time
 
i mean szName stay but the time counting to be on steamid, not the name

Bugsy 09-25-2020 21:39

Re: STEAMID played time
 
Change
new g_szName[MAX_PLAYERS+1][32]
to
new g_szAuthID[MAX_PLAYERS+1][32]

In client_authorized, change
get_user_name(id, g_szName[id], charsmax(g_szName[]))
to
get_user_authid(id, g_szAuthID[id], charsmax(g_szAuthID[]))

In client_disconnect(), change
nvault_set(g_iVault, g_szName[id], szTime)
to
nvault_set(g_iVault, g_szAuthID[id], szTime)

Supremache 09-25-2020 22:30

Re: STEAMID played time
 
Quote:

Originally Posted by Magicher0ex (Post 2718958)
i mean szName stay but the time counting to be on steamid, not the name

Saving time to NVault = 0
Save time by Name = 2
Save time by steamid = 1
Save time by IP = 0

Code:
#include <amxmodx> #include <colorchat> #include <nvault> #include <time> #define MAX_PLAYERS 32 new g_iVault new g_SaveTime, g_SaveType; new g_szAuth[MAX_PLAYERS+1][32] new g_iLastPlayedTime[MAX_PLAYERS+1] public plugin_init() {     register_plugin("Time", "0.1", "ConnorMcLeod")     register_dictionary("time.txt")         g_SaveType = register_cvar("time_savetype","0") // Save time to : 0 = NVault.     g_SaveTime = register_cvar("time_save","1") // Save time by : 2 = Name, 1 = SteamID, 0 = IP.     g_iVault = nvault_open("played_time")     register_clcmd("say /time", "ClientCommand_PlayedTime") } public plugin_end() nvault_close( g_iVault )   public client_authorized( id ) {     LoadData(id) } get_user_total_playtime( id ) {     return g_iLastPlayedTime[id] + get_user_time(id) } public ClientCommand_PlayedTime( id ) {     new szTime[128]     new szName[32]     get_time_length(id, get_user_total_playtime( id ), timeunit_seconds, szTime, charsmax(szTime))     get_user_name(id, szName, charsmax(szName))     ColorChat( id, GREEN, "^x04%s^x01's Time:^x04 %s", szName, szTime) } public client_disconnect( id ) {     SaveData(id) } SaveData(id) {     new szKey[64];         if (get_pcvar_num(g_SaveTime) == 0)     {         get_user_ip(id, g_szAuth[id] , charsmax(g_szAuth[]), 1)         formatex(szKey , charsmax(szKey) , "%s-IP" , g_szAuth[id])     }     else if (get_pcvar_num(g_SaveTime) == 1)     {         get_user_authid(id , g_szAuth[id] , charsmax(g_szAuth[]))         formatex(szKey , charsmax(szKey) , "%s-ID" , g_szAuth[id])     }     else if (get_pcvar_num(g_SaveTime) == 2)     {         get_user_name(id, g_szAuth[id] , charsmax(g_szAuth[]))         formatex(szKey , charsmax(szKey) , "%s-NAME" , g_szAuth[id])     }         if (!get_pcvar_num(g_SaveType))     {         new szData[256]                 formatex(szData , charsmax(szData) , "%i#" , get_user_total_playtime( id ))                 nvault_pset(g_iVault , szKey , szData)     } } LoadData(id) {     new szKey[64];         if (get_pcvar_num(g_SaveTime) == 0)     {         get_user_ip(id, g_szAuth[id] , charsmax(g_szAuth[]), 1)         formatex(szKey , charsmax(szKey) , "%s-IP" , g_szAuth[id])     }     else if (get_pcvar_num(g_SaveTime) == 1)     {         get_user_authid(id , g_szAuth[id] , charsmax(g_szAuth[]))         formatex(szKey , charsmax(szKey) , "%s-ID" , g_szAuth[id])     }     else if (get_pcvar_num(g_SaveTime) == 2)     {         get_user_name(id, g_szAuth[id] , charsmax(g_szAuth[]))         formatex(szKey , charsmax(szKey) , "%s-NAME" , g_szAuth[id])     }         if (!get_pcvar_num(g_SaveType))     {         new szData[256], szTime[32];                 formatex(szData , charsmax(szData), "%i#", g_iLastPlayedTime[id])         nvault_get(g_iVault, szKey, szData, charsmax(szData))         replace_all(szData , charsmax(szData), "#", " ")         parse(szData, szTime, charsmax(szTime))         g_iLastPlayedTime[id] = str_to_num(szTime)     } }

Bugsy 09-26-2020 00:42

Re: STEAMID played time
 
@Supremache:

1. You should set the appropriate value in g_szAuth[id] at client_authorized() instead of doing it twice--once at load and once at save. The goal is to call as few natives as possible in a plugin for efficiency.
2. There is no need to use anything but steam id as a unique identifier for a player.

Supremache 09-26-2020 01:10

Re: STEAMID played time
 
1. I was want to use one value for everything "Name, steamid, ip" but well i did it
Spoiler


2. I want to give him every opptions togther in plugin "'Name, steamid, Ip", I do that because there's other people at sometime searching for this thing and making a new topic but as we saying in egypt i dont know how to say that but it's like, This is the end of the topic

Bugsy 09-26-2020 11:07

Re: Thank you supre ;3
 
I don't agree with your argument. There's no reason why anyone should use anything but the steam id to store player-specific data. Only people who do not have steam would want this, which AMX-X does not support.

Supremache 09-26-2020 12:46

Re: Thank you supre ;3
 
I gave him more options and he have the choice :D

Code:
g_SaveTime = register_cvar("time_save","1") // Save time by : 2 = Name, 1 = SteamID, 0 = IP.

Bugsy 09-26-2020 13:01

Re: Thank you supre ;3
 
I understand that. My point is there is no point in using name or IP... steam ID should be the ONLY unique player identifier that is used.

Supremache 09-26-2020 13:05

Re: Thank you supre ;3
 
Quote:

Originally Posted by Bugsy (Post 2719077)
I understand that. My point is there is no point in using name or IP... steam ID should be the ONLY unique player identifier that is used.

You are right, As i said i was want to give him more options :up:


All times are GMT -4. The time now is 23:45.

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