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

Save String Array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
XSlayer
Member
Join Date: Dec 2021
Old 12-11-2021 , 19:09   Save String Array
Reply With Quote #1

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?
XSlayer is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 12-11-2021 , 19:13   Re: Save String Array
Reply With Quote #2

Use steam id
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.
Supremache is offline
XSlayer
Member
Join Date: Dec 2021
Old 12-11-2021 , 19:18   Re: Save String Array
Reply With Quote #3

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

Last edited by XSlayer; 12-11-2021 at 19:18.
XSlayer is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 12-11-2021 , 19:42   Re: Save String Array
Reply With Quote #4

Quote:
Originally Posted by XSlayer View Post
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;
    }

__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 12-11-2021 at 20:11.
Supremache is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-11-2021 , 20:07   Re: Save String Array
Reply With Quote #5

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" );
    }

__________________

Last edited by Bugsy; 12-11-2021 at 20:10.
Bugsy is offline
XSlayer
Member
Join Date: Dec 2021
Old 12-12-2021 , 00:05   Re: Save String Array
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
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

Last edited by XSlayer; 12-12-2021 at 00:06.
XSlayer is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 12-12-2021 , 01:46   Re: Save String Array
Reply With Quote #7

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" );
       }

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 12-12-2021 at 01:49.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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 10:38.


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