Authority
#1

I started using zcmd and the other feature forgot the name, I came up with this:
Now, I just want to ask, what is the problem with my code ? every player can use it, while not being an admin, even though I defined everything.
pawn Код:
CMD:goto(playerid, params[])
{
if (PlayerInfo[playerid][pAdmin] >= 1){return SendClientMessage(playerid, 0xFF4646FF, "You are not authorized to use that command !");

}else
{
new pID;

  new otherId;


  new string[256];



if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, COLOR_RED, "* Invalid player ID!");
    {
     if(sscanf(params, "rii", otherId)) return SendClientMessage(playerid, 0xAFAFAFAA, "Usage: /goto [PlayerID/PartOfName]");
  format(string, sizeof(string), "* You have successfully teleported your self",playerid);
  SendClientMessage(playerid, COLOR_LIGHTRED, string);


    new Float:x, Float:y, Float:z;
    GetPlayerPos(otherId, x, y, z);
    SetPlayerPos(playerid, x+1, y, z);






}

        }
    return 1;
}
Reply
#2

How can you honestly be so clueless?

pawn Код:
if (PlayerInfo[playerid][pAdmin] >= 1){return SendClientMessage(playerid, 0xFF4646FF, "You are not authorized to use that command !");
You're checking if they ARE an admin and THEN not letting them use the command.

Although you're new to zcmd/sscanf, common sense still should apply.

pawn Код:
if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, COLOR_RED, "* Invalid player ID!");
You're checking if the user is(n't) connected before you've parsed a value to the variable, therefore the ID is constantly 0 and the command is only going to work for ID 0. Plus, the variable you want to use is 'otherID' I assume.

pawn Код:
new string[256];
Why?! You're not even using 64 cells in the format function...

pawn Код:
if(sscanf(params, "rii", otherId))
Use 'u', not 'r'.. You only have one parameter, what's with the triple usage of 'i'?
Reply
#3

First of all: What the hell?!? Why did you make the indentation so hard to understand??

Here is the code in understandable format, look where I put the question marks and tell me what that's all about?
pawn Код:
CMD:goto(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] >= 1) // Wrong way :)
    {
        return SendClientMessage(playerid, 0xFF4646FF, "You are not authorized to use that command !");
    }
    else
    {
        new pID,
            otherId,
            string[256];
        if(!IsPlayerConnected(pID))
            return SendClientMessage(playerid, COLOR_RED, "* Invalid player ID!");
        { // ???????
             if(sscanf(params, "rii", otherId)) // Missing two parimeters (Two integers)
                 return SendClientMessage(playerid, 0xAFAFAFAA, "Usage: /goto [PlayerID/PartOfName]");
              format(string, sizeof(string), "* You have successfully teleported your self",playerid);
              SendClientMessage(playerid, COLOR_LIGHTRED, string);
            new Float:x, Float:y, Float:z;
            GetPlayerPos(otherId, x, y, z);
            SetPlayerPos(playerid, x+1, y, z);
        } // ???????
    }
    return 1;
}
Reply
#4

Oh, something else to add.

pawn Код:
CMD:goto(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] >= 1) // Wrong way :)
    {
        return SendClientMessage(playerid, 0xFF4646FF, "You are not authorized to use that command !");
    }
    else
    {
        new pID,
            otherId,
            string[256];
        if(!IsPlayerConnected(pID))
            return SendClientMessage(playerid, COLOR_RED, "* Invalid player ID!");
        { // ???????
             if(sscanf(params, "rii", otherId)) // Useless parameter? lol
                 return SendClientMessage(playerid, 0xAFAFAFAA, "Usage: /goto [PlayerID/PartOfName]");
              format(string, sizeof(string), "* You have successfully teleported your self",playerid);
              SendClientMessage(playerid, COLOR_LIGHTRED, string);
            new Float:x, Float:y, Float:z;
            GetPlayerPos(otherId, x, y, z);
            SetPlayerPos(playerid, x+1, y, z);
        } // ???????
    }
    return 1;
}
Reply
#5

Oh, and don't use 256 as string lenght.

In fact, why do you even have it?!
Look at this:
pawn Код:
format(string, sizeof(string), "* You have successfully teleported your self",playerid);
?? What is the point
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)