GOTO crash
#1

Why does this script crash?
pawn Код:
if(!strcmp(cmd, "/goto", true))
    {
    //News
    new otherplayer;
    tmp = strtok(cmdtext, idx);

    //strlen
    if(!strlen(tmp))
            {
                SendClientMessage(playerid, RED,"USAGE: /goto [playerid]");
                return 1;
            }

    //strval
    otherplayer = strval(tmp);

    //Playerid = Connected
  if(IsPlayerConnected(otherplayer))
        {
            //News
            new interior;
            new othername[MAX_PLAYER_NAME];

            //Gets
            GetPlayerName(otherplayer, othername, sizeof(othername));
            GetPlayerPos(otherplayer, px, py, pz);
            interior = GetPlayerInterior(otherplayer);

            //Sets
            SetPlayerInterior(playerid, interior);
        SetPlayerPos(playerid, px, py, pz+2);

        //Text
        SendClientMessage(playerid, GREEN, "You've been teleported to %s (ID %d)!, othername, otherplayer");
        SendClientMessage(otherplayer, GREEN, "%s (ID %d) has been teleported to you!, name, playerid");

        //Print
            format(string, sizeof(string), "%s (ID %d) is teleported to %s (ID %d). ", name, playerid, othername, otherplayer);
            print(string);
        return 1;
        }
    else
        {
            SendClientMessage(playerid, RED, "That player isn't online!");
        }
return 1;
}
I defined name earlier in the script, and i used the goto only on myself (because there's nobody else on my server).

Do anybody have a idea?
Reply
#2

What crashes? your game/server/pawn?
Reply
#3

Quote:
Originally Posted by MenaceX^
What crashes? your game/server/pawn?
Ow, sorry. I mean it crash ingame. The pawn compiler gives no error, but if i teleport to my own, the server crashes. SA stays on.

This is what happens:
I type /goto 0, i see meself teleport, but no messages and the server crashes before i touch the ground.
Reply
#4

Uhm, seriously, that's the problem I think, because you can't "goto" yourself. That's kinda like trying to add nitro to bikes or dividing by 0.

Edit: Maybe it's also because of your pz+2, try something like py+10 pz+10 instead.
Reply
#5

Quote:
Originally Posted by Torekk
Uhm, seriously, that's the problem I think, because you can't "goto" yourself. That's kinda like trying to add nitro to bikes or dividing by 0.
But i have earlier teleported to myself, and it works :S

But i shall test it on someone else, and make a security to not teleport to yourself.
Reply
#6

Dude, a guy I was telling about this found your problem. You added a " in the wrong place:
pawn Код:
SendClientMessage(otherplayer, GREEN, "%s (ID %d) has been teleported to you!, name, playerid");
but it should look like this:
pawn Код:
SendClientMessage(otherplayer, GREEN, "%s (ID %d) has been teleported to you!", name, playerid);
Edit: [16:09] JayFoxRox: credits to JayFoxRox please

Edit2: Also you need to format a string and then add it to SendClientMessage, don't ask me how you would do that, never did it myself yet. :X

Edit3: Well, forget my "solution". :/
Reply
#7

EDIT:
Ow is see. TNX
I was forgotten the name, playerid after the message

And your thing was also a error, tnx

EDIT 2:
I got warnings now, no errors. On the rules
pawn Код:
SendClientMessage(playerid, GREEN, "You've been teleported to %s (ID %d)!", othername, otherplayer);
        SendClientMessage(otherplayer, GREEN, "%s (ID %d) has been teleported to you!, name, playerid", name, playerid);
I get the 4 warnings, 2 on both rules:
Warning 202, number of arguments does not match definition.
Reply
#8

You forgot to format the messages.

Код:
new string[256];
format(string, 256, "You've been teleported to %s (ID %d)!", othername, otherplayer);
SendClientMessage(playerid, GREEN, string);
format(string, 256, "%s (ID %d) has been teleported to you!", name, playerid);
SendClientMessage(otherplayer, GREEN, string);
Reply
#9

Quote:
Originally Posted by [MOB
Tr1viUm ]
You forgot to format the messages.

Код:
new string[256];
format(string, 256, "You've been teleported to %s (ID %d)!", othername, otherplayer);
SendClientMessage(playerid, GREEN, string);
format(string, 256, "%s (ID %d) has been teleported to you!", name, playerid);
SendClientMessage(otherplayer, GREEN, string);
TNX to all, my /goto works now perfectly
Reply
#10

No problem mate.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)