[QUESTION] About OnPlayerCommandText
#1

Hello guys I have a question. I wrote this code which heals specific player...
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);
        }  
    }
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?
Reply


Messages In This Thread
[QUESTION] About OnPlayerCommandText - by vakhtang - 29.08.2014, 16:08
Re: [QUESTION] About OnPlayerCommandText - by Stinged - 29.08.2014, 16:11
Re: [QUESTION] About OnPlayerCommandText - by vakhtang - 29.08.2014, 16:13
Re: [QUESTION] About OnPlayerCommandText - by vakhtang - 29.08.2014, 16:18

Forum Jump:


Users browsing this thread: 1 Guest(s)