Shout command
#1

Hey I have problem with Shout command, I can't make it work, so problem is when I write /shout "a" it says "USAGE: /shout [text]" when I do /shout AAAAAaaaaaaaAAAAA it says me same thing "USAGE:...." if I write /shout (a lot of mixed letters) it will show only last letters for example: iagnslfhwrshnaskdbngh it will show: "(name) shouts: bngh"
What is wrong?

pawn Код:
if(strcmp(cmd, "/shout", true) == 0)
    {
        //if(IsDown[playerid] == 1 || IsDown[playerid] == 2) { return SendClientMessage(playerid,0xFF0000AA,"You can't shout while incapacitated."); }
        if(IsPlayerConnected(playerid))
        {
            GetPlayerName(playerid, Name, sizeof(Name));
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[256];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = cmdtext[idx];
                idx++;
            }
            if(!strlen(result))
            {
                SendClientMessage(playerid, 0xffffffff, "USAGE: /shout [text]");
                return 1;
            }
            format(Str, sizeof(Str), "%s shouts: %s", Name, result);
            SendClientMessage(playerid, 0xffffffff, Str);
            //ProxDetector(30.0, playerid, string,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF);
            printf("- /shout: %s", Str);
        }
        return 1;
    }
    return 0;
}
this is also what I have current OnPlayerCommandText:
pawn Код:
new cmd[256];
    new tmp[256];
    new idx;
    cmd = strtok(cmdtext, idx);
    tmp = strtok(cmdtext, idx);
    new id = strval(tmp);
    new Float:x;
    new Float:y;
    new Float:z;
    new Str[256];
And I'm using strtok also..
pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
I think I showed you everything I need :P thanks for help in advance
Reply
#2

Your using such primitive methods to do this it's like comparing rubbing two sticks together to having a lighter.

Use sscanf() and a good command processor.
Reply
#3

I can't use it with sscanf because it's not for me, and server have commands in strcmp and there is no time to convert everything to zcmd + sscanf.. to much commands there, so can you help me with this /shout, please?
Reply
#4

Give me a break dude, that is complete non-sense it's not hard to do at all. In fact you should just be able to toss zcmd include in without converting everything.
Reply
#5

Converting strcmp to zcmd is easy, just use ctrl+h thats how I did it for someone D:

instead of strlen, use if(IsNull(params))

idk if that works of not but :P
Reply
#6

Cmon guys im not asking for converting to zcmd + sscanf i need help with this command i've posted here :/ and you may tell me what is so much better at zcmd plus sscanf easier and faster? And help me with my shout cmd please cuz i really need it, i will convert commans other time but now i need shout in strcmp :/ thanks for responding anyway
Reply
#7

Try this

PHP код:
    if(strcmp(cmd"/shout"true) == || strcmp(cmd"/s"true) == 0)
    {
        if(
IsPlayerConnected(playerid))
        {
            
GetPlayerName(playeridsendernamesizeof(sendername));
            new 
length strlen(cmdtext);
            while ((
idx length) && (cmdtext[idx] <= ' '))
            {
                
idx++;
            }
            new 
offset idx;
            new 
result[MAX_PARAM_LENGTH];
            while ((
idx length) && ((idx offset) < (sizeof(result) - 1)))
            {
                
result[idx offset] = cmdtext[idx];
                
idx++;
            }
            
result[idx offset] = EOS;
            if(!
strlen(result))
            {
                
SendClientMessage(playerid,COLOR"(/s)hout [local chat]");
                return 
1;
            }
            
format(stringsizeof(string), "%s shouts: %s!",playerid,result);
                         
ProxDetector(30.0playeridstring,WHITE,WHITE,WHITE,FADE1,FADE2);
        }
        return 
1;
    } 
PHP код:
stock ProxDetector(Float:radiplayeridstring[], col1col2col3col4col5)
{
    if(
IsPlayerConnected(playerid))
    {
        new 
Float:posxFloat:posyFloat:posz;
        new 
Float:oldposxFloat:oldposyFloat:oldposz;
        new 
Float:tempposxFloat:tempposyFloat:tempposz;
        new 
invehicle[MAX_PLAYERS];
        new 
virtualworld GetPlayerVirtualWorld(playerid);
        new 
interior GetPlayerInterior(playerid);
        new 
vehicleid GetPlayerVehicleID(playerid);
        new 
ivehicleid;
        if(
vehicleid)
        {
            
GetVehiclePos(vehicleid,oldposx,oldposy,oldposz);
        }
        else
        {
            
GetPlayerPos(playeridoldposxoldposyoldposz);
            
vehicleid GetPlayerVehicleID(playerid);
        }
        while (
strfind(stringPlayerName(playerid), false) != -&& PlayerInfo[playerid][pMask])
        {
            new 
pos strfind(stringPlayerName(playerid), false);
            
strdel(stringpospos strlen(PlayerName(playerid)));
               
strins(string"Stranger"pos258);
        }
        for(new 
0MAX_PLAYERSi++)
        {
            if(
IsPlayerConnected(i))
            {
                if(!
BigEar[i])
                {
                    if(
GetPlayerVirtualWorld(i) == virtualworld)
                    {
                        if((
GetPlayerInterior(i) == interior))
                        {
                            if(
vehicleid)
                            {
                                if(
IsPlayerInVehicle(i,vehicleid)) invehicle[i] = 1;
                            }
                            if(!
invehicle[i])
                            {
                                if(
IsPlayerInAnyVehicle(i))
                                {
                                    
ivehicleid GetPlayerVehicleID(i);
                                    
GetVehiclePos(ivehicleid,posx,posy,posz);
                                }
                                else
                                {
                                    
GetPlayerPos(i,posx,posy,posz);
                                }
                                
tempposx = (oldposx -posx);
                                
tempposy = (oldposy -posy);
                                
tempposz = (oldposz -posz);
                                if (((
tempposx radi/16) && (tempposx > -radi/16)) && ((tempposy radi/16) && (tempposy > -radi/16)) && ((tempposz radi/16) && (tempposz > -radi/16))) SendClientMessage(icol1string);
                                else if (((
tempposx radi/8) && (tempposx > -radi/8)) && ((tempposy radi/8) && (tempposy > -radi/8)) && ((tempposz radi/8) && (tempposz > -radi/8))) SendClientMessage(icol2string);
                                else if (((
tempposx radi/4) && (tempposx > -radi/4)) && ((tempposy radi/4) && (tempposy > -radi/4)) && ((tempposz radi/4) && (tempposz > -radi/4))) SendClientMessage(icol3string);
                                else if (((
tempposx radi/2) && (tempposx > -radi/2)) && ((tempposy radi/2) && (tempposy > -radi/2)) && ((tempposz radi/2) && (tempposz > -radi/2))) SendClientMessage(icol4string);
                                else if (((
tempposx radi) && (tempposx > -radi)) && ((tempposy radi) && (tempposy > -radi)) && ((tempposz radi) && (tempposz > -radi))) SendClientMessage(icol5string);
                            }
                            else 
SendClientMessage(icol1string);
                        }
                    }
                }
                else 
SendClientMessage(icol1string);
            }
        }
    }
    return 
1;

Reply
#8

pawn Код:
error 017: undefined symbol "MAX_PARAM_LENGTH"
error 009: invalid array size (negative, zero or out of bounds)
error 036: empty statement
fatal error 107: too many error messages on one line
on this line

pawn Код:
new result[MAX_PARAM_LENGTH]; // ERROR LINE
Reply
#9

Try this
Код:
CMD:shout(playerid, params[])
{
    new string[128],shout[100];
    if(sscanf(params, "s[100]", shout))
    {
        SendClientMessage(playerid, -1, ""chat" /(s)hout [message]");
        return 1;
    }
    else
    {
        format(string, sizeof(string), "%s shouts: %s!",PlayerName(playerid),shout);
        ProxDetector(80.0, playerid, string, COLOR_GREY);
    }
    return 1;
}
Reply
#10

Okay I make it work somehow with your help guys but now there is the problem when I write /b or /d or /c or any command that does not exist it will write "/(s)hout [local chat]" here is the command

pawn Код:
if(strcmp(cmd, "/shout", true) == 0 || strcmp(cmd, "/s", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            GetPlayerName(playerid, Name, sizeof(Name));
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[256];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = cmdtext[idx];
                idx++;
            }
            result[idx - offset] = EOS;
            if(!strlen(result))
            {
                SendClientMessage(playerid,COLOR_LIGHTGREEN, "(/s)hout [local chat]");
                return 1;
            }
            if(Masked[playerid] == 1) format(Str, sizeof(Str), "* Stranger shouts: %s",result);
            else format(Str, sizeof(Str), "%s shouts: %s!",Name,result);
            SendClientMessage(playerid,COLOR_LIGHTGREEN, Str);
            //ProxDetector(30.0, playerid, Str,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA);
            printf("- /shout:  %s", Str);
        }
        return 1;
    }
How ti fix it ? :/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)