[HELP] Goto Command
#1

So i have here a go command... But after compiling i have this error error 017: undefined symbol "id" i highlight it to make clear.

PHP код:
CMD:go(playeridparams[])
{
    new 
ID;//creates a new something idk what we call it :P but it is defined later on or used in something this 1 is used in next line
    
if(sscanf(params"u"ID)) SendClientMessage(playerid0xFF0000FF"USAGE: /goto [id]");//checks if you have written something after /goto if no it sends error
    
else if(!IsPlayerConnected(id) || id == playerid) return SendClientMessage(playerid0xFF0000FF"This player is offline or it is yourself"); <--------------This is the error line.
    else
//ELSE what will happen if no errors
    
{
    new 
Float:xFloat:yFloat:z;//creates new floats
    
GetPlayerPos(IDxyz);//gets the player id(which we have entered after /goto position and like saves them into x,y,z defined above as floats
    
SetPlayerPos(playeridx+1y+1z);//sets the player position the id of that player +1 in x +1 in y and z remains same as it defines height
    
}
    return 
1;

EDIT: If player disbled his /goff command. if someone try to go to him it will say

GameTextForPlayer(playerid,"Playername Go is disabled",2000,3);
Reply
#2

wait so whats highlighted the red
Reply
#3

Quote:
Originally Posted by [A]ndrei
Посмотреть сообщение
wait so whats highlighted the red
Sorry the bold is not working in PHP. I wrote it down. just drag the bar to the right.
Reply
#4

Fixed

pawn Код:
CMD:go(playerid, params[])
{
    new ID;//creates a new something idk what we call it :P but it is defined later on or used in something this 1 is used in next line
    if(sscanf(params, "u", ID)) SendClientMessage(playerid, 0xFF0000FF, "USAGE: /goto [id]");//checks if you have written something after /goto if no it sends error
    else if(!IsPlayerConnected(ID) || ID == playerid) return SendClientMessage(playerid, 0xFF0000FF, "This player is offline or it is yourself"); <--------------This is the error line.
    else//ELSE what will happen if no errors
    {
        new Float:x, Float:y, Float:z;//creates new floats
        GetPlayerPos(ID, x, y, z);//gets the player id(which we have entered after /goto position and like saves them into x,y,z defined above as floats
        SetPlayerPos(playerid, x+1, y+1, z);//sets the player position the id of that player +1 in x +1 in y and z remains same as it defines height
    }
    return 1;
}
Variables are case-sensitive, the error was because it was lowercased.

Make a global variable or a Boolean, and then set it to true or 1 when the player connects. Then, when they do /goff, set it to 0. Then, on the command, check if the Boolean or global variable is value 0 for the playerid, and if it is, you can't teleport to them.

EDIT: TIP: Use [.pawn] and [./pawn] tags instead of the current ones you are using in the future (without the period, of course).
Reply
#5

Quote:
Originally Posted by Kindred
Посмотреть сообщение
Fixed

pawn Код:
CMD:go(playerid, params[])
{
    new ID;//creates a new something idk what we call it :P but it is defined later on or used in something this 1 is used in next line
    if(sscanf(params, "u", ID)) SendClientMessage(playerid, 0xFF0000FF, "USAGE: /goto [id]");//checks if you have written something after /goto if no it sends error
    else if(!IsPlayerConnected(ID) || ID == playerid) return SendClientMessage(playerid, 0xFF0000FF, "This player is offline or it is yourself"); <--------------This is the error line.
    else//ELSE what will happen if no errors
    {
        new Float:x, Float:y, Float:z;//creates new floats
        GetPlayerPos(ID, x, y, z);//gets the player id(which we have entered after /goto position and like saves them into x,y,z defined above as floats
        SetPlayerPos(playerid, x+1, y+1, z);//sets the player position the id of that player +1 in x +1 in y and z remains same as it defines height
    }
    return 1;
}
Variables are case-sensitive, the error was because it was lowercased.

Make a global variable or a Boolean, and then set it to true or 1 when the player connects. Then, when they do /goff, set it to 0. Then, on the command, check if the Boolean or global variable is value 0 for the playerid, and if it is, you can't teleport to them.

EDIT: TIP: Use [.pawn] and [./pawn] tags instead of the current ones you are using in the future (without the period, of course).
Man thanks its working, Can you add this?

EDIT: If player use /goff he can toggle his go to off and on.


Example /goff - Go Enabled /goff - Go Disabled

If player disabled his /go. the player who try to go to him will show this on screen.
GameTextForPlayer(playerid,"Playername Go is disabled",2000,3);
Reply
#6

Try something like this:

pawn Код:
new GotoDisabled[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    GotoDisabled[playerid] = 0;
    //Rest of code for OnPlayerConnect
    return 1;
}

CMD:goff(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        if(GotoDisabled[playerid] == 1) return GotoDisabled[playerid] = 0;
        else return GotoDisabled[playerid] = 0;
    }
    return 1;
}

CMD:go(playerid, params[])
{
    new ID;//creates a new something idk what we call it :P but it is defined later on or used in something this 1 is used in next line
    if(sscanf(params, "u", ID)) SendClientMessage(playerid, 0xFF0000FF, "USAGE: /goto [id]");//checks if you have written something after /goto if no it sends error
    else if(!IsPlayerConnected(ID) || ID == playerid) return SendClientMessage(playerid, 0xFF0000FF, "This player is offline or it is yourself"); <--------------This is the error line.
    if(GotoDisabled[ID] == 1)
    {
        new string[50], name[MAX_PLAYER_NAME];
        format(string, sizeof(string), "%s's goto is disabled!", GetPlayerName(playerid, name, sizeof(name)));
        GameTextForPlayer(playerid,string,2000,3);
        return 1;
    }
    else//ELSE what will happen if no errors
    {
        new Float:x, Float:y, Float:z;//creates new floats
        GetPlayerPos(ID, x, y, z);//gets the player id(which we have entered after /goto position and like saves them into x,y,z defined above as floats
        SetPlayerPos(playerid, x+1, y+1, z);//sets the player position the id of that player +1 in x +1 in y and z remains same as it defines height
    }
    return 1;
}
Should work with no errors.

Hope I helped.
Reply
#7

Quote:
Originally Posted by Kindred
Посмотреть сообщение
Try something like this:

pawn Код:
new GotoDisabled[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    GotoDisabled[playerid] = 0;
    //Rest of code for OnPlayerConnect
    return 1;
}

CMD:goff(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        if(GotoDisabled[playerid] == 1) return GotoDisabled[playerid] = 0;
        else return GotoDisabled[playerid] = 0;
    }
    return 1;
}

CMD:go(playerid, params[])
{
    new ID;//creates a new something idk what we call it :P but it is defined later on or used in something this 1 is used in next line
    if(sscanf(params, "u", ID)) SendClientMessage(playerid, 0xFF0000FF, "USAGE: /goto [id]");//checks if you have written something after /goto if no it sends error
    else if(!IsPlayerConnected(ID) || ID == playerid) return SendClientMessage(playerid, 0xFF0000FF, "This player is offline or it is yourself"); <--------------This is the error line.
    if(GotoDisabled[ID] == 1)
    {
        new string[50], name[MAX_PLAYER_NAME];
        format(string, sizeof(string), "%s's goto is disabled!", GetPlayerName(playerid, name, sizeof(name)));
        GameTextForPlayer(playerid,string,2000,3);
        return 1;
    }
    else//ELSE what will happen if no errors
    {
        new Float:x, Float:y, Float:z;//creates new floats
        GetPlayerPos(ID, x, y, z);//gets the player id(which we have entered after /goto position and like saves them into x,y,z defined above as floats
        SetPlayerPos(playerid, x+1, y+1, z);//sets the player position the id of that player +1 in x +1 in y and z remains same as it defines height
    }
    return 1;
}
Should work with no errors.

Hope I helped.
Dude, no error. But if i use /go it teleports me to my position. Also if i type /goff a gametextforplayer will also show to my screen like this GameTextForPlayer(playerid,"~b~You have ~r~disabled ~b~go",2000,3);
Reply
#8

Try now

pawn Код:
new GotoDisabled[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    GotoDisabled[playerid] = 0;
    //Rest of code for OnPlayerConnect
    return 1;
}

CMD:goff(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        if(GotoDisabled[playerid] == 1)
        {
            GotoDisabled[playerid] = 0;
            GameTextForPlayer(playerid,"~b~You have ~r~enabled ~b~go",2000,3);
            return 1;
        }
        else
        {
            GotoDisabled[playerid] = 1;
            GameTextForPlayer(playerid,"~b~You have ~r~disabled ~b~go",2000,3);
            return 1;
        }
    }
    return 1;
}

CMD:go(playerid, params[])
{
    new ID;//creates a new something idk what we call it :P but it is defined later on or used in something this 1 is used in next line
    if(sscanf(params, "u", ID)) return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /goto [id]");//checks if you have written something after /goto if no it sends error
    else if(!IsPlayerConnected(ID) || ID == playerid) return SendClientMessage(playerid, 0xFF0000FF, "This player is offline or it is yourself"); <--------------This is the error line.
    if(GotoDisabled[ID] == 1)
    {
        new string[50], name[MAX_PLAYER_NAME];
        format(string, sizeof(string), "%s's goto is disabled!", GetPlayerName(playerid, name, sizeof(name)));
        GameTextForPlayer(playerid,string,2000,3);
        return 1;
    }
    else//ELSE what will happen if no errors
    {
        new Float:x, Float:y, Float:z;//creates new floats
        GetPlayerPos(ID, x, y, z);//gets the player id(which we have entered after /goto position and like saves them into x,y,z defined above as floats
        SetPlayerPos(playerid, x+1, y+1, z);//sets the player position the id of that player +1 in x +1 in y and z remains same as it defines height
    }
    return 1;
}
Reply
#9

Quote:
Originally Posted by Kindred
Посмотреть сообщение
Try now

pawn Код:
new GotoDisabled[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    GotoDisabled[playerid] = 0;
    //Rest of code for OnPlayerConnect
    return 1;
}

CMD:goff(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        if(GotoDisabled[playerid] == 1)
        {
            GotoDisabled[playerid] = 0;
            GameTextForPlayer(playerid,"~b~You have ~r~enabled ~b~go",2000,3);
            return 1;
        }
        else
        {
            GotoDisabled[playerid] = 1;
            GameTextForPlayer(playerid,"~b~You have ~r~disabled ~b~go",2000,3);
            return 1;
        }
    }
    return 1;
}

CMD:go(playerid, params[])
{
    new ID;//creates a new something idk what we call it :P but it is defined later on or used in something this 1 is used in next line
    if(sscanf(params, "u", ID)) return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /goto [id]");//checks if you have written something after /goto if no it sends error
    else if(!IsPlayerConnected(ID) || ID == playerid) return SendClientMessage(playerid, 0xFF0000FF, "This player is offline or it is yourself"); <--------------This is the error line.
    if(GotoDisabled[ID] == 1)
    {
        new string[50], name[MAX_PLAYER_NAME];
        format(string, sizeof(string), "%s's goto is disabled!", GetPlayerName(playerid, name, sizeof(name)));
        GameTextForPlayer(playerid,string,2000,3);
        return 1;
    }
    else//ELSE what will happen if no errors
    {
        new Float:x, Float:y, Float:z;//creates new floats
        GetPlayerPos(ID, x, y, z);//gets the player id(which we have entered after /goto position and like saves them into x,y,z defined above as floats
        SetPlayerPos(playerid, x+1, y+1, z);//sets the player position the id of that player +1 in x +1 in y and z remains same as it defines height
    }
    return 1;
}
Man you just rock my server! hahaha. tons of thanks You help me alot! Just a simple request. how about if i add [id/Partofname]? is that possible?
Reply
#10

Quote:
Originally Posted by kbalor
Посмотреть сообщение
Man you just rock my server! hahaha. tons of thanks You help me alot! Just a simple request. how about if i add [id/Partofname]? is that possible?
if(sscanf(params, "u", ID)) return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /goto [id][Name]");

Код:
Specifier(s)			Name				Example values
	i, d			Integer				1, 42, -10
	c			Character			a, o, *
	l			Logical				true, false
	b			Binary				01001, 0b1100
	h, x			Hex				1A, 0x23
	o			Octal				045 12
	n			Number				42, 0b010, 0xAC, 045
	f			Float				0.7, -99.5
	g			IEEE Float			0.7, -99.5, INFINITY, -INFINITY, NAN, NAN_E
	u			User name/id (bots and players)	******, 0
	q			Bot name/id			ShopBot, 27
	r			Player name/id			******, 42
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)