Raised This Month: $32 Target: $400
 8% 

Translation in a timer action possible?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JLmelenchon
Senior Member
Join Date: Mar 2019
Old 08-18-2022 , 18:18   Translation in a timer action possible?
Reply With Quote #1

It will give me client index error, i suppose because there is not client handle ?

Code:
public Action Timer_TEST(Handle timer)
{
	CPrintToChatAll("%t", "translation_message" sName);
			
}

Last edited by JLmelenchon; 08-18-2022 at 18:19.
JLmelenchon is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-18-2022 , 18:31   Re: Translation in a timer action possible?
Reply With Quote #2

*edit
https://wiki.alliedmods.net/Translat...ge_in_a_Plugin



PHP Code:
    ...




    
int userid GetClientUserId(client);
    
    
CreateTimer(10.0delayuserid);
}

public 
Action delay(Handle timerany userid)
{

    
int client GetClientOfUserId(userid);

    if(
client == || !IsClientInGame(client))
        return 
Plugin_Continue;


    
//CPrintToChatAll("%t", client, "translation_message", "Random Name ?"); // I guess you not need add client in translation %t when use PrintToChat*
    
CPrintToChatAll("%t""translation_message""Random Name ?");

    return 
Plugin_Continue;

You could also show your translation file.
__________________
Do not Private Message @me

Last edited by Bacardi; 08-19-2022 at 07:19. Reason: fix
Bacardi is offline
JLmelenchon
Senior Member
Join Date: Mar 2019
Old 08-18-2022 , 21:49   Re: Translation in a timer action possible?
Reply With Quote #3

I can not do that because my timer is created OnPluginStart
"int userid = GetClientUserId(client);"

Last edited by JLmelenchon; 08-18-2022 at 21:49.
JLmelenchon is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 08-18-2022 , 21:59   Re: Translation in a timer action possible?
Reply With Quote #4

you need to do a loop through all connected and nonfake clients then.
__________________
Marttt is offline
Cruze
Veteran Member
Join Date: May 2017
Old 08-19-2022 , 05:04   Re: Translation in a timer action possible?
Reply With Quote #5

Plugin:
PHP Code:
public Action Timer_TEST(Handle timer)
{
    for(
int client 1client <= MaxClientsclient++)
    {
        if(
IsClientInGame(client) && !IsFakeClient(client))
        {
            
CPrintToChat(client"%T""translation_message"clientclient);
        }
    }    

Translation file:
PHP Code:
"Phrases"
{
    
"translation_message"
    
{
        
"#format"        "{1:N}"
        "en"            "This is translated message for {1}."
    
}

__________________
Taking paid private requests! Contact me

Last edited by Cruze; 08-19-2022 at 05:05.
Cruze is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 08-19-2022 , 10:58   Re: Translation in a timer action possible?
Reply With Quote #6

Cruze, it works too
PHP Code:
public Action Timer_TEST(Handle timer)
{
    for(
int client 1client <= MaxClientsclient++)
    {
        if(
IsClientInGame(client) && !IsFakeClient(client))
        {
            
CPrintToChat(client"%t""translation_message"client);
        }
    }    

__________________

Last edited by Grey83; 08-19-2022 at 10:58.
Grey83 is offline
JLmelenchon
Senior Member
Join Date: Mar 2019
Old 08-19-2022 , 14:58   Re: Translation in a timer action possible?
Reply With Quote #7

Yes thank you i figured it out like that:
Code:
#define IS_VALID_CLIENT(%1)     (%1 > 0 && %1 <= MaxClients)
#define IS_VALID_INGAME(%1)     (IS_VALID_CLIENT(%1) && IsClientInGame(%1))

public Action: Timer_DoingStuff ( Handle:timer )
{
    AnotherThing();
}

stock AnotherThing ( client = -1 )
{
    CPrintToChatAll("%t", "translation_done", client);
}

The whole difficulty now is that i have to get the name of a particular client that was in an array and trigger on player disconnect ...

Last edited by JLmelenchon; 08-19-2022 at 15:02.
JLmelenchon is offline
azalty
AlliedModders Donor
Join Date: Feb 2020
Location: France
Old 09-03-2022 , 17:06   Re: Translation in a timer action possible?
Reply With Quote #8

Quote:
Originally Posted by JLmelenchon View Post
The whole difficulty now is that i have to get the name of a particular client that was in an array and trigger on player disconnect ...
If you want to show a message with the name of a client. Won't work if the client has disconnected during the timer interval.
PHP Code:
void SomeFunction(int client)
{
    
CreateTimer(1.0Timer_TESTGetClientUserId(client));
}


Action Timer_TEST(Handle timerany data)
{
    
int client GetClientOfUserId(data);
    if (!
client// check if client disconnected during that 1s delay
    
{
        return 
Plugin_Stop;
    }
    
CPrintToChatAll("%t""translation_message"client); // CPrintToChatAll loops CPrintToChat, it is a bit special as it allows %t instead of %T

    
return Plugin_Stop;

example translation file (@Cruze 's example)
PHP Code:
"Phrases"
{
    
"translation_message"
    
{
        
"#format"        "{1:N}" // 1=client index
        
"en"            "This is translated message for {1}."
    
}



Still want the message to show even if the player disconnected? A bit more annoying, you'll have to use a DataPack.
Here's the code for it:

-- If you want to show a message with the name of a client. WILL work if the client has disconnected during the timer interval. --
-- You can also call SomeFunction() on OnClientDisconnect(), because OnClientDisconnect() is a pre-hook, so the client is still counted as in the game when it's called. --
PHP Code:
void SomeFunction(int client)
{
    
// Get client name
    
char sName[MAX_NAME_LENGTH 1];
    
GetClientName(clientsNamesizeof(sName));

    
// Store the client name in a datapack
    
DataPack hData = new DataPack();
    
hData.WriteCell(GetClientOfUserId(client)); // Pass the client userid in the datapack, optional, but could be useful
    
hData.WriteString(buffer); // Pass the client name in the datapack
    
CreateTimer(1.0Timer_TESThData);
}


Action Timer_TEST(Handle timerany data)
{
    
// ALWAYS DO 'delete data;' BEFORE EXITING THE TIMER!

    
data.Reset(); // Resets the cursor/position in the datapack
    
int client GetClientOfUserId(data.ReadCell());
    if (!
client// check if client disconnected during that 1s delay
    
{
        
delete data// Prevents a memory leak
        
return Plugin_Stop;
    }

    
char sName[MAX_NAME_LENGTH 1];
    
data.ReadString(sNamesizeof(sName));
    
delete data// Prevents a memory leak
    
CPrintToChatAll("%t""translation_message"sName); // CPrintToChatAll loops CPrintToChat, it is a bit special as it allows %t instead of %T

    
return Plugin_Stop;

example translation file
PHP Code:
"Phrases"
{
    
"translation_message"
    
{
        
"#format"        "{1:s}" // 1=client name
        
"en"            "This is translated message for {1}."
    
}

You could also use CreateDataTimer() but I never use it personally.
__________________
GitHub | Discord: @azalty | Steam

Last edited by azalty; 09-03-2022 at 17:13.
azalty is offline
Reply


Thread Tools
Display Modes

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 23:17.


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