SA-MP Forums Archive
how to make a /giveplayerweapon command using strtok? - 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: how to make a /giveplayerweapon command using strtok? (/showthread.php?tid=168642)



how to make a /giveplayerweapon command using strtok? - CSMajor - 16.08.2010

ok my idea didnt work this is what i tried:
pawn Код:
if(strcmp(cmd,"/setweapon",true)==0)
    {
        new giveplayerweapon,giveplayerammo;
        tmp = strtok(cmdtext,idx);
        if(!strlen(tmp))return SendClientMessage(playerid,0xFFF0000FF,"USAGE: /setweapon [PLAYERID] [WEAPONID]");
        {
            giveplayerid = strval(tmp);
            giveplayerweapon = strval(tmp);
            giveplayerammo = strval(tmp);
            GivePlayerWeapon(giveplayerid,giveplayerweapon,giveplayerammo);
        }
        return 1;
    }

and well it epicly failed, so how might i make a command like that with strtok?


Re: how to make a /giveplayerweapon command using strtok? - [XST]O_x - 16.08.2010

pawn Код:
if(strcmp(cmd,"/setweapon",true)==0)
    {
        new tmp[128],tmp2[128],tmp3[128];
        tmp = strtok(cmdtext,idx); tmp2 = strtok(cmdtext,idx); tmp3 = strtok(cmdtext,idx);
       
        if(!strlen(tmp) || !strlen(tmp2) || !strlen(tmp3)) return SendClientMessage(playerid,color,"USAGE: /setweapon [playerid] [weaponid] [ammo]");
        else
        {
            new giveplayerid = strval(tmp),giveplayerweapon = strval(tmp2),giveplayerammo = strval(tmp3);
            GivePlayerWeapon(giveplayerid,giveplayerweapon,giveplayerammo);
        }
        return 1;
    }



Re: how to make a /giveplayerweapon command using strtok? - Injection - 16.08.2010

You created here one only 'tmp', so 'giveplayerid', 'giveplayerweapon' and 'giveplayerammo' will return the '[PLAYERID]' parameter.
You should create two more 'tmp's, try this one:
pawn Код:
if(strcmp(cmd,"/setweapon",true)==0)
    {
        new giveplayerweapon,giveplayerammo;
        tmp = strtok(cmdtext,idx);
        new tmp2[2][64];
        tmp2[0] = strtok(cmdtext,idx), tmp2[1] = strtok(cmdtext,idx);
        if(!strlen(tmp) || !strlen(tmp2[0]) || !strlen(tmp2[1])) return SendClientMessage(playerid,0xFFF0000FF,"USAGE: /setweapon [PLAYERID] [WEAPONID]");
        {
            giveplayerid = strval(tmp);
            giveplayerweapon = strval(tmp2[0]);
            giveplayerammo = strval(tmp2[1]);
            GivePlayerWeapon(giveplayerid,giveplayerweapon,giveplayerammo);
        }
        return 1;
    }