CMD:Agl issue
#1

Hey People,

Just noticed this command doesn't work, but I don't see an issue?

pawn Код:
CMD:agl(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        if (PlayerInfo[playerid][pAdmin] >= 2)
        {
            new string[256], giveplayerid, x_nr[24];
            if(sscanf(params, "s[60]", x_nr))
            {
                SCM(playerid, COLOR_WHITE, "USAGE: /agl [name] [playerid/PartOfName]");
                SCM(playerid, COLOR_WHITE, "Available names: Driving, Flying, Sailing, Fishing, Weapon.");
                return 1;
            }
            if(strcmp(x_nr,"flying",true) == 0)
            {
                if(sscanf(params, "u", giveplayerid))
                {
                    SCM(playerid, COLOR_WHITE, "USAGE: /agl Flying [playerid/PartOfName]");
                    return 1;
                }
                if(IsPlayerConnected(giveplayerid))
                {
                    if(giveplayerid != INVALID_PLAYER_ID)
                    {
                        if(PlayerInfo[giveplayerid][pPassport] == 1)
                        {
                            format(string, sizeof(string), "* You've given a Flying License to %s (%d).",GetPlayerNameEx(giveplayerid), giveplayerid);
                            SCM(playerid, COLOR_LIGHTBLUE, string);
                            format(string, sizeof(string), "* %s has given you a Flying License.",GetPlayerNameEx(playerid));
                            SCM(giveplayerid, COLOR_LIGHTBLUE, string);
                            PlayerInfo[giveplayerid][pFlyLic] = 1;
                            format(string, sizeof(string), "AdmCmd: %s Has Given a Flying License to %s (%d).",GetPlayerNameEx(playerid) ,GetPlayerNameEx(giveplayerid), giveplayerid);
                            ABroadCast(COLOR_LIGHTRED, string, 5);
                            return 1;
                        }
                        else
                        {
                            SCM(playerid, COLOR_GREY, "   That player doesn't has a passport!");
                            return 1;
                        }
                    }
                }
                else
                {
                    SCM(playerid, COLOR_GREY, "   That player is Offline!");
                    return 1;
                }
            }
            else if(strcmp(x_nr,"sailing",true) == 0)
            {
                if(sscanf(params, "u", giveplayerid))
                {
                    SCM(playerid, COLOR_WHITE, "USAGE: /agl sailinglicense [playerid/PartOfName]");
                    return 1;
                }
                if(IsPlayerConnected(giveplayerid))
                {
                    if(giveplayerid != INVALID_PLAYER_ID)
                    {
                        format(string, sizeof(string), "* You've given a Sailing License to %s (%d).",GetPlayerNameEx(giveplayerid), giveplayerid);
                        SCM(playerid, COLOR_LIGHTBLUE, string);
                        format(string, sizeof(string), "* Admin %s has given you a Sailing License.",GetPlayerNameEx(playerid));
                        SCM(giveplayerid, COLOR_LIGHTBLUE, string);
                        PlayerInfo[giveplayerid][pBoatLic] = 1;
                        format(string, sizeof(string), "AdmCmd: %s Has Given a Sailing License to %s (%d).",GetPlayerNameEx(playerid) ,GetPlayerNameEx(giveplayerid), giveplayerid);
                        ABroadCast(COLOR_LIGHTRED, string, 5);
                        return 1;
                    }
                }
                else
                {
                    SCM(playerid, COLOR_GREY, "   That player is Offline!");
                    return 1;
                }
            }
            else if(strcmp(x_nr,"driving",true) == 0)
            {
                if(sscanf(params, "u", giveplayerid))
                {
                    SCM(playerid, COLOR_WHITE, "USAGE: /agl Driverslicense [playerid/PartOfName]");
                    return 1;
                }
                if(IsPlayerConnected(giveplayerid))
                {
                    if(giveplayerid != INVALID_PLAYER_ID)
                    {
                        if(PlayerInfo[giveplayerid][pPassport] == 1)
                        {
                            format(string, sizeof(string), "* You've given a Driving License to %s (%d).",GetPlayerNameEx(giveplayerid), giveplayerid);
                            SCM(playerid, COLOR_LIGHTBLUE, string);
                            format(string, sizeof(string), "* Admin %s has given you a Driving License.",GetPlayerNameEx(playerid));
                            SCM(giveplayerid, COLOR_LIGHTBLUE, string);
                            PlayerInfo[giveplayerid][pCarLic] = 1;
                            format(string, sizeof(string), "AdmCmd: %s Has Given a Driving License to %s (%d).",GetPlayerNameEx(playerid) ,GetPlayerNameEx(giveplayerid), giveplayerid);
                            ABroadCast(COLOR_LIGHTRED, string, 5);
                            return 1;
                        }
                        else
                        {
                            SCM(playerid, COLOR_GREY, "This player hasn't a passport!");
                            return 1;
                        }
                    }
                }
                else
                {
                    SCM(playerid, COLOR_GREY, "   That player is Offline !");
                    return 1;
                }
            }
            else if(strcmp(x_nr,"fishing",true) == 0)
            {
                if(sscanf(params, "u", giveplayerid))
                {
                    SCM(playerid, COLOR_WHITE, "USAGE: /agl fishinglicense [playerid/PartOfName]");
                    return 1;
                }
                if(IsPlayerConnected(giveplayerid))
                {
                    if(giveplayerid != INVALID_PLAYER_ID)
                    {
                        format(string, sizeof(string), "* You've given a Fishing License to %s (%d).",GetPlayerNameEx(giveplayerid), giveplayerid);
                        SCM(playerid, COLOR_LIGHTBLUE, string);
                        format(string, sizeof(string), "* Admin %s has given you a Fishing License.",GetPlayerNameEx(playerid));
                        SCM(giveplayerid, COLOR_LIGHTBLUE, string);
                        PlayerInfo[giveplayerid][pFishLic] = 1;
                        format(string, sizeof(string), "AdmCmd: %s Has Given a Fishing License to %s (%d).",GetPlayerNameEx(playerid) ,GetPlayerNameEx(giveplayerid), giveplayerid);
                        ABroadCast(COLOR_LIGHTRED, string, 5);
                        return 1;
                    }
                }
                else
                {
                    SCM(playerid, COLOR_GREY, "   That player is Offline!");
                    return 1;
                }
            }
            else if(strcmp(x_nr,"weapon",true) == 0)
            {
                if(sscanf(params, "u", giveplayerid))
                {
                    SCM(playerid, COLOR_WHITE, "USAGE: /agl weaponlicense [playerid/PartOfName]");
                    return 1;
                }
                if(IsPlayerConnected(giveplayerid))
                {
                    if(giveplayerid != INVALID_PLAYER_ID)
                    {
                        format(string, sizeof(string), "* You've given a Weapon License to %s (%d).",GetPlayerNameEx(giveplayerid), giveplayerid);
                        SCM(playerid, COLOR_LIGHTBLUE, string);
                        format(string, sizeof(string), "* Admin %s has given you a Weapon License.",GetPlayerNameEx(playerid));
                        SCM(giveplayerid, COLOR_LIGHTBLUE, string);
                        PlayerInfo[giveplayerid][pGunLic] = 1;
                        format(string, sizeof(string), "AdmCmd: %s Has Given a Weapon License to %s (%d).",GetPlayerNameEx(playerid) ,GetPlayerNameEx(giveplayerid), giveplayerid);
                        ABroadCast(COLOR_LIGHTRED, string, 5);
                        return 1;
                    }
                }
                else
                {
                    SCM(playerid, COLOR_GREY, "   That player is Offline!");
                    return 1;
                }
            }
        }
        else
        {
            SCM(playerid, COLOR_GREY, "   You are not authorised to use this command!");
            return 1;
        }
    }
    return 1;
}
Does the X_NR need to classed as params? and then "u", on sscanf, and ignore the x_nr?
Reply
#2

You want.... sscanf(params, "s[60]u", x_nr, giveplayerid);

also....

if(IsPlayerConnected(playerid))
{

Obviously the player is connected if they typed the command
Reply
#3

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
You want.... sscanf(params, "s[60]u", x_nr, giveplayerid);

also....

if(IsPlayerConnected(playerid))
{

Obviously the player is connected if they typed the command
On just that one line of code?

pawn Код:
if(sscanf(params, "s[60]", x_nr))
At the top, of every other one too?
Reply
#4

You mixed the hell out of zCMD(or whatever you are using, y_cmd and stuff) with reguler command input.
You need to replace those (strcmp(x_nr, ..) == 0) with it, just learn about sscanf how to make it. sscanf has a guide about it.

@[uL]Pottus
Just uhm, to note out. The thing about "if(IsPlayerConnected(playerid))" as I quote from samp wiki:
Quote:

This function can be used to check if a player is connected to the server via SA:MP.

This will know if the player that is currently executing the command is actually connecting from SA:MP and not just a random packet sender(bot). Tho this is a complete failure when player connects cause it only sets player connection after OnPlayerConnect(playerid) executes. So 'IsPlayerConnected' won't work before or inside OnPlayerConnect. Afterwards it should work perfectly.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)