Shout command -
Lajko1 - 26.10.2013
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
Re: Shout command -
Pottus - 26.10.2013
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.
Re: Shout command -
Lajko1 - 26.10.2013
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?
Re: Shout command -
Pottus - 26.10.2013
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.
Re: Shout command -
Mattakil - 26.10.2013
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
Re: Shout command -
Lajko1 - 27.10.2013
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
Re: Shout command -
-CaRRoT - 27.10.2013
Try this
PHP код:
if(strcmp(cmd, "/shout", true) == 0 || strcmp(cmd, "/s", true) == 0)
{
if(IsPlayerConnected(playerid))
{
GetPlayerName(playerid, sendername, sizeof(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(string, sizeof(string), "%s shouts: %s!",playerid,result);
ProxDetector(30.0, playerid, string,WHITE,WHITE,WHITE,FADE1,FADE2);
}
return 1;
}
PHP код:
stock ProxDetector(Float:radi, playerid, string[], col1, col2, col3, col4, col5)
{
if(IsPlayerConnected(playerid))
{
new Float:posx, Float:posy, Float:posz;
new Float:oldposx, Float:oldposy, Float:oldposz;
new Float:tempposx, Float:tempposy, Float: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(playerid, oldposx, oldposy, oldposz);
vehicleid = GetPlayerVehicleID(playerid);
}
while (strfind(string, PlayerName(playerid), false) != -1 && PlayerInfo[playerid][pMask])
{
new pos = strfind(string, PlayerName(playerid), false);
strdel(string, pos, pos + strlen(PlayerName(playerid)));
strins(string, "Stranger", pos, 258);
}
for(new i = 0; i < MAX_PLAYERS; i++)
{
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(i, col1, string);
else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8))) SendClientMessage(i, col2, string);
else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4))) SendClientMessage(i, col3, string);
else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2))) SendClientMessage(i, col4, string);
else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi))) SendClientMessage(i, col5, string);
}
else SendClientMessage(i, col1, string);
}
}
}
else SendClientMessage(i, col1, string);
}
}
}
return 1;
}
Re: Shout command -
Lajko1 - 27.10.2013
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
Re: Shout command -
Tomix - 27.10.2013
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;
}
Re: Shout command -
Lajko1 - 27.10.2013
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 ? :/