ajuda pawno - teteu - 12/02/2024
por algum motivo eu uso o comando e a mensagem da string simplismente nao aparece no chat, alguem ajuda?
Código: if (strcmp(cmd, "/abd", true) == 0)
{
new fardado = false;
for (new s; s < 16; s++)
{
if (GetPlayerSkin(playerid) == FardaSkin[s] ||
GetPlayerSkin(playerid) == 265 ||
GetPlayerSkin(playerid) == 267 ||
GetPlayerSkin(playerid) == 266 ||
GetPlayerSkin(playerid) == 281 ||
GetPlayerSkin(playerid) == 282 ||
GetPlayerSkin(playerid) == 283 ||
GetPlayerSkin(playerid) == 284 ||
GetPlayerSkin(playerid) == 285 ||
GetPlayerSkin(playerid) == 286 ||
GetPlayerSkin(playerid) == 287 ||
GetPlayerSkin(playerid) == 288 ||
GetPlayerSkin(playerid) == 289 ||
GetPlayerSkin(playerid) == 306 ||
GetPlayerSkin(playerid) == 307 ||
GetPlayerSkin(playerid) == 308 ||
GetPlayerSkin(playerid) == 309 ||
GetPlayerSkin(playerid) == 310 ||
GetPlayerSkin(playerid) == 311)
{
fardado = true;
break;
}
}
if (!fardado)
{
return SendClientMessage(playerid, COR_ERRO, "| ERRO | Você não está fardado.");
}
else
{
new string[128];
new corp[32];
if (PROF[playerid] == PM)
{
format(corp, sizeof corp, "PM");
}
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i) && i != playerid)
{
new Float:px, Float:py, Float:pz;
GetPlayerPos(i, px, py, pz);
new Float:distance = GetDistance3D(x, y, z, px, py, pz);
if (distance <= 15.0)
{
format(string, sizeof string, "[{FFD700}%s][%s] ENCOSTA!! ENCOSTA!! ABORDAGEM DE ROTINA.", corp, PlayerName(playerid));
SendClientMessage(playerid, COR_AMARELO, string);
SendClientMessage(i, COR_AMARELO, string);
}
}
}
}
return 1;
RE: ajuda pawno - Fack_Insane - 12/02/2024
Bem amigo não dá pra entender esse código recomendo usar um processador de comandos ao invés de strcmp
RE: ajuda pawno - Luiz - 12/02/2024
Com o break o código não continua. Precisa removê-lo.
É interessante que ao invés de fazer uma verificação enorme pra saber se está fardado, use uma função para facilitar.
Código PHP: stock Fardado(playerid) { if(GetPlayerSkin(playerid) == FardaSkin[s] || GetPlayerSkin(playerid) == 265 || GetPlayerSkin(playerid) == 267 || GetPlayerSkin(playerid) == 266 || GetPlayerSkin(playerid) == 281 || GetPlayerSkin(playerid) == 282 || GetPlayerSkin(playerid) == 283 || GetPlayerSkin(playerid) == 284 || GetPlayerSkin(playerid) == 285 || GetPlayerSkin(playerid) == 286 || GetPlayerSkin(playerid) == 287 || GetPlayerSkin(playerid) == 288 || GetPlayerSkin(playerid) == 289 || GetPlayerSkin(playerid) == 306 || GetPlayerSkin(playerid) == 307 || GetPlayerSkin(playerid) == 308 || GetPlayerSkin(playerid) == 309 || GetPlayerSkin(playerid) == 310 || GetPlayerSkin(playerid) == 311) return true; return false; }
Uso:
Código PHP: if(!Fardado[playerid]) return SendClientMessage(playerid, -1, "Você não está fardado.");
RE: ajuda pawno - White_Blue - 12/02/2024
Este código está totalmente mal otimizado e desatualizado. Recomendo o uso de processadores de comando como y_commands ou Pawn.CMD, pois strcmp para criar comandos é muito lento e completamente obsoleto.
Segue um código simplificado utilizando Pawn.CMD, com a verificação de farda em uma função reutilizável (adapte conforme suas necessidades):
Código PHP: // Esse comando de abordar faria mais sentido ser por ID e não por proximidade para evitar situações em que dois jogadores estão próximos e o policial pode acabar abordando o jogador errado CMD:abordar(playerid) { if(!Fardado(playerid)) return SendClientMessage(playerid, -1, "Você não está fardado");
for(new i = 0; i < MAX_PLAYERS; i++) /* Para este tipo de loop recomendo o uso do foreach, basta trocar para foreach(new i : Player) caso esteja usando YSI */ { if(GetDistanceBetweenPlayers(playerid, i) > 8.0) continue;
format(string, sizeof(string), "[{FFD700}%s][%s] ENCOSTA!! ENCOSTA!! ABORDAGEM DE ROTINA.", corp, PlayerName(playerid)); SendClientMessage(i, COR_AMARELO, string); } return 1; }
// Essa verificação gigante aqui também é completamente desnecessária na minha opinião, faz muito mais sentido criar uma variável booleana para determinar se o jogador está fardado ou não ao invés de todas essas verificações. stock bool:Fardado(playerid) { if(GetPlayerSkin(playerid) == 265 || GetPlayerSkin(playerid) == 267 || GetPlayerSkin(playerid) == 266 || GetPlayerSkin(playerid) == 281 || GetPlayerSkin(playerid) == 282 || GetPlayerSkin(playerid) == 283 || GetPlayerSkin(playerid) == 284 || GetPlayerSkin(playerid) == 285 || GetPlayerSkin(playerid) == 286 || GetPlayerSkin(playerid) == 287 || GetPlayerSkin(playerid) == 288 || GetPlayerSkin(playerid) == 289 || GetPlayerSkin(playerid) == 306 || GetPlayerSkin(playerid) == 307 || GetPlayerSkin(playerid) == 308 || GetPlayerSkin(playerid) == 309 || GetPlayerSkin(playerid) == 310 || GetPlayerSkin(playerid) == 311) return true; return false; }
stock Float:GetDistanceBetweenPlayers(playerid, targetid) { static Float:X, Float:Y, Float:Z; GetPlayerPos(targetid, X, Y, Z); return GetPlayerDistanceFromPoint(playerid, X, Y, Z); }
|