Params not working.
#1

Hello everyone, well I'm making a gangs filterscript and there's one huge problem i got and its with params..
Thats causing the USAGE's not to show.

Code:
pawn Код:
dcmd_gang(playerid,params[])
{
    new tmp[256];
    new gangcmd, gangnum;
    new string[128], sendername[MAX_PLAYER_NAME], giveplayerid, giveplayer[MAX_PLAYER_NAME];
    if(params[0] == '\0') {
        SendClientMessage(playerid, COLOR_WHITE, "USAGE: /gang [create/join/invite/quit] [name/number]");
        return 1;
    }

    if(strcmp(params, "create", true)==0) gangcmd = 1;
    else if(strcmp(params, "invite", true)==0) gangcmd = 2;
    else if(strcmp(params, "join", true)==0) gangcmd = 3;
    else if(strcmp(params, "quit", true)==0) gangcmd = 4;

   if(gangcmd < 3) {
        if(gangcmd==0)
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /gang [create/join/invite/quit] [name/number]");
        else if(gangcmd==1)
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /gang [create] [name]");
        else if(gangcmd==2)
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /gang [invite] [playerID]");
        return 1;
    }

//Create Gang//
    if(gangcmd==1) {
        if(playerGang[playerid]>0) {
            SendClientMessage(playerid, COLOR_RED, "You are already in a gang!");
            return 1;
        }

        for(new i = 1; i < MAX_GANGS; i++) {
            if(gangInfo[i][0]==0) {
//name gang
                format(gangNames[i], MAX_GANG_NAME, "%s", tmp);
//Gang exists
                gangInfo[i][0]=1;
//There is one member
                gangInfo[i][1]=1;
//Gang color is player's color
                gangInfo[i][2]=playerColors[playerid];

//Player is the first gang member
                gangMembers[i][0] = playerid;
                format(string, sizeof(string),"You have created the gang '%s' (id: %d)", gangNames[i], i);
                SendClientMessage(playerid, COLOR_GREEN, string);

                playerGang[playerid]=i;

                return 1;
            }
        }

        return 1;

//Join Gang//
    }
    else if (gangcmd==3) {
        gangnum = gangInvite[playerid];

        if(playerGang[playerid]>0) {
            SendClientMessage(playerid, COLOR_RED, "You are already in a gang!");
            return 1;
        }
        if(gangInvite[playerid]==0) {
            SendClientMessage(playerid, COLOR_RED, "You have not been invited to a gang.");
            return 1;
        }
        if(gangInfo[gangnum][0]==0) {
            SendClientMessage(playerid, COLOR_RED, "That gang does not exist!");
            return 1;
        }

        if(gangInfo[gangnum][1] < MAX_GANG_MEMBERS) {
            new i = gangInfo[gangnum][1];

            gangInvite[playerid]=0;

            gangMembers[gangnum][i] = playerid;

            GetPlayerName(playerid, sendername, MAX_PLAYER_NAME);
            for(new j = 0; j < gangInfo[gangnum][1]; j++) {
                format(string, sizeof(string),"%s has joined your gang.", sendername);
                SendClientMessage(gangMembers[gangnum][j], COLOR_ORANGE, string);
            }

            gangInfo[gangnum][1]++;
            playerGang[playerid] = gangnum;

            SetPlayerColor(playerid,gangInfo[gangnum][2]);

            format(string, sizeof(string),"You have joined the gang '%s' (id: %d)", gangNames[gangnum], gangnum);
            SendClientMessage(playerid, COLOR_GREEN, string);

            return 1;
        }

        SendClientMessage(playerid, COLOR_RED, "That gang is full.");
        return 1;

//Invite to Gang//
    }
    else if (gangcmd==2) {
        giveplayerid = strval(tmp);

        if(playerGang[playerid]==0) {
            SendClientMessage(playerid, COLOR_RED, "You are not in a gang!");
            return 1;
        }
//          if(gangMembers[playerGang[playerid]][0]!=playerid) {
//              SendClientMessage(playerid, COLOR_RED, "You need to be the gang leader to send an invite.");
//              return 1;
//          }

        if(IsPlayerConnected(giveplayerid)) {
            GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
            GetPlayerName(playerid, sendername, sizeof(sendername));

            format(string, sizeof(string),"You have sent a gang invite to %s.", giveplayer);
            SendClientMessage(playerid, COLOR_GREEN, string);
            format(string, sizeof(string),"You have recieved a gang invite from %s to '%s' (id: %d)", sendername, gangNames[playerGang[playerid]],playerGang[playerid]);
            SendClientMessage(giveplayerid, COLOR_GREEN, string);

            gangInvite[giveplayerid]=playerGang[playerid];

        } else
        SendClientMessage(playerid, COLOR_RED, "No such player exists!");

//Leave Gang//
    }
    else if (gangcmd==4) {
        PlayerLeaveGang(playerid);
    }

    return 1;
}
Whats wrong with that code which doesn't show the gang usage stuff? Please help.

Edit: And yes im having trouble converting this command into DCMD.
Reply
#2

~~~~ Bump ~~~~
Reply
#3

Remove the && !params[0], because if you type "/gang asdaiosud", it wont go to that part
Reply
#4

Alright ill try it out Dice


Edit: Nope it dont work, when i type /gang create it replies with that use msg of /gang [create/join/invite/etc]
Reply
#5

Hmm, you'll need a different approach when doing a command like this. First of

pawn Код:
if(strcmp(params, "create", true)==0) gangcmd = 1;
    else if(strcmp(params, "invite", true)==0) gangcmd = 2;
    else if(strcmp(params, "join", true)==0) gangcmd = 3;
    else if(strcmp(params, "quit", true)==0) gangcmd = 4;
When you type "/gang create somename", then 'params' holds the value "create somename", that's why you'll need to fix your strcmps to compare just the first x letters of 'params'.

About the not showing usage lines, this should work now
pawn Код:
if(gangcmd < 3 && !params[7]) {
That will check if there was anything typed after "create " or "invite ".

Also, I see you don't actually get the gangs name anywhere
Reply
#6

Quote:
Originally Posted by dice7
Посмотреть сообщение
When you type "/gang create somename", then 'params' holds the value "create somename", that's why you'll need to fix your strcmps to compare just the first x letters of 'params'.
Im not any good with params, except those strcmp ones.. Whats wrong with them? so how do i fix those params?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)