How to convert this command into ZCMD?
#1

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
        new cmd[256];
        new tmp[256];
        new string[128];
        new idx;
        cmd = strtok(cmdtext, idx);
        if(!strcmp(cmd,"/setaccent", true))
        {
            if(IsPlayerConnected(playerid) && PlayerInfo[playerid][pAdmin] > 1)
            {
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp) || strlen(tmp) <= 6 || strlen(tmp) > 26)
                {
                        SendClientMessage(playerid,0xFFFFFFAA,"Usage: /accent {58A624}[ accent name ]{FFFFFF}.");
                        SendClientMessage(playerid,0xFFFFFFAA,"Example: {58A624}/accent Portuguese ");
                        return 1;
                }
                format(string,sizeof(string),"Accent: You have changed your accent to {58A624}%s.",tmp);
                SendClientMessage(playerid,0xFFFFFFAA,string);
                strmid(pAccent[playerid],tmp,0,sizeof(tmp),255);
                }
                return 1;
        }
        return 0;
}
Reply
#2

PHP код:
CMD:setaccent(playerid,params[])
{
            new 
cmd[256];
            new 
tmp[256];
            new 
string[128];
            new 
idx;
            if(
IsPlayerConnected(playerid) && PlayerInfo[playerid][pAdmin] > 1)
            {
                
tmp strtok(cmdtextidx);
                if(!
strlen(tmp) || strlen(tmp) <= || strlen(tmp) > 26)
                {
                        
SendClientMessage(playerid,0xFFFFFFAA,"Usage: /accent {58A624}[ accent name ]{FFFFFF}.");
                        
SendClientMessage(playerid,0xFFFFFFAA,"Example: {58A624}/accent Portuguese ");
                        return 
1;
                }
                
format(string,sizeof(string),"Accent: You have changed your accent to {58A624}%s.",tmp);
                
SendClientMessage(playerid,0xFFFFFFAA,string);
                
strmid(pAccent[playerid],tmp,0,sizeof(tmp),255);
                }
                return 
1;

Reply
#3

I suggest you use sscanf, strtok is outdated & slow. Anywho here it is, sscanf version.

pawn Код:
CMD:setaccent(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] > 1)
    {
        new accent[27], string[128];
        if(sscanf(params, "s[27]", accent))
        {
            SendClientMessage(playerid,0xFFFFFFAA,"Usage: /accent {58A624}[ accent name ]{FFFFFF}.");
            SendClientMessage(playerid,0xFFFFFFAA,"Example: {58A624}/accent Portuguese ");
            return 1;
        }
        if(strlen(accent) <= 6 || strlen(accent) > 26) return cmd_setaccent(playerid, ""); // recall the command /setaccent
       
        format(string,sizeof(string),"Accent: You have changed your accent to {58A624}%s.",accent);
        SendClientMessage(playerid,0xFFFFFFAA,string);
        strmid(pAccent[playerid],accent,0,sizeof(accent),255);
    }
    return 1;
}
Also you do not need to use IsPlayerConnected when a player uses a command, it is pretty obvious that the user is online, mmm GF Edit alert?
Reply
#4

Quote:
Originally Posted by Mouiz
Посмотреть сообщение
PHP код:
CMD:setaccent(playerid,params[])
{
            new 
cmd[256];
            new 
tmp[256];
            new 
string[128];
            new 
idx;
            if(
IsPlayerConnected(playerid) && PlayerInfo[playerid][pAdmin] > 1)
            {
                
tmp strtok(cmdtextidx);
                if(!
strlen(tmp) || strlen(tmp) <= || strlen(tmp) > 26)
                {
                        
SendClientMessage(playerid,0xFFFFFFAA,"Usage: /accent {58A624}[ accent name ]{FFFFFF}.");
                        
SendClientMessage(playerid,0xFFFFFFAA,"Example: {58A624}/accent Portuguese ");
                        return 
1;
                }
                
format(string,sizeof(string),"Accent: You have changed your accent to {58A624}%s.",tmp);
                
SendClientMessage(playerid,0xFFFFFFAA,string);
                
strmid(pAccent[playerid],tmp,0,sizeof(tmp),255);
                }
                return 
1;

Everything works, but when I got in to test it and I typed in "/accent Jamaican" it just printed:

Usage: /accent [ accent name ]
Example: /accent Portuguese

The accent did not change, I had Johnny [ accent]: Bla bla
Reply
#5

Quote:
Originally Posted by JaKe Elite
Посмотреть сообщение
I suggest you use sscanf, strtok is outdated & slow. Anywho here it is, sscanf version.

pawn Код:
CMD:setaccent(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] > 1)
    {
        new accent[27], string[128];
        if(sscanf(params, "s[27]", accent))
        {
            SendClientMessage(playerid,0xFFFFFFAA,"Usage: /accent {58A624}[ accent name ]{FFFFFF}.");
            SendClientMessage(playerid,0xFFFFFFAA,"Example: {58A624}/accent Portuguese ");
            return 1;
        }
        if(strlen(accent) <= 6 || strlen(accent) > 26) return cmd_setaccent(playerid, ""); // recall the command /setaccent
       
        format(string,sizeof(string),"Accent: You have changed your accent to {58A624}%s.",accent);
        SendClientMessage(playerid,0xFFFFFFAA,string);
        strmid(pAccent[playerid],accent,0,sizeof(accent),255);
    }
    return 1;
}
Also you do not need to use IsPlayerConnected when a player uses a command, it is pretty obvious that the user is online, mmm GF Edit alert?
Wow, yours worked fine..But, idk now...I mean, it doesn't say anything when I type regularly...Here's where I found it
http://pastebin.com/8drSMj1s
Reply
#6

What do you mean type regularly? You mean like if you type

/accent American

or something like, /accent [blank no parameter]?
Reply
#7

Ok, so I messed up everything now...

THIS command, /setaccent, sets your own accent...It should set ANOTHER player's accent, not your own..
/setaccent [Player ID/Part of name] [Accent]


PHP код:
CMD:setaccent(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] > 1)
    {
        new 
accent[27], string[128], tmp[256];
        if(
sscanf(params"s[27]"accent))
        {
            
SendClientMessage(playerid,0xFFFFFFAA,"Usage: /setaccent {58A624}[ Accent name ]{FFFFFF}.");
            return 
1;
        }
        if(
strlen(accent) <= || strlen(accent) > 26) return cmd_setaccent(playerid""); // recall the command /setaccent
        
format(string,sizeof(string),"Accent: You have changed your accent to {58A624}%s.",accent);
        
SendClientMessage(playerid,0xFFFFFFAA,string);
        
strmid(pAccent[playerid],tmp,0,sizeof(tmp),255);
    }
    return 
1;

Now, another problem I have is this...
This is my OnPlayerText, I have it if the player is talking on a cellphpone or not
PHP код:
public OnPlayerText(playeridtext[])
{
    if(
OnCall[playerid] == -1)//If the player is not talking on a cellphone then
    
{
        if(
strlen(pAccent[playerid]) > 0)
        {
            
format(message,sizeof(message),"%s [%s accent]: %s"GetName(playerid), pAccent[playerid], text);
            
ProxDetector(30.0playeridmessage, -1);
              
Log("/logs/chat.txt"message);
              
SetPlayerChatBubble(playerid,text,COLOR_WHITE,20.0,5000);
        }
        else
        {
             
format(messagesizeof(message), "%s says: %s"GetName(playerid), text);
              
ProxDetector(30.0playeridmessage, -1);
              
Log("/logs/chat.txt"message);
              
SetPlayerChatBubble(playerid,text,COLOR_WHITE,20.0,5000);
          }
    }
    
       if(
OnCall[playerid] != -)//If the player is talking on a cellphone then
    
{
        if(
strlen(pAccent[playerid]) > 0)
        {
            
format(string,sizeof(string),"%s [Muffled %s accent](cellhpone) %s"GetPlayerNameEx(playerid), pAccent[playerid], text);
            
ProxDetector(20.0playeridstringCOLOR_FADE1);
              
Log("/logs/chat.txt"string);
              
SetPlayerChatBubble(playerid,text,COLOR_WHITE,20.0,5000);
        }
        else
        {
        
format(stringsizeof(string), "(cellphone) %s says: %s"GetPlayerNameEx(playerid), text);
        
ProxDetector(20.0playeridstring,COLOR_FADE1);
        
Log("/logs/chat.txt"string);
        
SetPlayerChatBubble(playerid,text,COLOR_WHITE,20.0,5000);
        }
    }
    
    
    if(
IsPlayerConnected(OnCall[playerid]))
    {
        if(
OnCall[OnCall[playerid]] == playerid)
        {
            
SendClientMessage(OnCall[playerid], COLOR_YELLOWstring);
            
Log("/logs/cellphone.txt"message);
        }
    }
    return 
0;

OnPlayerConnect

PHP код:
public OnPlayerConnect(playerid)
{
        new 
string[] = " ";
        
strmid(pAccent[playerid],string,0,sizeof string ,255);
        return 
1;

OnPlayerDisconnect

PHP код:
public OnPlayerDisconnect(playeridreason)
{
    new 
string[] = " ";
        
strmid(pAccent[playerid],string,0,sizeof string ,255);
        return 
1;

God faken damn it, if anyone could help it would mean the world to me
Reply
#8

So the problem is...? That you want /setaccent to work for admins, like they can set player's accent but not their accent?
Reply
#9

Quote:
Originally Posted by JaKe Elite
Посмотреть сообщение
So the problem is...? That you want /setaccent to work for admins, like they can set player's accent but not their accent?

Yes, only admins could set the player's accent. I'm just a pawn beginner I don't know how I should write this.
I see you are making a roleplay server yourself, maybe make the accent system there and tell me the code, so you can test it and everything...

This is all I could find about accents: http://pastebin.com/8drSMj1s

Also, I don't like the accent system with dialogs https://sampforum.blast.hk/showthread.php?tid=178112
Reply
#10

Well if you're going to use sscanf just to determine a string from the parameters, you in fact don't need sscanf at all...

Seeing as you now want to include a 'target' parameter, you would do this:
pawn Код:
CMD:setaccent(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] > 1)
    {
        new targetid, accent[26];
        if(sscanf(params, "us[26]", targetid, accent)) return SendClientMessage(playerid, 0xFFFFFFAA, "Usage: /accent {58A624}[ User / ID] [ Accent name ]{FFFFFF}.");
        if(!IsPlayerConnected(targetid) || targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFFFFFFAA, "Player is not connected.");
        new string[80];
        format(string, sizeof(string), "Accent: You have changed %s's accent to {58A624}%s.", GetName(targetid), accent);
        SendClientMessage(playerid, 0xFFFFFFAA, string);
        strmid(pAccent[targetid], accent, 0, 26);
    }
    return 1;
}
Then for your OnPlayerText...
pawn Код:
public OnPlayerText(playerid, text[])
{
    new msg[144]; // Global strings are a no-no.
    if(OnCall[playerid] == -1)// If the player is not talking on a cellphone then
    {
        // I would recommend making use of 'isnull' here instead of strlen.
        if(strlen(pAccent[playerid])) format(msg, sizeof(msg), "%s [%s accent]: %s", GetName(playerid), pAccent[playerid], text);
        else format(msg, sizeof(msg), "%s says: %s", GetName(playerid), text);
        ProxDetector(30.0, playerid, msg, -1);
    }
    else // If the player is talking on a cellphone then
    {
        // I would recommend making use of 'isnull' here instead of strlen.
        if(strlen(pAccent[playerid])) format(msg, sizeof(msg), "%s [Muffled %s accent](cellphone) %s", GetPlayerNameEx(playerid), pAccent[playerid], text);
        else format(msg, sizeof(msg), "(cellphone) %s says: %s", GetPlayerNameEx(playerid), text);
        ProxDetector(20.0, playerid, msg, COLOR_FADE1);
    }
    Log("/logs/chat.txt", msg);
    SetPlayerChatBubble(playerid, msg, COLOR_WHITE, 20.0, 5000);
    if(IsPlayerConnected(OnCall[playerid]))
    {
        if(OnCall[OnCall[playerid]] == playerid)
        {
            SendClientMessage(OnCall[playerid], COLOR_YELLOW, msg);
            Log("/logs/cellphone.txt", msg);
        }
    }
    return 0;
}

public OnPlayerConnect(playerid)
{
    pAccent[playerid][0] = EOS;
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)