SA-MP Forums Archive
Variable help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Variable help (/showthread.php?tid=222717)



Variable help - yarrum3 - 08.02.2011

how do i set a Variable with strtok


Re: Variable help - (SF)Noobanatior - 08.02.2011

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