do I have to use dcmd && sscanf? -
bijoyekuza - 28.02.2011
Hey guys ...
so If I want a good RP mode ...
Do I HAVE to use dcmd && sscanf ?
If so ... Can I have any tutorials about them ?
Thank you very much !
AW: do I have to use dcmd && sscanf? -
dUDALUS - 28.02.2011
Hello
Read this topic and you will understand it
https://sampforum.blast.hk/showthread.php?tid=120356
Re: do I have to use dcmd && sscanf? -
bijoyekuza - 28.02.2011
OMG
Well,I guess this will be the hardest thing to learn at pawn scripting.
Thanks.
Re: do I have to use dcmd && sscanf? -
dice7 - 28.02.2011
No, you don't have to use strcmp and sscanf if you don't want
Re: do I have to use dcmd && sscanf? -
Mean - 28.02.2011
Example:
pawn Код:
dcmd_poke( playerid, params[ ] )
{
new id;
if( sscanf( params, "u", id ) )
return SendClientMessage( playerid, 0xAAAAAA, "Usage: /poke [ID] " );
return SendClientMessage( id, 0xAAAAAA, "Poked" ); // Sends a message to the ID you entered.
}
Re: do I have to use dcmd && sscanf? -
admantis - 28.02.2011
You dont 'HAVE' to, but it's STRONGLY recommended due it's shorter, efficent, faster, unlike strtok with you need to re-change past in the future, and you won't because since their +80 commands you going to say 'fuck this' and drop it, so make it with sscanf from the start.. It's worth it.
And I recommend more zcmd than dcmd
Re: do I have to use dcmd && sscanf? -
dice7 - 28.02.2011
Quote:
Originally Posted by admantis
You dont 'HAVE' to, but it's STRONGLY recommended
|
By who?
Quote:
Originally Posted by admantis
due it's shorter
|
No, It's not shorter, look at the code
Quote:
Originally Posted by admantis
efficent
|
You got me
Quote:
Originally Posted by admantis
faster
|
Yes, if you type a command which accepts 20 params (/cmd [playerid] [weaponid] [ammo] [something] [somethingelse] [somethingelse2] ...) 150 times in 2 seconds, then you
may notice a difference
Quote:
Originally Posted by admantis
unlike strtok with you need to re-change past in the future, and you won't because since their +80 commands you going to say 'fuck this' and drop it, so make it with sscanf from the start.. It's worth it.
|
If it works, don't fix it
Quote:
Originally Posted by admantis
And I recommend more zcmd than dcmd
|
Could argue here about how using strcmp and dcmd could in some cases result in shorter code, but I wont
My point is, stop brainwashing people and forcing them to use functions they do not understand or do not even need to use. I do not care if my code is 5 miliseconds faster then before, all I want is to get the job done.
NOTE that this applies only for stuff like commands. In situations like spliting huge strings, like mysql results or data read from a file, I suggest sscanf.
Same with dini, y_ini, djson and similar. If you're only gonna use it under OnPlayerConnect and OnPlayerDisconnect then it really doesn't matter what you use, but if you're gonna read/write large quantities of data in a loop, which can lag the server, then use the fastest option, which is y_ini, I believe.
Re: do I have to use dcmd && sscanf? -
[WF]Demon - 28.02.2011
Well i never got strtok not sure how anyone ever did, sscanf and zcmd is shorter (Not ZCMD its about the same size as strcmp) but sscanf is indeed shorter and easier, i dont care if its faster or more efficient i say simpler is better, you can argue with me all day for saying this i will not reply back, but yes i do recommend using sscanf and zcmd, ill show you why
STRCMP And STRTOK PM:
pawn Код:
if(strcmp("/pm", cmd, true) == 0)
{
tmp = strtok(cmdtext,idx);
if(!strlen(tmp) || strlen(tmp) > 5) {
SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /pm (id) (message)");
return 1;
}
new id = strval(tmp);
gMessage = strrest(cmdtext,idx);
if(!strlen(gMessage)) {
SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /pm (id) (message)");
return 1;
}
if(!IsPlayerConnected(id)) {
SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/pm : Bad player ID");
return 1;
}
if(playerid != id) {
GetPlayerName(id,iName,sizeof(iName));
GetPlayerName(playerid,pName,sizeof(pName));
format(Message,sizeof(Message),">> %s(%d): %s",iName,id,gMessage);
SendClientMessage(playerid,PM_OUTGOING_COLOR,Message);
format(Message,sizeof(Message),"** %s(%d): %s",pName,playerid,gMessage);
SendClientMessage(id,PM_INCOMING_COLOR,Message);
PlayerPlaySound(id,1085,0.0,0.0,0.0);
printf("PM: %s",Message);
}
else {
SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"You cannot PM yourself");
}
return 1;
}
long ass command right?
ZCMD And SSCANF PM
pawn Код:
COMMAND:pm(playerid, params[])
{
new otherid, message[100], pname[24], string[128];
if(sscanf(params, "is", otherid, message)) return SendClientMessage(playerid, 0xFFFFFFFF, "Command Syntax: /pm [ID] [Message]");
if(!IsPlayerConnected(otherid)) return SendClientMessage(playerid, 0xFFFFFFFF, "That Player Is Not Connected");
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "PM From %s : %s", pname, message);
SendClientMessage(otherid, 0xFFFFFFFF, string);
return 1;
}
I made that last PM in 3 minutes or less, see what i mean?
i just recommend ZCMD and SSCANF, i will not reply unless the topic starter is replying to me.
Re: do I have to use dcmd && sscanf? -
bijoyekuza - 01.03.2011
Quote:
Originally Posted by dice7
By who?
No, It's not shorter, look at the code
You got me
Yes, if you type a command which accepts 20 params (/cmd [playerid] [weaponid] [ammo] [something] [somethingelse] [somethingelse2] ...) 150 times in 2 seconds, then you may notice a difference
If it works, don't fix it
Could argue here about how using strcmp and dcmd could in some cases result in shorter code, but I wont
My point is, stop brainwashing people and forcing them to use functions they do not understand or do not even need to use. I do not care if my code is 5 miliseconds faster then before, all I want is to get the job done.
NOTE that this applies only for stuff like commands. In situations like spliting huge strings, like mysql results or data read from a file, I suggest sscanf.
Same with dini, y_ini, djson and similar. If you're only gonna use it under OnPlayerConnect and OnPlayerDisconnect then it really doesn't matter what you use, but if you're gonna read/write large quantities of data in a loop, which can lag the server, then use the fastest option, which is y_ini, I believe.
|
Your reply really helped me . Thanks alot.
Just 1 more question.
How can I check with strtok if the player writes numbers or characters ? I mean
PHP код:
if(strcmp(cmd,"/hello",true,10) == 0)
{
new tmp[256];
tmp = strtok(cmdtext, idx);
if(strlen(tmp) == 0) return blabla bla // so that checks if nothing entered .//how do I check if the tmp value is character.
}
Re: do I have to use dcmd && sscanf? -
Mean - 01.03.2011
Quote:
Originally Posted by [WF]Demon
Well i never got strtok not sure how anyone ever did, sscanf and zcmd is shorter (Not ZCMD its about the same size as strcmp) but sscanf is indeed shorter and easier, i dont care if its faster or more efficient i say simpler is better, you can argue with me all day for saying this i will not reply back, but yes i do recommend using sscanf and zcmd, ill show you why
STRCMP And STRTOK PM:
pawn Код:
if(strcmp("/pm", cmd, true) == 0) { tmp = strtok(cmdtext,idx); if(!strlen(tmp) || strlen(tmp) > 5) { SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /pm (id) (message)"); return 1; } new id = strval(tmp); gMessage = strrest(cmdtext,idx); if(!strlen(gMessage)) { SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /pm (id) (message)"); return 1; } if(!IsPlayerConnected(id)) { SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/pm : Bad player ID"); return 1; } if(playerid != id) { GetPlayerName(id,iName,sizeof(iName)); GetPlayerName(playerid,pName,sizeof(pName)); format(Message,sizeof(Message),">> %s(%d): %s",iName,id,gMessage); SendClientMessage(playerid,PM_OUTGOING_COLOR,Message); format(Message,sizeof(Message),"** %s(%d): %s",pName,playerid,gMessage); SendClientMessage(id,PM_INCOMING_COLOR,Message); PlayerPlaySound(id,1085,0.0,0.0,0.0); printf("PM: %s",Message); } else { SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"You cannot PM yourself"); } return 1; }
long ass command right?
ZCMD And SSCANF PM
pawn Код:
COMMAND:pm(playerid, params[]) { new otherid, message[100], pname[24], string[128]; if(sscanf(params, "is", otherid, message)) return SendClientMessage(playerid, 0xFFFFFFFF, "Command Syntax: /pm [ID] [Message]"); if(!IsPlayerConnected(otherid)) return SendClientMessage(playerid, 0xFFFFFFFF, "That Player Is Not Connected"); GetPlayerName(playerid, pname, sizeof(pname)); format(string, sizeof(string), "PM From %s : %s", pname, message); SendClientMessage(otherid, 0xFFFFFFFF, string); return 1; }
I made that last PM in 3 minutes or less, see what i mean?
i just recommend ZCMD and SSCANF, i will not reply unless the topic starter is replying to me.
|
That's b*llshit, you didn't put half of the code in ZCMD one, like IsPlayerConnected, yes I go for ZCMD, it's faster and shorter, but these are 2 diffrent commands!
You should use ZCMD and SSCANF, it's much faster than STRTOK and STRCMP.