29.08.2014, 16:08
Hello guys I have a question. I wrote this code which heals specific player...
So what happens is if i write /heal asdf it heals player with id 0 and I don't want that to happen. strval() returns 0 if the string is not numeric and that is the problem. Any ideas?
pawn Код:
if (strcmp(cmd, "/heal", true) == 0) {
new tmp[128];
tmp = strtok(cmdtext, idx); // find string after " " (space) and store it in tmp
if (strlen(tmp) == 0) {
return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /heal [playerid]");
}
new player = strval(tmp); // get integer value from string (0 if the string is not numeric)
new messageStr[256];
if (!IsPlayerConnected(player)) {
format(messageStr, sizeof(messageStr), "Player with id %i does not exist!", player);
return SendClientMessage(playerid, 0xFFFFFFFF, messageStr);
} else {
format(messageStr, sizeof(messageStr), "Player with id %i has been healed.", player);
SetPlayerHealth(player, 100.0);
return SendClientMessage(playerid, 0xFFFFFFFF, messageStr);
}
}