SA-MP Forums Archive
Problem with a... variable? /goto command - 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)
+--- Thread: Problem with a... variable? /goto command (/showthread.php?tid=660828)



Problem with a... variable? /goto command - dabv_astur - 14.11.2018

Hi everyone, again me. This error seems to be very basic, but I do not understand what happens and I have the crazy head.

That's is my code:

pawn Code:
CMD:ir(playerid, params[])
{
    new idJugador;
    new Float:xJugador, Float:yJugador, Float:zJugador;
    new StringMen[64];
    if(pInfo[playerid][Admin] >= 1)
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
              new vehiculo = GetPlayerVehicleID(playerid);
              new seat = GetPlayerVehicleSeat(playerid);
              GetPlayerPos(idJugador, xJugador, yJugador, zJugador);
              SetPlayerPos(playerid, xJugador, yJugador+2, zJugador);
              SetVehiclePos(vehiculo, xJugador, yJugador+2, zJugador);
              PutPlayerInVehicle(playerid, vehiculo, seat);
         }
         else
         {
            GetPlayerPos(idJugador, xJugador, yJugador, zJugador);
            SetPlayerPos(playerid, xJugador+1, yJugador+1, zJugador);
           
            format(StringMen, sizeof StringMen, "[IR] %s fue a %s", pInfo[playerid][Name], pInfo[idJugador][Name]);
            SendClientMessage(playerid, COLOR_RED, StringMen);
           
         }
    }
    else return SendClientMessage(playerid, COLOR_RED, "No eres staff o no tienes rango suficiente!");
   
    return 1;
}
The problem is when I try teleport with ID 0 to ID 1 I can't and I receive that SendClientMessage:
HTML Code:
[IR] DabvAsturDemo fue a DabvAsturDemo
My main account and also I am trying go to is named DabvAstur

Watch the video so understand me better.
https://youtube.com/watch?v=bdTVIX3_D2M


Re: Problem with a... variable? /goto command - OiLoL - 15.11.2018

new vehiculo = GetPlayerVehicleID(playerid);
new seat = GetPlayerVehicleSeat(playerid);

You are doing wrong?

change it to :
idJugador

new vehiculo = GetPlayerVehicleID(idJugador);
new seat = GetPlayerVehicleSeat(idJugador);

You are getting player's vehicle ID and player's seat and placing the same player in that vehicle xD


Re: Problem with a... variable? /goto command - Rolux - 15.11.2018

Don't listen to that guy.

You are not giving any value to the variable "idJugador",so it's value will be 0.
That causes you to teleport to ID 0.


Re: Problem with a... variable? /goto command - dabv_astur - 15.11.2018

Quote:
Originally Posted by Rolux
View Post
Don't listen to that guy.

You are not giving any value to the variable "idJugador",so it's value will be 0.
That causes you to teleport to ID 0.
Can you please tell me how I do that? With sscanf maybe?


Re: Problem with a... variable? /goto command - BiGuy - 15.11.2018

Quote:
Originally Posted by dabv_astur
View Post
Can you please tell me how I do that? With sscanf maybe?
Yes its easy check the examples https://sampforum.blast.hk/showthread.php?tid=570927


Re: Problem with a... variable? /goto command - dabv_astur - 15.11.2018

Quote:
Originally Posted by BiGuy
View Post
if (sscanf(params, "u", idJugador)) return SendClientMessage(playerid, COLOR_RED, "Usa: /ir IDJUGADOR");

I add this line to my command but the result is same

EDIT:
Ok i change "u" parameter with "d" but with that I can't put the username on the command. Maybe because the variable is an integer and not string?


Re: Problem with a... variable? /goto command - TheToretto - 16.11.2018

d and u are will work the same.

Show your new code.


Re: Problem with a... variable? /goto command - Flofey - 16.11.2018

I don't know.. but it might work _:_ give it a try tho

PHP Code:
CMD:goto(playeridparams[])
{
    new 
idPlayer;
    new 
Float:xPlayerFloat:yPlayerFloat:zPlayer;
    new 
StringMen[64];
    new 
playername[MAX_PLAYER_NAME];
    new 
targetname[MAX_PLAYER_NAME];
    
GetPlayerName(idPlayer,targetname,sizeof(targetname));
    
GetPlayerName(playerid,playername,sizeof(playername));
    if(
Info[playerid][Admin] >= 1)
    {
        if(
sscanf(params,"u",idPlayer)) return SendClientMessage(playerid,-1"/goto [ID]");
        if(!
IsPlayerConnected(idPlayer)) return SendClientMessage(playerid, -1"The ID is wrong or the player isn't online!");
        if(
IsPlayerInAnyVehicle(playerid))
        {
              new 
vehicle GetPlayerVehicleID(playerid);
              new 
seat GetPlayerVehicleSeat(playerid);
              
GetPlayerPos(idPlayerxPlayeryPlayerzPlayer);
              
SetPlayerPos(playeridxPlayeryPlayer+2zPlayer);
              
SetVehiclePos(vehiclexPlayeryPlayer+2zPlayer);
              
PutPlayerInVehicle(playeridvehicleseat);
         }
         else
         {
            
GetPlayerPos(idPlayerxPlayeryPlayerzPlayer);
            
SetPlayerPos(playeridxPlayer+1yPlayer+1zPlayer);

            
format(StringMensizeof StringMen"[GOTO] %s teleported to %s"playernametargetname);
            
SendClientMessage(playerid, -1StringMen);

         }
    }
    else return 
SendClientMessage(playerid, -1"You're not allowed to use this command!");

    return 
1;

PS: sry for using English :P


Re: Problem with a... variable? /goto command - Mencent - 16.11.2018

Quote:
Originally Posted by TheToretto
View Post
d and u are will work the same.
That's wrong. d is only for integers and u is for strings and integers.

_______________________________________-


Try this:
PHP Code:
CMD:ir(playerid,params[])
{
    new 
idJugador,Float:xJugador,Float:yJugador,Float:zJugador,StringMen[64];
    if(
pInfo[playerid][Admin] >= 1)
    {
        if(
sscanf(params,"u",idJugador))return SendClientMessage(playerid,-1,"WARNING: /ir [playerid]");
        if(!
IsPlayerConnected(idJugador))return SendClientMessage(playerid,-1,"playerid doesn't exists");
        if(
IsPlayerInAnyVehicle(playerid))
        {
              new 
vehiculo GetPlayerVehicleID(playerid);
              new 
seat GetPlayerVehicleSeat(playerid);
              
GetPlayerPos(idJugadorxJugadoryJugadorzJugador);
              
SetPlayerPos(playeridxJugadoryJugador+2zJugador);
              
SetVehiclePos(vehiculoxJugadoryJugador+2zJugador);
              
PutPlayerInVehicle(playeridvehiculoseat);
              return 
1;
         }
         else
         {
            
GetPlayerPos(idJugadorxJugadoryJugadorzJugador);
            
SetPlayerPos(playeridxJugador+1yJugador+1zJugador);
            
format(StringMensizeof StringMen"[IR] %s fue a %s"pInfo[playerid][Name], pInfo[idJugador][Name]);
            
SendClientMessage(playeridCOLOR_REDStringMen);
            return 
1;
         }
    }
    else return 
SendClientMessage(playeridCOLOR_RED"No eres staff o no tienes rango suficiente!");




Re: Problem with a... variable? /goto command - Flofey - 17.11.2018

Quote:
Originally Posted by Mencent
View Post
That's wrong. d is only for integers and u is for strings and integers.

_______________________________________-


Try this:
PHP Code:
CMD:ir(playerid,params[])
{
    new 
idJugador,Float:xJugador,Float:yJugador,Float:zJugador,StringMen[64];
    if(
pInfo[playerid][Admin] >= 1)
    {
        if(
sscanf(params,"u",idJugador))return SendClientMessage(playerid,-1,"WARNING: /ir [playerid]");
        if(!
IsPlayerConnected(idJugador))return SendClientMessage(playerid,-1,"playerid doesn't exists");
        if(
IsPlayerInAnyVehicle(playerid))
        {
              new 
vehiculo GetPlayerVehicleID(playerid);
              new 
seat GetPlayerVehicleSeat(playerid);
              
GetPlayerPos(idJugadorxJugadoryJugadorzJugador);
              
SetPlayerPos(playeridxJugadoryJugador+2zJugador);
              
SetVehiclePos(vehiculoxJugadoryJugador+2zJugador);
              
PutPlayerInVehicle(playeridvehiculoseat);
              return 
1;
         }
         else
         {
            
GetPlayerPos(idJugadorxJugadoryJugadorzJugador);
            
SetPlayerPos(playeridxJugador+1yJugador+1zJugador);
            
format(StringMensizeof StringMen"[IR] %s fue a %s"pInfo[playerid][Name], pInfo[idJugador][Name]);
            
SendClientMessage(playeridCOLOR_REDStringMen);
            return 
1;
         }
    }
    else return 
SendClientMessage(playeridCOLOR_RED"No eres staff o no tienes rango suficiente!");

Excuse me Mencent, isn't what you did is the same as I did but in a different language :/


Re: Problem with a... variable? /goto command - Mencent - 17.11.2018

Quote:
Originally Posted by Flofey
View Post
Excuse me Mencent, isn't what you did is the same as I did but in a different language :/
Sorry, my mistake. Next time I will look better.


Re: Problem with a... variable? /goto command - CantBeJohn - 17.11.2018

Quote:
Originally Posted by Mencent
View Post
That's wrong. d is only for integers and u is for strings and integers. [/PHP]
Just to clarify, that's not right either and sounds misleading. "u" is explicitly for Usernames/IDs.


Re: Problem with a... variable? /goto command - Joe Staff - 17.11.2018

Quote:
Originally Posted by Flofey
View Post
Excuse me Mencent, isn't what you did is the same as I did but in a different language :/
Not quite, you were trying to use GetPlayerName before ever collecting the ID of the player from the parameter, but then you never actually used the players' names anyway.


Re: Problem with a... variable? /goto command - Mencent - 17.11.2018

Quote:
Originally Posted by CantBeJohn
View Post
Just to clarify, that's not right either and sounds misleading. "u" is explicitly for Usernames/IDs.
Well I mean the right but write the wrong. Sorry and thanks for your correction!


Re: Problem with a... variable? /goto command - Flofey - 17.11.2018

Quote:
Originally Posted by Joe Staff
View Post
Not quite, you were trying to use GetPlayerName before ever collecting the ID of the player from the parameter, but then you never actually used the players' names anyway.
Code:
format(StringMen, sizeof StringMen, "[GOTO] %s teleported to %s", playername,targetname);
and what do you call these?


Re: Problem with a... variable? /goto command - TheToretto - 17.11.2018

Use GetPlayerName after the sscanf


Re: Problem with a... variable? /goto command - Flofey - 18.11.2018

Thanks for correcting me.


PHP Code:
CMD:goto(playeridparams[])
{

    new 
idPlayer,Float:xPlayerFloat:yPlayerFloat:zPlayerStringMen[64], playername[MAX_PLAYER_NAME], targetname[MAX_PLAYER_NAME];
    if(
IsPlayerAdmin(playerid))
    {
        if(
sscanf(params,"u",idPlayer)) return SendClientMessage(playerid,-1"/goto [ID]");
        if(!
IsPlayerConnected(idPlayer)) return SendClientMessage(playerid, -1"The ID is wrong or the player isn't online!");
        if(
IsPlayerInAnyVehicle(playerid))
        {
              new 
vehicle GetPlayerVehicleID(playerid);
              new 
seat GetPlayerVehicleSeat(playerid);
              
GetPlayerPos(idPlayerxPlayeryPlayerzPlayer);
              
SetVehiclePos(vehiclexPlayeryPlayer+2zPlayer);
              
PutPlayerInVehicle(playeridvehicleseat);
              
GetPlayerName(idPlayer,targetname,sizeof(targetname));
              
GetPlayerName(playerid,playername,sizeof(playername));
              
format(StringMensizeof StringMen"[GOTO] %s teleported to %s"playernametargetname);
              
SendClientMessage(playerid, -1StringMen);
         }
         else
         {
            
GetPlayerPos(idPlayerxPlayeryPlayerzPlayer);
            
SetPlayerPos(playeridxPlayer+1yPlayer+1zPlayer);

            
GetPlayerName(idPlayer,targetname,sizeof(targetname));
            
GetPlayerName(playerid,playername,sizeof(playername));
            
format(StringMensizeof StringMen"[GOTO] %s teleported to %s"playernametargetname);
            
SendClientMessage(playerid, -1StringMen);

         }
    }
    else return 
SendClientMessage(playerid, -1"You're not allowed to use this command!");

    return 
1;