Opa, blz Castiel, consegui arrumar com o seu post, mas, eu digito o comando e n acontece nada..
(Sei que strtok й ultrapassado, mas qero pelo menos aprender como mexer nele)
pawn Код:
#include <a_samp>
new Float:px, Float:py, Float:pz;
public OnFilterScriptInit()
{
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
new string[256];
new cmd[128], idx;
new tmp[128];
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/cumprimentar", true) == 0)
{
tmp = strtok(cmdtext, idx);
if(strlen(tmp) == 0)
return SendClientMessage(playerid, -1, "USO: /cumprimentar [ID/ParteDoNome]");
new otherid;
otherid = ReturnUser(tmp);
if(!IsPlayerConnected(otherid))
return SendClientMessage(playerid, -1, "Esse Player nao estб conectado");
GetPlayerPos(otherid, px, py, pz);
if(!IsPlayerInRangeOfPoint(playerid, 2.0, px, py, pz))
return SendClientMessage(playerid, -1, "Aproxime-se do jogador");
new pname[MAX_PLAYER_NAME];
new oname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
GetPlayerName(otherid, oname, sizeof(oname));
new Float:Angle;
GetPlayerFacingAngle(playerid, Angle);
if(Angle == 0)
{
SetPlayerFacingAngle(otherid, 180);
ApplyAnimation(playerid, "GANGS", "hndshkaa", 4.0, 1, 0, 0, 0, 0);
ApplyAnimation(otherid, "GANGS", "hndshkaa", 4.0, 1, 0, 0, 0, 0);
format(string, sizeof(string), "Vocк comprimentou %s", oname);
SendClientMessage(playerid, -1, string);
format(string, sizeof(string), "Vocк comprimentou %s", pname);
SendClientMessage(otherid, -1, string);
}
if(Angle == 180)
{
SetPlayerFacingAngle(otherid, 0);
ApplyAnimation(playerid, "GANGS", "hndshkaa", 4.0, 1, 0, 0, 0, 0);
ApplyAnimation(otherid, "GANGS", "hndshkaa", 4.0, 1, 0, 0, 0, 0);
format(string, sizeof(string), "Vocк comprimentou %s", oname);
SendClientMessage(playerid, -1, string);
format(string, sizeof(string), "Vocк comprimentou %s", pname);
SendClientMessage(otherid, -1, string);
}
if(Angle == 90)
{
SetPlayerFacingAngle(otherid, 270);
ApplyAnimation(playerid, "GANGS", "hndshkaa", 4.0, 1, 0, 0, 0, 0);
ApplyAnimation(otherid, "GANGS", "hndshkaa", 4.0, 1, 0, 0, 0, 0);
format(string, sizeof(string), "Vocк comprimentou %s", oname);
SendClientMessage(playerid, -1, string);
format(string, sizeof(string), "Vocк comprimentou %s", pname);
SendClientMessage(otherid, -1, string);
}
if(Angle == 270)
{
SetPlayerFacingAngle(otherid, 90);
ApplyAnimation(playerid, "GANGS", "hndshkaa", 4.0, 1, 0, 0, 0, 0);
ApplyAnimation(otherid, "GANGS", "hndshkaa", 4.0, 1, 0, 0, 0, 0);
format(string, sizeof(string), "Vocк comprimentou %s", oname);
SendClientMessage(playerid, -1, string);
format(string, sizeof(string), "Vocк comprimentou %s", pname);
SendClientMessage(otherid, -1, string);
}
return 1;
}
return 0;
}
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;
}
IsNumeric(const string[])
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] > '9' || string[i] < '0') return 0;
}
return 1;
}
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
new pos = 0;
while (text[pos] < 0x21)
{
if (text[pos] == 0) return INVALID_PLAYER_ID;
pos++;
}
new userid = INVALID_PLAYER_ID;
if (IsNumeric(text[pos]))
{
userid = strval(text[pos]);
if (userid >=0 && userid < MAX_PLAYERS)
{
if(!IsPlayerConnected(userid))
{
{
SendClientMessage(playerid, 0xFF0000AA, "User not connected");
}
userid = INVALID_PLAYER_ID;
}
else
{
return userid;
}
}
}
new len = strlen(text[pos]);
new count = 0;
new name[MAX_PLAYER_NAME];
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i, name, sizeof (name));
if (strcmp(name, text[pos], true, len) == 0)
{
if (len == strlen(name))
{
return i;
}
else
{
count++;
userid = i;
}
}
}
}
if (count != 1)
{
if (playerid != INVALID_PLAYER_ID)
{
if (count)
{
SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow earch");
}
else
{
SendClientMessage(playerid, 0xFF0000AA, "No matching user found");
}
}
userid = INVALID_PLAYER_ID;
}
return userid;
}