This is actually covered in the section for the function you should use at the wiki: https://sampwiki.blast.hk/wiki/Strins
To get it random, simply store random prefixes in an array then use random() to select a random index of the array. |
Thank you for help, but I dont understand this. I'm noob in scripting
![]() |
CMD:astatus(playerid, params[])
{
new
szPrefix[ 10 ] //I chose 9 letters as maximum (7 inside [ ])
;
if( sscanf( params, "s[10]", szPrefix ))
return SendClientMessage( playerid, 0x00FF00FF, "[USAGE] /astatus (prefix)" );
new
szName[ MAX_PLAYER_NAME ]
;
GetPlayerName( playerid, szName, MAX_PLAYER_NAME );
format( szPrefix, sizeof( szPrefix ), "[%s]", szPrefix ); //put it in square brackets
strins( szName, szPrefix, 0 ); //this would insert the parameter (prefix) at the beginning of the name string
SetPlayerName( playerid, szName ); //change the name to the newly updated string with the prefix.
return true;
}
new
g_szPrefixes[][] =
{
"Prefix1",
"Prefix2
}
;
CMD:astatus(playerid, params[])
{
new
szPrefix[ 10 ] //I chose 9 letters as maximum (7 inside [ ])
;
sscanf( params, "S[10]", szPrefix ));
new
szName[ MAX_PLAYER_NAME ]
;
GetPlayerName( playerid, szName, MAX_PLAYER_NAME );
if( isnull( szPrefix ))
{
new
iRand = random( sizeof( g_szPrefixes ))
;
strcat( szPrefix, g_szPrefixes[ iRand ] );
}
format( szPrefix, sizeof( szPrefix ), "[%s]", szPrefix ); //put it in square brackets
strins( szName, szPrefix, 0 ); //this would insert the parameter (prefix) at the beginning of the name string
SetPlayerName( playerid, szName ); //change the name to the newly updated string with the prefix.
return true;
}
CMD:astatusoff(playerid, params[])
{
SetPlayerName( playerid, g_szMyGlobalNameVariable[ playerid ] ); //change the name to the newly updated string with the prefix.
return true;
}
error 017: undefined symbol "g_szMyGlobalNameVariable" warning 215: expression has no effect error 001: expected token: ";", but found "]" error 029: invalid expression, assumed zero
SetPlayerName(playerid, g_szMyGlobalNameVariable[playerid]); //change the name to the newly updated string with the prefix.