Raised This Month: $ Target: $400
 0% 

Solved Equivalent of SubString() in AMXX


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Rirre
Veteran Member
Join Date: Nov 2006
Old 07-26-2022 , 17:25   Equivalent of SubString() in AMXX
Reply With Quote #1

For some reason show_motd() cuts the message at 48 characters in Sven Co-op 5.0+.
So I have been googling around for an alternative and found this AS (AngelScript) script functioning for this game.
I gave it a try to convert it and got stuck at the SubString() part. Don't know how to proceed from there though.
This is the original AS code:
Code:
void UTIL_ShowMOTD( edict_t@ client, string motd, int mlen, const string name ) {     const string hostname = g_EngineFuncs.CVarGetString( "hostname" ); //g_pvHostname.GetString();     if ( !hostname.IsEmpty() && hostname != name )     {         NetworkMessage msgname( MSG_ONE, NetworkMessages::ServerName, g_vecZero, client );         msgname.WriteString( name );         msgname.End();     }     string chunk;     int a = 0;     while ( mlen > a )     {         chunk = motd.SubString( a, a + MAX_MOTD_CHUNK > mlen ? mlen - a : MAX_MOTD_CHUNK );         a += MAX_MOTD_CHUNK;         NetworkMessage msgmotd( MSG_ONE, NetworkMessages::MOTD, g_vecZero, client );         msgmotd.WriteByte( chunk.Length() == MAX_MOTD_CHUNK ? uint8( 0 ) : uint8( 1 ) ); // 0 means there is still more message to come         msgmotd.WriteString( chunk );         msgmotd.End();      }         if ( !hostname.IsEmpty() && hostname != name )     {         NetworkMessage msghostname( MSG_ONE, NetworkMessages::ServerName, g_vecZero, client );         msghostname.WriteString( hostname );         msghostname.End();     } }

How far I have come with the conversion to AMXX:
Code:
stock UTIL_ShowMOTD(player, szMessage[], iLen, szHead[]) {     new szServerName[MAX_NAME_LENGTH];     get_cvar_string("hostname", szServerName, charsmax(szServerName));     Util_ServerName(player, szHead);     new chunk[MAX_MOTD_CHUNK];     new a = 0;     while( iLen > a )     {         copy(chunk, sizeof(chunk), szMessage);         // The equivalent of SubString() here         a += MAX_MOTD_CHUNK;         message_begin(player ? MSG_ONE : MSG_ALL, get_user_msgid("MOTD"), _, player);         write_byte(strlen(chunk) == MAX_MOTD_CHUNK ? 0 : 1);         write_string(chunk);         message_end();     }     Util_ServerName(player, szServerName); }

Last edited by Rirre; 07-26-2022 at 19:02.
Rirre is offline
 



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 15:38.


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