First of all, the callback must exist in a loaded filterscript for it to work in gamemode. Looking at CallRemoteFunction, I presume that's what you do.
About the problem: returning 0 means that the command did not exist and it searches in other script. What you do here is:
pawn Код:
if (...) return printf(...);
but printf does not return any specific value; thus makes it return 0. In order to fix it, all you have to do is:
pawn Код:
if (...)
{
printf(...);
return 1; // command was found
}
The methods you are using are not up-to-date and especially strtok which is used since 2006. sscanf is so much faster and it's the best string splitter you can find out there - consider using it!
Player pool was added in 0.3.7 and reduces the iterators a player-loop will have (especially if you have not re-defined MAX_PLAYERS and you just loop
1000 times for nothing). Foreach/y_iterate is also great include.
PHP код:
public OnRconCommand(cmd[])
{
if (!strcmp(cmd, "sms", true))
{
print("Usage: /rcon sms <nick>");
return 1;
}
if (!strcmp(cmd, "sms ", true, 4))
{
printf("[SMS]");
printf("[SMS] Aktywowano komende");
if (!(3 <= strlen(cmd[4]) <= 20))
{
print("[SMS] Blad! Za krуtki/dlugi nick.");
return 1;
}
printf("[SMS] Podany nick: '%s', szukam gracza...", cmd[4]);
new Nick2[MAX_PLAYER_NAME];
for (new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if (IsPlayerConnected(i) == 0) continue;
GetPlayerName(i, Nick2, sizeof(Nick2));
if (!strcmp(cmd[4], Nick2))
{
printf("[SMS] Gracz znaleziony.", cmd[4]);
if (IsPlayerNPC(i))
{
printf("[SMS] Blad! Wybrany gracz to NPC.");
return 1;
}
printf("[SMS] Wreczam klucz graczowi: '%s' ID: %d", Nick2, i);
CallRemoteFunction("DajKlucz", "i", i);
return 1;
}
}
printf("[SMS] Blad! Nie znaleziono gracza o nicku '%s'", cmd[4]);
return 1;
}
return 0;
}