How to make... ?
#1

Hello,

I want to make a teleport sistem like this:

/goto [city] [location]

Example: /goto lasventuras 3

Can anyone give me an example ? Thanks.

Btw. I use strcmp

Reply
#2

12+ hours passed. BUMP !
Reply
#3

Use dcmd and sscanf instead, it's much easier to use / understand.
With sscanf, you need to check for a string, then an integrer, so the format will be "sd".
Check the string (which will store the city) with strcmp for these: "lasventuras", "lv". If it is the same, tele the player to the location of that city the player has given.
Do the same for "sanfierro", "sf" and "lossantos", "ls"
DCMD and SSCANF
Reply
#4

My whole gamemode is on strcmp so i'll stick by it for now.

Thanks for the theory, but could you give some example code ? Thank you.
Reply
#5

pawn Код:
if(!strcmp(cmdtext, "/goto lasventuras 3", true))
  {
  SetPlayerPos(playerid,floatx,floaty,floatz);
  return 1;
  }

 if(!strcmp(cmdtext, "/goto lasventuras 4", true))
  {
  SetPlayerPos(playerid,floatx,floaty,floatz);
  return 1;
  }

And so on ....
Reply
#6

Quote:
Originally Posted by ►►►Peter Corneile◄◄◄
pawn Код:
if(!strcmp(cmdtext, "/goto lasventuras 3", true))
  {
  SetPlayerPos(playerid,floatx,floaty,floatz);
  return 1;
  }

 if(!strcmp(cmdtext, "/goto lasventuras 4", true))
  {
  SetPlayerPos(playerid,floatx,floaty,floatz);
  return 1;
  }

And so on ....
VERY VERY bad code right there. That's just going to literally clatter up your OnPlayerCommandText() with useless code. Read this: https://sampwiki.blast.hk/wiki/Dcmd
Reply
#7

That's not a good way to do, it should be done using only one command.

I'd post the code for the dcmd, but I'm not too good with strtok, sorry.
Reply
#8

Then post it but keep in mind that he wants a strcmp one .. So mine would be fine for him
Reply
#9

pawn Код:
// FOLLOWING ARE JUST FOR EXAMPLES, MODIFY THEM AS NEEDED !
new Float:LSTeles[3][5] =
{
    {X, Y, Z, A, INT},
    {X, Y, Z, A, INT},
    {X, Y, Z, A, INT}
};
new Float:SFTeles[3][5] =
{
    {X, Y, Z, A, INT},
    {X, Y, Z, A, INT},
    {X, Y, Z, A, INT}
};
new Float:LVTeles[3][5] =
{
    {X, Y, Z, A, INT},
    {X, Y, Z, A, INT},
    {X, Y, Z, A, INT}
};

dcmd_goto(playerid, params[])
{
    new
      city[32],
      telenum;
    if (sscanf(params, "sd", city, telenum) != 0)
    {
        SendClientMessage(playerid, COLOR_SERVER, "Usage: /goto <city> <location ID>");
        return 1;
    }
    if (telenum < 0) return SendClientMessage(playerid, COLOR, "[FAIL] Location ID can not be lower than 0");
    if (!strcmp(city, "ls", true, 2) || !strcmp(city, "lossantos", true, 9))
    {
      SetPlayerPos(playerid, LSTeles[telenum][0], LSTeles[telenum][1],LSTeles[telenum][2]);
      SetPlayerFacingAngle(playerid, LSTeles[telenum][3]);
      SetPlayerInterior(playerid, LSTeles[telenum][4]);
      format(city, sizeof(city), "Teleported to #%d in LS.", telenum);
      SendClientMessage(playerid, COLOR, city);
      return 1;
    }
    if (!strcmp(city, "sf", true, 2) || !strcmp(city, "sanfierro", true, 9))
    {
      SetPlayerPos(playerid, LSTeles[telenum][0], LSTeles[telenum][1],LSTeles[telenum][2]);
      SetPlayerFacingAngle(playerid, LSTeles[telenum][3]);
      SetPlayerInterior(playerid, LSTeles[telenum][4]);
      format(city, sizeof(city), "Teleported to #%d in SF.", telenum);
      SendClientMessage(playerid, COLOR, city);
      return 1;
    }
    if (!strcmp(city, "lv", true, 2) || !strcmp(city, "lasventuras", true, 11))
    {
      SetPlayerPos(playerid, LSTeles[telenum][0], LSTeles[telenum][1],LSTeles[telenum][2]);
      SetPlayerFacingAngle(playerid, LSTeles[telenum][3]);
      SetPlayerInterior(playerid, LSTeles[telenum][4]);
      format(city, sizeof(city), "Teleported to #%d in LV.", telenum);
      SendClientMessage(playerid, COLOR, city);
      return 1;
    }
    return 1;
}
Reply
#10

I call this just showing off as he asked for a strcmp .. Anyways i dont care
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)