AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Save String Array (https://forums.alliedmods.net/showthread.php?t=335533)

XSlayer 12-11-2021 19:09

Save String Array
 
Hi i was wondering how can i save a string for a specific player, i want to save the string when spawn and later load it in a condition ex:

Code:

////////////////////

new __int_String[32];

public fw_spawn( Client )
{
      get_user_name( Client, __int_String, charsmax(__int_String));

      set_task( 5.0, "LoadString", Client, _, _, "a", 1 );
}
public LoadString( Client )
{
      if(equal(__int_String, "XSlayer" ))
      {
              client_print( Client, print_chat, "XSlayer entered the game" );
      }
}


////////////////////

for a simple view the code is ok, but if other player enter the game after the 5 seconds, the string change, how can i save the string for personal client and then load it in a condition?

Supremache 12-11-2021 19:13

Re: Save String Array
 
Use steam id

XSlayer 12-11-2021 19:18

Re: Save String Array
 
is use the name for only a string example, but the string that i want to save is a class i cannot use the steam id

Supremache 12-11-2021 19:42

Re: Save String Array
 
Quote:

Originally Posted by XSlayer (Post 2765738)
is use the name for only a string example, but the string that i want to save is a class i cannot use the steam id

Edit: i don't understand what you are talking about but what i understand is you want to check if the player has the same nickname that has owned when joined the server.
PHP Code:

new g_iPlayerName33 ][ 32 ]
public 
client_authorizedid )
{
    
get_user_nameid g_iPlayerNameid ] , charsmaxg_iPlayerName[ ] ) );
}

public 
LoadStringClient )
{
    new 
szName32 ]
    
get_user_nameClientszNamecharsmax(szName));
    if(
equal(g_iPlayerNameClient ], szName ))
    {
        
client_printClientprint_chat"%s entered the game"g_iPlayerNameClient ] );
    }


PHP Code:

public LoadStringClient )
{
    new 
szName32 ]
    
get_user_nameClientszNamecharsmax(szName));
    
    if( !
bNameChanged )
    {
        
client_printClientprint_chat"%s entered the game"szName );
    }
}


public 
client_infochanged(id)
{
    static 
szNewName[32], szOldName[32]
    
get_user_info(id"name"szNewNamecharsmax(szNewName))
    
get_user_name(idszOldNamecharsmax(szOldName))
    
    if(!
equal(szNewNameszOldName))
    {
        
bNameChanged true;
    }
    else
    {
        
bNameChanged false;
    }



Bugsy 12-11-2021 20:07

Re: Save String Array
 
I think you're pretty close.
  • The missing part is you need a 2-dimension array so that each players name can be stored. Your current code would make each player overwrite the next.
  • You do not need to use flag 'a' with 1 in set_task() to execute the task once, that is only if you need it triggered/repeated more than once.
  • You want to call remove_task() on client_disconnect, just incase they disconnect between spawn and the 5 second task.

I would recommend you explain what you are trying to accomplish instead of asking questions in code.

PHP Code:

#define MAX_PLAYERS 32
#define MAX_NAME_LENGTH 32

new g_szNameMAX_PLAYERS ][ MAX_NAME_LENGTH ];

public 
fw_spawnClient )
{
    
get_user_nameClient g_szNameClient ] , charsmaxg_szName[] ) );
    
    
set_task5.0 "LoadString" Client );
}

public 
client_disconnectClient 
{
    
remove_taskClient );
}

public 
LoadStringClient )
{
    if ( 
equalg_szNameClient ] , "XSlayer" ))
    {
        
client_printClient print_chat"XSlayer entered the game" );
    }



XSlayer 12-12-2021 00:05

Re: Save String Array
 
Quote:

Originally Posted by Bugsy (Post 2765740)
I think you're pretty close.
  • The missing part is you need a 2-dimension array so that each players name can be stored. Your current code would make each player overwrite the next.
  • You do not need to use flag 'a' with 1 in set_task() to execute the task once, that is only if you need it triggered/repeated more than once.
  • You want to call remove_task() on client_disconnect, just incase they disconnect between spawn and the 5 second task.

I would recommend you explain what you are trying to accomplish instead of asking questions in code.

PHP Code:

#define MAX_PLAYERS 32
#define MAX_NAME_LENGTH 32

new g_szNameMAX_PLAYERS ][ MAX_NAME_LENGTH ];

public 
fw_spawnClient )
{
    
get_user_nameClient g_szNameClient ] , charsmaxg_szName[] ) );
    
    
set_task5.0 "LoadString" Client );
}

public 
client_disconnectClient 
{
    
remove_taskClient );
}

public 
LoadStringClient )
{
    if ( 
equalg_szNameClient ] , "XSlayer" ))
    {
        
client_printClient print_chat"XSlayer entered the game" );
    }



Thanks! and thanks for explaining the reasons why it didn't work, that helps me learn more and supremache too

Natsheh 12-12-2021 01:46

Re: Save String Array
 
Why just not save the string in the set_task parameters?

PHP Code:

set_task5.0"LoadString"Client__int_Stringsizeof  __int_String);

public 
LoadString( const szString[], Client )
{
       if(
equal(szString"XSlayer" ))
       {
              
client_printClientprint_chat"XSlayer entered the game" );
       }




All times are GMT -4. The time now is 11:58.

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