how do i make strcmp params?
#1

How would I make a command like:

/setscore [team] [score]

Like if I did

/setscore 1 3

Using params with strcmp?
Reply
#2

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/setscore", true, 9)) // 9 is the length of /setscore
    {
        if(!cmdtext[9])return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /setscore [team] [score]");
        new receiverid;
        new score;
        SetPlayerScore(receiverid,score);
        return 1;
    }
    return 0;
}
It might be wrong, since I don't use strcmp

Like this?
Reply
#3

Quote:
Originally Posted by [CG]Milito
Посмотреть сообщение
pawn Код:
// 9 is the length of /me
Hm, no! The lenght of "/me" is 3.


@(_AcE_)
- You can use either strtok or sscanf, but I'd recomment you to use ZCMD with sscanf. It's great combination.
Reply
#4

well [CG]Milito's method is wrong and 2ndly why would yo uwant to use strcmp..? There are many other easier methods such as zcmd, or ycmd or if you really wanna go to the worst dcmd..
Reply
#5

Well, I am just making a simple small script and I've already made several commands and I don't feel like having to transfer the scripts to dcmd or zcmd.
Reply
#6

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/setscore", true))
    {
        if(!IsPlayerAdmin) return 0;
        new tmp[128];
        tmp = strtok(cmdtext,idx);
        if(!strlen(tmp)) return SendClientMessage(playerid,-1,"Usage: /setscore [ID] [SCORE]");
        if(!IsPlayerConnected(tmp)) return SendClientMessage(playerid,-1,"Player not found.");
        new id = strval(tmp);
        tmp = strtok(cmdtext,idx);
        if(!strlen(tmp)) return SendClientMessage(playerid,-1,"Usage: /setscore [ID] [SCORE]");
        SetPlayerScore(id,tmp);
        return 1;
    }
    return 0;
}
Made now, not tested.
Like this?
Reply
#7

Could you explain it? I don't think I could understand how to do other commands like this if I don't really understand what's going on. :P

parts like:

new tmp[128];
tmp = strtok(cmdtext,idx);
new id = strval(tmp);
tmp = strtok(cmdtext,idx);

Everything else is self explanatory.
Reply
#8

tmp is just a variable.
strtok gets the input, anything u will write after /setscore.
Quote:
Originally Posted by (_AcE_)
Посмотреть сообщение
Everything else is self explanatory.
Reply
#9

What if I wanted like

/setscore [team id] [score]

my two teams are TEAM_HOME and TEAM_AWAY so it would be:

pawn Код:
new tmp[128];
        tmp = strtok(cmdtext,teamid, score);
        if(!strlen(tmp)) return SendClientMessage(playerid,-1,"Usage: /setscore [TEAM ID] [SCORE]");
        if(!gTeam[tmp] == TEAM_HOME || gTeam[tmp] TEAM_AWAY) return SendClientMessage(playerid,-1,"Invalid team id.");
        new id = strval(tmp);
        tmp = strtok(cmdtext,teamid, score);
        if(!strlen(tmp)) return SendClientMessage(playerid,-1,"Usage: /setscore [TEAM ID] [SCORE]");
        teamhomescore = tmp;
        return 1;
??
Reply
#10

It would be like:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/setscore", true))
    {
        if(!IsPlayerAdmin) return 0;
        new tmp[128];
        tmp = strtok(cmdtext,idx);
        if(!strlen(tmp)) return SendClientMessage(playerid,-1,"Usage: /setscore [TeamID] [Score]");
        if(tmp < 1 || tmp > 2) return SendClientMessage(playerid,-1,"Invalid team ID.");
        new id = strval(tmp);
        tmp = strtok(cmdtext,idx);
        if(!strlen(tmp)) return SendClientMessage(playerid,-1,"Usage: /setscore [ID] [SCORE]");
        new score = strval(tmp);
        switch(id)
        {
                case 1: SetPlayerScore(teamhomescore,score);
                case 2: SetPlayerScore(teamawayscore,score);
        }
        return 1;
    }
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)