[HELP] Front Name
#1

Hello!

I have a question. I want to make something like this. When I use /astatus (Name) then I can set a front name. Like (Drifter)Mexix or [DM]Mexix Something like this. When I use /astatusoff then It is just like Mexix.
I can set random name too. But not [Admin] or [admin] in front of my name.

If you dont understand what I mean, then ask for more details.

Hope you understand.



Thank You!
Reply
#2

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.
Reply
#3

Quote:
Originally Posted by LarzI
Посмотреть сообщение
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
Reply
#4

Quote:
Originally Posted by martin3644
Посмотреть сообщение
Thank you for help, but I dont understand this. I'm noob in scripting
Well okay, let me give you an example.

The command would look something like this (using zcmd and sscanf2):
pawn Код:
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;
}
To add random prefix you would simply need to put a global string array, like so:
pawn Код:
new
    g_szPrefixes[][] =
    {
        "Prefix1",
        "Prefix2
    }
;
And so on.

If you'd want the player to get a random prefix when no parameters were written, you could simply alter the command to something like this:
pawn Код:
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;
}
To get the /astatusoff thing to work, you could declare a global string array to hold the player's original name on connect, then just set the players name back to that array whenever a player did /astatusoff. Example:
pawn Код:
CMD:astatusoff(playerid, params[])
{
    SetPlayerName( playerid, g_szMyGlobalNameVariable[ playerid ] ); //change the name to the newly updated string with the prefix.
    return true;
}
I hope you understand a little bit more! If you don't, then I'm sorry - I can't explain it more noobfriendly.
Reply
#5

Very nice, Thank you. I test it now.
Reply
#6

Updated:

Код:
error 017: undefined symbol "g_szMyGlobalNameVariable"
warning 215: expression has no effect
error 001: expected token: ";", but found "]"
error 029: invalid expression, assumed zero
With this:

pawn Код:
SetPlayerName(playerid, g_szMyGlobalNameVariable[playerid]); //change the name to the newly updated string with the prefix.
Reply
#7

OOPS New post. Sorry.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)