how do i make strcmp params? -
(_AcE_) - 01.04.2013
How would I make a command like:
/setscore [team] [score]
Like if I did
/setscore 1 3
Using params with strcmp?
Re: how do i make strcmp params? -
[CG]Milito - 01.04.2013
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?
Re: how do i make strcmp params? -
Konstantinos - 01.04.2013
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.
Re: how do i make strcmp params? -
kamzaf - 01.04.2013
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..
Re: how do i make strcmp params? -
(_AcE_) - 01.04.2013
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.
Re: how do i make strcmp params? -
zxc1 - 01.04.2013
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?
Re: how do i make strcmp params? -
(_AcE_) - 01.04.2013
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.
Re: how do i make strcmp params? -
zxc1 - 01.04.2013
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.
|
Re: how do i make strcmp params? -
(_AcE_) - 01.04.2013
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;
??
Re: how do i make strcmp params? -
zxc1 - 02.04.2013
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;
}