Variable help
#2

you dont ue strtok to set variables it looks in a string for a token usually a space " " but not all ways ill give you a quick example of how to seperate a cmdtext string my a space

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[]){
    new index,giveplayerid;
    new cmd[256],tmp[256];
    cmd = strtok(cmdtext, index);

    if (strcmp("/stats", cmd, true, 10) == 0)   {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) { //if nothing was typed after the command send help
            SendClientMessage(playerid,COLOUR_WHITE,"Usage:/stats 'ID'");
            return 1;
        }
        giveplayerid = strval(tmp);//a playerid is a number so we conver the string to a number
        if(!IsPlayerConnected(giveplayerid)) {//is the requested player connected
            SendClientMessage(playerid,COLOUR_BAD,"Invalid ID");
            return 1;
        }
        else {
            // show stats
            printf("stats for playid %d",giveplayerid); //info to console
            return 1;
        }
    }
    return 0;
}
hope that helps
Reply


Messages In This Thread
Variable help - by yarrum3 - 08.02.2011, 00:36
Re: Variable help - by (SF)Noobanatior - 08.02.2011, 03:08

Forum Jump:


Users browsing this thread: 1 Guest(s)