Non-Rp name Kick
#1

Wanna do a kick command.

/kicknonrp

Kicks the player, and sends clientmessagetoall

%s was kicked, come back with a roleplaying name such as GETPLAYERNAME

no idea..

EDIT:

I USE STRCMP
Reply
#2

It's pretty easy, have a sec and I make it for you.
Reply
#3

allright thanks
Reply
#4

pawn Код:
dcmd_kicknonrp(playerid,params[])
{
    new target;
    if(!sscanf(params,"u",target))
    {
        if(IsPlayerConnected(target))
        {
            new Playername[MAX_PLAYER_NAME],str[70];
            GetPlayerName(target,Playername,sizeof(Playername));
            format(str,sizeof(str),"* %s was kicked, come back with a roleplay name.",Playername);
            SendClientMessageToAll(-1,str);
            Kick(target);
        }
        else return SendClientMessage(playerid,-1,"Invalid player.");
    }
    else return SendClientMessage(playerid,-1,"Error: /kicknonrp [ID].");
}
You may need the DCMD define. I used DCMD here cause it's faster than strcmp and easier to use (but I suggest you ZCMD)

pawn Код:
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
Jochem
Reply
#5

Quote:
Originally Posted by Jochemd
Посмотреть сообщение
pawn Код:
dcmd_kicknonrp(playerid,params[])
{
    new target;
    if(!sscanf(params,"u",target))
    {
        if(IsPlayerConnected(target))
        {
            new Playername[MAX_PLAYER_NAME],str[70];
            GetPlayerName(target,Playername,sizeof(Playername));
            format(str,sizeof(str),"* %s was kicked, come back with a roleplay name.",Playername);
            SendClientMessageToAll(-1,str);
            Kick(target);
        }
        else return SendClientMessage(playerid,-1,"Invalid player.");
    }
    else return SendClientMessage(playerid,-1,"Error: /kicknonrp [ID].");
}
You may need the DCMD define. I used DCMD here cause it's faster than strcmp and easier to use (but I suggest you ZCMD)

pawn Код:
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
Jochem
k with a roleplay name. . I want it to say, come back with a roleplaying name such as %s
Reply
#6

In your script u should have a CMD /name if yeah then its for kick NON-RP names or use the one that he gave you.
Reply
#7

pawn Код:
dcmd_kicknonrp(playerid,params[])
{
    new target;
    if(!sscanf(params,"u",target))
    {
        if(IsPlayerConnected(target))
        {
            new Playername[MAX_PLAYER_NAME],Targetname[MAX_PLAYER_NAME],str[110];
            GetPlayerName(playerid,Playername,sizeof(Playername));
            GetPlayerName(target,Targetname,sizeof(Targetname));
            format(str,sizeof(str),"* %s was kicked, come back with a roleplay name such as %s.",Targetname,Playername);
            SendClientMessageToAll(-1,str);
            Kick(target);
        }
        else return SendClientMessage(playerid,-1,"Invalid player.");
    }
    else return SendClientMessage(playerid,-1,"Error: /kicknonrp [ID].");
}
Reply
#8

not defined, targetname
Reply
#9

i added it, when i did /kicknonrp ID, it kicks myself
Reply
#10

you can also use this stock function to detect if the player uses Non-RP name:
pawn Код:
stock IsRPName(const name[], max_underscores = 2)
{
    new underscores = 0;
    if (name[0] < 'A' || name[0] > 'Z') return false; // First letter is not capital
    for(new i = 1; i < strlen(name); i++)
    {
        if(name[i] != '_' && (name[i] < 'A' || name[i] > 'Z') && (name[i] < 'a' || name[i] > 'z')) return false; // a-zA-Z_
        if( (name[i] >= 'A' && name[i] <= 'Z') && (name[i - 1] != '_') ) return false; // unneeded capital letter
        if(name[i] == '_')
        {
            underscores++;
            if(underscores > max_underscores || i == strlen(name)) return false; // More underlines than limit, or underline at the last pos
            if(name[i + 1] < 'A' || name[i + 1] > 'Z') return false; // Not a capital letter after underline
        }
    }
    if (underscores == 0) return false; // No underline detected
    return true;
}
under OnPlayerConnect, you put:
pawn Код:
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME], roleplayname[MAX_PLAYER_NAME] = "Will_Smith", goodbyemessage[108];
    GetPlayerName(playerid, name, sizeof(name));
    if (!IsRPName(name)) // you can control the max underlines, e.g if you allow max. 1 underlines, write this: if (!IsRPName(name, 1))
    {
        for (new i = 0; i < MAX_PLAYERS; i++) if (IsPlayerConnected(i)) break; // find a player who is online (and hasn't got kicked from the server -> has got a RolePlay name
        if (IsPlayerConnected(i)) GetPlayerName(i, roleplayname, MAX_PLAYER_NAME); // if there was an online player, it's name will be the suggested roleplay name
        format (goodbyemessage, sizeof(goodbyemessage), "* %s was kicked, come back with a roleplay name such as %s", name, roleplayname);
        SendClientMessageToAll(-1, goodbyemessage);
        return Kick(playerid);
    }

    // more things you do in OnPlayerConnect
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)