strtok causing problems?
#1

I am trying to load 4 seperate filterscripts with a stock strtok in each but the final one i load doesnt work

i get no errors, all compiled successfully, all scripts run fine until they are all loaded.

they all use the onplayercommandtext bit

what am i missing?
Reply
#2

Please show the command
Reply
#3

well i think its down to my invalids filterscript.

ill post that one:

Код:
#define FILTERSCRIPT
#include <a_samp>
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
stock strtok(const string[], &index)
{
  new length = strlen(string);
  while ((index < length) && (string[index] <= ' '))
  {
   index++;
  }

  new offset = index;
  new result[20];
  while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  {
   result[index - offset] = string[index];
   index++;
  }
  result[index - offset] = EOS;
  return result;
}
new playercash;
new InvalidNosVehicles[30] =
{
  581,523,462,521,463,522,461,448,468,586,
  509,481,510,472,473,493,595,484,430,453,
  452,446,454,590,569,537,538,539,570,449
};
new InvalidSellVehicles[21] =
{
  592,537,538,449,435,450,524,528,553,569,
  570,584,590,591,592,601,606,607,608,610,
  611
};
forward IsPlayerInInvalidNosVehicle(playerid);
forward IsPlayerInInvalidSellVehicle(playerid);

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print("---Invalids Filterscript (Sell/Nos)---");
	print("--------------------------------------\n");
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

public IsPlayerInInvalidNosVehicle(playerid)
{
  new carid = GetPlayerVehicleID(playerid);
  new carmodel = GetVehicleModel(carid);
  for (new i=0; i<sizeof(InvalidNosVehicles); i++) {
    if (carmodel == InvalidNosVehicles[i]) return 1;
  }
  return 0;
}


public IsPlayerInInvalidSellVehicle(playerid)
{
  new carid = GetPlayerVehicleID(playerid);
  new carmodel = GetVehicleModel(carid);
  for (new i=0; i<sizeof(InvalidSellVehicles); i++) {
    if (carmodel == InvalidSellVehicles[i]) return 1;
  }
  return 0;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
  new string[256];
  new cmd[256];
  new idx;

  cmd = strtok(cmdtext, idx);
  if(strcmp(cmdtext, "/sell", true) == 0) {
    if(IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) != 0) {
      SendClientMessage(playerid, 0xFFFFFFFF, "You are not driving this vehicle!");
    }
    if(!IsPlayerInAnyVehicle(playerid)) {
      SendClientMessage(playerid, 0xFFFFFFFF, "Your not in a vehicle!");
    }
    if(IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0) {

      new carvalue;
      new carvaluedamaged1;
      new carvaluedamaged2;
      new currentveh;
      new Float:health;

      currentveh = GetPlayerVehicleID(playerid);

      GetVehicleHealth(currentveh, health);
      carvaluedamaged1 = random(2500);
      carvaluedamaged2 = random(900);

      if(health == 1000) {
        carvalue = random(5000);
      }
      else if (health >999) {
        carvalue = carvaluedamaged1;
      }
      else if (health >550) {
        carvalue = carvaluedamaged2;
      }
      if(!IsPlayerInInvalidSellVehicle(playerid)) {
        DestroyVehicle(currentveh);
        format(string, sizeof(string), "You get %i for your vehicle!", carvalue);
        SendClientMessage(playerid, 0xFFFFFFFF, string);
        GivePlayerMoney(playerid, carvalue);
      }
      else {
        SendClientMessage(playerid, 0xFFFFFFFF, "This vehicle can't be sold!");
      }

    }
    return 1;
  }
  if(strcmp(cmd, "/nos", true) == 0) {

    playercash = GetPlayerMoney(playerid);

    if (IsPlayerInAnyVehicle(playerid)) {
      if(!IsPlayerInInvalidNosVehicle(playerid)) {
        if(playercash > 50) {
                         // Nitro
          AddVehicleComponent(GetPlayerVehicleID(playerid), 1009);
          SendClientMessage(playerid, 0xFFFFFFAA, "Nitro added.");
          GivePlayerMoney(playerid, -50);
        }
        else {
          SendClientMessage(playerid, 0xFFFFFFAA, "You need more money.");
        }
      }
      else {
        SendClientMessage(playerid, 0xFFFFFFAA, "Put your money away, this vehicle cant have nitrous.");
      }
    }
    else {
      SendClientMessage(playerid, 0xFFFFFFAA, "Your not in a car.");
    }
    return 1;
  }
  return 1;
}
Reply
#4

im just gonna stick that bit back in the gamemode rather than mess around
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)