SA-MP Forums Archive
Problem with the 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problem with the command (/showthread.php?tid=125395)



Problem with the command - MrLeNy - 03.02.2010

Hello. I have a problem with the command, because when I entered / sgang Invite this shows me that this player does not have
Here's the code commands:
Код:
dcmd_sgang(playerid,cmdtext[])
{
new giveplayerid, string[128];
if(!strlen(cmdtext))
{
SendClientMessage(playerid, COLOR_WHITE, "*Wpisz: /sgang [invite/uninvite/pos/gate]");
return 1;
}
//Zaproszenie
if(!strcmp(cmdtext, "invite", true))
{
if(PlayerInfo[playerid][Leader] >= 0)
{
if(sscanf(cmdtext, "u", giveplayerid))SendClientMessage(playerid, COLOR_WHITE, "*Wpisz: /sgang zapros [id_gracza]");
else if(giveplayerid == INVALID_PLAYER_ID)SendClientMessage(playerid, COLOR_RED, "BŁĄD: Gracza o danym ID nie ma!");
else if(!dini_Exists(udb_encode(PlayerName(giveplayerid))))SendClientMessage(playerid, COLOR_RED, "BŁĄD: Gracz o danym ID nie ma konta!");
else{
format(string,sizeof(string),"Zostałeś/aś przyjęty/a do gangu: %s przez Lidera: %s",Team[PlayerInfo[playerid][Leader]][Name],PlayerName(playerid));
SendClientMessage(giveplayerid, COLOR_YELLOW, string);
dini_IntSet(udb_encode(PlayerName(giveplayerid)), "PlayerTeam",PlayerInfo[playerid][Leader]);
}
}else SendClientMessage(playerid, COLOR_RED, "*BŁĄD: Nie jesteś liderem gangu/mafii!");
return 1;
}
//Wyrzucanie
if(!strcmp(cmdtext, "uninvite", true))
{
if(PlayerInfo[playerid][Leader] >=0)
{
if(sscanf(cmdtext, "u", giveplayerid))SendClientMessage(playerid, COLOR_WHITE, "*Wpisz: /sgang zapros [id_gracza]");
else if(giveplayerid == INVALID_PLAYER_ID)SendClientMessage(playerid, COLOR_RED, "BŁĄD: Gracza o danym ID nie ma!");
else{
format(string,sizeof(string),"Zostałeś/aś wyrzucony/a z gangu: %s przez Lidera: %s",Team[PlayerInfo[playerid][Leader]][Name],PlayerName(playerid));
SendClientMessage(giveplayerid, COLOR_YELLOW, string);
dini_IntSet(udb_encode(PlayerName(giveplayerid)), "PlayerTeam",0);
}
}else SendClientMessage(playerid, COLOR_RED, "*BŁĄD: Nie jesteś liderem gangu/mafii!");
return 1;
}
//teleport
if(!strcmp(cmdtext, "pos", true))
{
if(PlayerInfo[playerid][PlayerGang] != 0)
{
for(new Gangid = 0; Gangid < MAX_GANGS; Gangid++)
{
if(PlayerInfo[playerid][PlayerGang] == Gangid)
{
SetPlayerPos(playerid,Team[Gangid][Spawn][0],Team[Gangid][Spawn][1],Team[Gangid][Spawn][2]);
SetPlayerFacingAngle(playerid, Team[Gangid][Spawn][3]);
}
}
}else SendClientMessage(playerid, COLOR_RED, "*BŁĄD: Nie należysz do żadnego gangu/mafii");
return 1;
}
//Bramy
if(!strcmp(cmdtext, "gate", true))
{
return 1;
}
return 1;
}
Please help


Re: Problem with the command - MrLeNy - 03.02.2010

please help me


Re: Problem with the command - mansonh - 04.02.2010

Quote:

b) Do not bump
Some people apparently think they are important enough to bump their own topic after 10 minutes.
You can bump topics when the last reply is at least 12 hours old.

You do if(!strcmp(cmdtext, "invite", true))
then you try to use it
if(sscanf(cmdtext, "u", giveplayerid))

If the strcmp passed then cmdtext can only be "invite"
so it will never pass the sscanf

if the cmdtext is "invite 8" it will fail the strcmp and never get to sscanf,

So instead start with sscanf
ex new txt[28];
if(sscanf(cmdtext, "su", txt, giveplayerid))
if(!strcmp(txt, "invite", true))

You use this again later on. It looks like you are trying to mix strcmp system with dcmd.
Might want to pick one and stick with it.


Re: Problem with the command - MrLeNy - 04.02.2010

I do not know how to do this dcmd functions with /cmd cmd cmd
You help?


Re: Problem with the command - mansonh - 04.02.2010

Oh, I get it
you want commands like
/sgang invite <player>
/sgang uninvite <player>
...
I thought you wanted
/invite
/uninvite

give me a sec i will fix up your code


Re: Problem with the command - mansonh - 04.02.2010


Your issue was that you were doing strcmp on the entire command:

ex. "/sgang invite bob" -> "invite bob"
then you were doing strcmp ... "invite bob" with "invite" which of course wouldn't match.

So you have two ways to deal with this:


The first simply takes the invite, uninvite ... out of cmdtext first for comparison
pawn Код:
dcmd_sgang(playerid,cmdtext[])
{
new giveplayerid, string[128];
    if(!strlen(cmdtext))
    {
    SendClientMessage(playerid, COLOR_WHITE, "*Wpisz: /sgang [invite/uninvite/pos/gate]");
    return 1;
    }
    //we need to take out the "invite" out of "invite player" then compare the "invite"
    new idx, cmd[24];
    cmd = strtok(cmdtext, idx);

    //Zaproszenie
    if(!strcmp(cmd, "invite", true))
    {
        if(PlayerInfo[playerid][Leader] >= 0)
        {
            if(sscanf(cmdtext, "u", giveplayerid))SendClientMessage(playerid, COLOR_WHITE, "*Wpisz: /sgang zapros [id_gracza]");
            else if(giveplayerid == INVALID_PLAYER_ID)SendClientMessage(playerid, COLOR_RED, "BLAD: Gracza o danym ID nie ma!");
            else if(!dini_Exists(udb_encode(PlayerName(giveplayerid))))SendClientMessage(playerid, COLOR_RED, "BLAD: Gracz o danym ID nie ma konta!");
            else{
                format(string,sizeof(string),"Zostales/as przyjety/a do gangu: %s przez Lidera: %s",Team[PlayerInfo[playerid][Leader]][Name],PlayerName(playerid));
                SendClientMessage(giveplayerid, COLOR_YELLOW, string);
                dini_IntSet(udb_encode(PlayerName(giveplayerid)), "PlayerTeam",PlayerInfo[playerid][Leader]);
            }
        }else SendClientMessage(playerid, COLOR_RED, "*BLAD: Nie jestes liderem gangu/mafii!");
        return 1;
    }
    //Wyrzucanie
    if(!strcmp(cmd, "uninvite", true))
    {
        if(PlayerInfo[playerid][Leader] >=0)
        {
            if(sscanf(cmdtext, "u", giveplayerid))SendClientMessage(playerid, COLOR_WHITE, "*Wpisz: /sgang zapros [id_gracza]");
            else if(giveplayerid == INVALID_PLAYER_ID)SendClientMessage(playerid, COLOR_RED, "BLAD: Gracza o danym ID nie ma!");
            else{
                format(string,sizeof(string),"Zostales/as wyrzucony/a z gangu: %s przez Lidera: %s",Team[PlayerInfo[playerid][Leader]][Name],PlayerName(playerid));
                SendClientMessage(giveplayerid, COLOR_YELLOW, string);
                dini_IntSet(udb_encode(PlayerName(giveplayerid)), "PlayerTeam",0);
            }
        }else SendClientMessage(playerid, COLOR_RED, "*BLAD: Nie jestes liderem gangu/mafii!");
        return 1;
    }
    //teleport
    if(!strcmp(cmd, "pos", true))
    {
        if(PlayerInfo[playerid][PlayerGang] != 0)
        {
            for(new Gangid = 0; Gangid < MAX_GANGS; Gangid++)
            {
                if(PlayerInfo[playerid][PlayerGang] == Gangid)
                {
                    SetPlayerPos(playerid,Team[Gangid][Spawn][0],Team[Gangid][Spawn][1],Team[Gangid][Spawn][2]);
                    SetPlayerFacingAngle(playerid, Team[Gangid][Spawn][3]);
                }
            }
        }else SendClientMessage(playerid, COLOR_RED, "*BLAD: Nie nalezysz do zadnego gangu/mafii");
        return 1;
    }
    //Bramy
    if(!strcmp(cmd, "gate", true))
    {
        return 1;  
    }
    return 1;
}
The second leaves invite,uninvite ... inside the cmdtext and just compares the first n charachters
pawn Код:
dcmd_sgang(playerid,cmdtext[])
{
new giveplayerid, string[128], tmp[28];
    if(!strlen(cmdtext))
    {
    SendClientMessage(playerid, COLOR_WHITE, "*Wpisz: /sgang [invite/uninvite/pos/gate]");
    return 1;
    }

    //Zaproszenie
    //Here we compare invite which is the first 6 of the whole string "invite player"
    if(!strcmp(cmdtext, "invite", true, 6))
    {
        if(PlayerInfo[playerid][Leader] >= 0)
        {
            //here we want to ignore the "invite" part thats still in cmdtext, so put it in tmp
            if(sscanf(cmdtext, "su", tmp, giveplayerid))SendClientMessage(playerid, COLOR_WHITE, "*Wpisz: /sgang zapros [id_gracza]");
            else if(giveplayerid == INVALID_PLAYER_ID)SendClientMessage(playerid, COLOR_RED, "BLAD: Gracza o danym ID nie ma!");
            else if(!dini_Exists(udb_encode(PlayerName(giveplayerid))))SendClientMessage(playerid, COLOR_RED, "BLAD: Gracz o danym ID nie ma konta!");
            else{
                format(string,sizeof(string),"Zostales/as przyjety/a do gangu: %s przez Lidera: %s",Team[PlayerInfo[playerid][Leader]][Name],PlayerName(playerid));
                SendClientMessage(giveplayerid, COLOR_YELLOW, string);
                dini_IntSet(udb_encode(PlayerName(giveplayerid)), "PlayerTeam",PlayerInfo[playerid][Leader]);
            }
        }else SendClientMessage(playerid, COLOR_RED, "*BLAD: Nie jestes liderem gangu/mafii!");
        return 1;
    }
    //Wyrzucanie
    if(!strcmp(cmdtext, "uninvite", true, 8))
    {
        if(PlayerInfo[playerid][Leader] >=0)
        {
            if(sscanf(cmdtext, "su", tmp, giveplayerid))SendClientMessage(playerid, COLOR_WHITE, "*Wpisz: /sgang zapros [id_gracza]");
            else if(giveplayerid == INVALID_PLAYER_ID)SendClientMessage(playerid, COLOR_RED, "BLAD: Gracza o danym ID nie ma!");
            else{
                format(string,sizeof(string),"Zostales/as wyrzucony/a z gangu: %s przez Lidera: %s",Team[PlayerInfo[playerid][Leader]][Name],PlayerName(playerid));
                SendClientMessage(giveplayerid, COLOR_YELLOW, string);
                dini_IntSet(udb_encode(PlayerName(giveplayerid)), "PlayerTeam",0);
            }
        }else SendClientMessage(playerid, COLOR_RED, "*BLAD: Nie jestes liderem gangu/mafii!");
        return 1;
    }
    //teleport
    if(!strcmp(cmdtext, "pos", true))
    {
        if(PlayerInfo[playerid][PlayerGang] != 0)
        {
            for(new Gangid = 0; Gangid < MAX_GANGS; Gangid++)
            {
                if(PlayerInfo[playerid][PlayerGang] == Gangid)
                {
                    SetPlayerPos(playerid,Team[Gangid][Spawn][0],Team[Gangid][Spawn][1],Team[Gangid][Spawn][2]);
                    SetPlayerFacingAngle(playerid, Team[Gangid][Spawn][3]);
                }
            }
        }else SendClientMessage(playerid, COLOR_RED, "*BLAD: Nie nalezysz do zadnego gangu/mafii");
        return 1;
    }
    //Bramy
    if(!strcmp(cmdtext, "gate", true))
    {
        return 1;  
    }
    return 1;
}



Re: Problem with the command - MrLeNy - 04.02.2010

thx. Working !!