do I have to use dcmd && sscanf?
#1

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 !
Reply
#2

Hello

Read this topic and you will understand it

https://sampforum.blast.hk/showthread.php?tid=120356
Reply
#3

OMG
Well,I guess this will be the hardest thing to learn at pawn scripting.
Thanks.
Reply
#4

No, you don't have to use strcmp and sscanf if you don't want
Reply
#5

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.
}
Reply
#6

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
Reply
#7

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.
Reply
#8

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.
Reply
#9

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(cmdtextidx);
if(
strlen(tmp) == 0) return blabla bla // so that checks if nothing entered .//how do I check if the tmp value is character.

Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)