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

Solved string format question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lexzor
Veteran Member
Join Date: Nov 2020
Old 10-03-2021 , 14:50   string format question
Reply With Quote #1

heyo

i m trying to pass a player name in a string like this

PHP Code:
formatex(szPassDatacharsmax(szPassData), "%s#%s#%i#%i"szMemberNameszMemberAuthidiIsMemberClanLeaderiIsMemberClanSecondLeader); 
and get it like this
PHP Code:
replace_all(szDatacharsmax(szData), "#"" ");
    
parse(szDataszMemberNamecharsmax(szMemberName), szMemberAuthidcharsmax(szMemberAuthid), szTemp[0], charsmax(szTemp[]), szTemp[1], charsmax(szTemp[]));
    
iIsMemberClanLeader str_to_num(szTemp[0]);
    
iIsMemberClanSecondLeader str_to_num(szTemp[1]); 
but if the player have space in his name (like "first second") the name will be just the "first"

how can i get full string?

Last edited by lexzor; 10-04-2021 at 15:11.
lexzor is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 10-03-2021 , 15:18   Re: string format question
Reply With Quote #2

Check if your szData string contains any whitespaces before doing anything with it. If it does, you can start figuring out how to get this:

Code:
Note
Example: to split text: "^"This is^" the best year",
call function like this: parse(text,arg1,len1,arg2,len2,arg3,len3,arg4,len4)
and you will get: "This is", "the", "best", "year"
Function returns number of parsed parameters.
Transform your First Second string to ^"First Second^", then parse it. You might aswell just apply this technique to every single name in the string to keep shit simple.
__________________

Last edited by Napoleon_be; 10-03-2021 at 15:19.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
lexzor
Veteran Member
Join Date: Nov 2020
Old 10-03-2021 , 18:18   Re: string format question
Reply With Quote #3

Thanks
lexzor is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-03-2021 , 19:57   Re: string format question
Reply With Quote #4

EDIT: I just realized that I read Napoleon_be's post wrong. His solution is probably the simplest. Just put quotes around the name and use spaces as the delimiter so that you can successfully use parse() without any additional modification.
__________________

Last edited by fysiks; 10-03-2021 at 22:34.
fysiks is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 10-03-2021 , 21:56   Re: string format question
Reply With Quote #5

i m trying to pass a string in functions
PHP Code:
public invite_to_clan_menu_handler(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }

    new 
szClanName[64], szClanTag[64];
    
copy(szClanNamecharsmax(szClanName), g_UserData[id][ClanName]);
    
copy(szClanTagcharsmax(szClanTag), g_UserData[id][ClanTag]);

    
item += 1;

    if(!
is_user_connected(item))
    {
        
client_print_color(idprint_team_default"%s %L"g_szTagid"INVITED_PLAYER_OFFLINE");
        return 
PLUGIN_HANDLED;
    }

    if(!
equal(g_UserData[item][ClanName], "NONE"))
    {
        
client_print_color(idprint_team_default"%s %L"g_szTagid"INVITED_ALREADY_MEMBER"g_UserData[item][szName], g_UserData[item][ClanName]);
        return 
PLUGIN_HANDLED;
    }

    
open_invite_menu(itemszClanNameszClanTagid);

    
client_print_color(idprint_team_default"%s %L"g_szTagid"INVITATION_SENT"g_UserData[item][szName]);

    return 
PLUGIN_CONTINUE;
}

public 
open_invite_menu(id, const clanname[], const clantag[], inviterid)
{
    new 
szData[64];
    
formatex(szDatacharsmax(szData), "%s#%s#%i"clannameclantaginviterid);

    new 
szTitle[64], szItem[2][64];
    
formatex(szTitlecharsmax(szTitle), "%L"id"PLAYER_INVITED_MENU_TITLE"clanname);
    new 
iMenu menu_create(szTitle"open_invite_menu_handler");

    
formatex(szItem[0], charsmax(szItem[]), "%L"id"FIRST_OPTION");
    
menu_additem(iMenuszItem[0], szData);

    
formatex(szItem[1], charsmax(szItem[]), "%L"id"SECOND_OPTION");
    
menu_additem(iMenuszItem[1], szData);

    
menu_setprop(iMenuMPROP_EXITMEXIT_ALL);
    
menu_display(idiMenu0);
}

public 
open_invite_menu_handler(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(id);
        return 
PLUGIN_HANDLED;
    }

    new 
iInviteriAccessszData[32], szClanName[32], szClanTag[32], szInviter[32];
    
menu_item_getinfo(menuitemiAccessszDatacharsmax(szData));
    
replace_all(szDatacharsmax(szData), "#"" ");
    
parse(szDataszClanNamecharsmax(szClanName), szClanTagcharsmax(szClanTag), szInvitercharsmax(szInviter));
    
iInviter str_to_num(szInviter);

    switch(
item)
    {
        case 
0:
        {
            
client_print_color(iInviterprint_team_default"%s %L"g_szTagiInviter"INVITE_DECLINED"g_UserData[id][szName]);
            
client_print_color(idprint_team_default"%s %L"g_szTagid"PLAYER_DECLINED_INVITATION"g_UserData[iInviter][ClanName], g_UserData[iInviter][szName]);
        }

        case 
1:
        {
            
copy(g_UserData[id][ClanName], charsmax(g_UserData[][ClanName]), g_UserData[iInviter][ClanName]);
            
copy(g_UserData[id][ClanTag], charsmax(g_UserData[][ClanTag]), g_UserData[iInviter][ClanTag]);

            
g_UserData[id][iIsUserClanLeader] = 0;
            
g_UserData[id][iIsUserClanSecondLeader] = 0;
            
g_UserData[id][iIsUserClanMember] = 1;

            for(new 
0<= get_maxplayers(); i++)
            {
                if(!
is_user_connected(i))
                    continue; 

                
client_print_color(iprint_team_default"%s %L"g_szTagi"PLAYER_ACCEPTED_INVITATION"g_UserData[id][szName], g_UserData[iInviter][ClanName]);
            }
        }
    }

    return 
PLUGIN_CONTINUE;


Last edited by lexzor; 10-03-2021 at 21:57.
lexzor is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-03-2021 , 22:16   Re: string format question
Reply With Quote #6

I edited my last post stating that I think Napoleon_be's suggestion is the way you should probably do it here for simplicity. This is what he was saying:

Code:
formatex(szData, charsmax(szData), "^"%s^" ^"%s^" %i", clanname, clantag, inviterid);
Then you can remove the replace_all() entirely and just use the parse() on szData.

Also, it looks like your player menu is not done correctly because you are using "item" (plus 1) as the player index which will not work.

So, I'd recommend that you send only the userid (get_user_userid()) and then use find_player_ex() to find the proper player index (just in case that player leaves between the player menu being opened and its menu handler being executed). Just remember that you need to include the "#" before the userid so that find_players_ex() will work with the FindPlayer_MatchUserId flag.

For example, your menu item data should simply be "#123" where 123 is the userid.
__________________

Last edited by fysiks; 10-03-2021 at 22:40.
fysiks is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 10-04-2021 , 15:11   Re: string format question
Reply With Quote #7

Nice idea, thanks
lexzor is offline
Reply



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 14:57.


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