Problem with strcmp
#1

Hello,

this is probably something I just overlooked.

pawn Код:
COMMAND:takejob(playerid, params[])
{
    if(player[playerid][ajob] != 0) return SendClientMessage(playerid, COLOR_WHITE, "ERROR » You already have a job, use /quitjob first");
    new job, accept[64], jobstring[128];
    sscanf(params, "s[63]", accept);
    printf("Parameters: %s", accept);
    if(IsPlayerInRangeOfPoint(playerid, 10.0, 2512.4465,-1473.9086,24.8523)) // Mechanic NPC
    {
        if(strcmp(accept, "accept", true) == 0)
        {
            job = 1;
            player[playerid][ajob] = job;
            SavePlayerData(playerid, "ajob", player[playerid][ajob], 2);
            format(jobstring, sizeof(jobstring), "NOTE » You are now a %s type /help for more information and perks.", ReturnJobName(job));
            SendClientMessage(playerid, COLOR_YELLOW, jobstring);
            printf("Woops, something went wrong!");
            return 1;
        }
        else
        {
            printf("Is it actually working?!");
            SendClientMessage(playerid, COLOR_WHITE, "Are you sure you want the job? Type /takejob confirm");
        }
    }
    return 1;
}
Returns the strcmp part no mather what.
Reply
#2

Try this:

pawn Код:
if(!strcmp(accept, "accept"))
instead of
pawn Код:
if(strcmp(accept, "accept", true) == 0)
Also read this: https://sampforum.blast.hk/showthread.php?tid=199796
It will help you to understand strcmp better
Reply
#3

Quote:
Originally Posted by Kwarde
Посмотреть сообщение
Try this:

pawn Код:
if(!strcmp(accept, "accept"))
instead of
pawn Код:
if(strcmp(accept, "accept", true) == 0)
Also read this: https://sampforum.blast.hk/showthread.php?tid=199796
It will help you to understand strcmp better
This is the same shit? Anyways didn't work.
Reply
#4

Hmm. I think I see it.

pawn Код:
COMMAND:takejob(playerid, params[])
{
    if(player[playerid][ajob] != 0) return SendClientMessage(playerid, COLOR_WHITE, "ERROR » You already have a job, use /quitjob first");
    new job, accept[64], jobstring[128];
    //This is removed (sscanf)
    printf("Parameters: %s", accept);
    if(IsPlayerInRangeOfPoint(playerid, 10.0, 2512.4465,-1473.9086,24.8523)) // Mechanic NPC
    {
        if(!sscanf(params, "s", accept)) //And this is changed
        {
            job = 1;
            player[playerid][ajob] = job;
            SavePlayerData(playerid, "ajob", player[playerid][ajob], 2);
            format(jobstring, sizeof(jobstring), "NOTE » You are now a %s type /help for more information and perks.", ReturnJobName(job));
            SendClientMessage(playerid, COLOR_YELLOW, jobstring);
            printf("Woops, something went wrong!");
            return 1;
        }
        else
        {
            printf("Is it actually working?!");
            SendClientMessage(playerid, COLOR_WHITE, "Are you sure you want the job? Type /takejob confirm");
        }
    }
    return 1;
}
Try this :P
Reply
#5

pawn Код:
COMMAND:takejob(playerid, params[])
{
    if(player[playerid][ajob] != 0) return SendClientMessage(playerid, COLOR_WHITE, "ERROR » You already have a job, use /quitjob first");
    new job, accept[64], jobstring[128];
    //This is removed (sscanf)
    printf("Parameters: %s", accept);
    if(IsPlayerInRangeOfPoint(playerid, 10.0, 2512.4465,-1473.9086,24.8523)) // Mechanic NPC
    {
        if(!sscanf(params, "s[63]", accept)) //And this is changed
        {
            job = 1;
            player[playerid][ajob] = job;
            SavePlayerData(playerid, "ajob", player[playerid][ajob], 2);
            format(jobstring, sizeof(jobstring), "NOTE » You are now a %s type /help for more information and perks.", ReturnJobName(job));
            SendClientMessage(playerid, COLOR_YELLOW, jobstring);
            printf("Woops, something went wrong!");
            return 1;
        }
        else
        {
            printf("Is it actually working?!");
            SendClientMessage(playerid, COLOR_WHITE, "Are you sure you want the job? Type /takejob confirm");
        }
    }
    return 1;
}
Have to index the string but other then that it actually works Thanks!
Reply
#6

No problem
And I have a little tip to make the script different. Don't use:
Код:
if (something is true )
   DO SOMETHING
but
Код:
if (this is not true) return //something
Ehm here's a little example:

What you do:
pawn Код:
if(IsPlayerAdmin(playerid))
{
    SetPlayerMoney(playerid, 100);
    printf("Player ID %d is an admin and received 100 dollar!", playerid);
}
What I mean:
pawn Код:
if(!IsPlayerAdmin(playerid)) return 0; //Stop.. xD
SetPlayerMoney(playerid, 100);
printf("Player ID %d is an admin and received 100 dollar!", playerid);
So your script will look like this:

pawn Код:
COMMAND:takejob(playerid, params[])
{
    if(player[playerid][ajob] != 0) return SendClientMessage(playerid, COLOR_WHITE, "ERROR » You already have a job, use /quitjob first"); //You've done good here
    new job, accept[64], jobstring[128];
    //This is removed (sscanf)
    printf("Parameters: %s", accept);
    if(!IsPlayerInRangeOfPoint(playerid, 10.0, 2512.4465,-1473.9086,24.8523)) return false;
    if(sscanf(params, "s[63]", accept)) return SendClientMessage(playerid, COLOR_WHITE, "Are you sure you want the job? Type /takejob confirm");
    job = 1;
    player[playerid][ajob] = job;
    SavePlayerData(playerid, "ajob", player[playerid][ajob], 2);
    format(jobstring, sizeof(jobstring), "NOTE » You are now a %s type /help for more information and perks.", ReturnJobName(job));
    SendClientMessage(playerid, COLOR_YELLOW, jobstring);
    return 1;

}
It saves a bit diskspace. But with every function/command, it CAN save alot of diskspace!
But it's just an tip. Use what you like
Reply
#7

Quote:
Originally Posted by Kwarde
Посмотреть сообщение
No problem
And I have a little tip to make the script different. Don't use:
Код:
if (something is true )
   DO SOMETHING
but
Код:
if (this is not true) return //something
Ehm here's a little example:

What you do:
pawn Код:
if(IsPlayerAdmin(playerid))
{
    SetPlayerMoney(playerid, 100);
    printf("Player ID %d is an admin and received 100 dollar!", playerid);
}
What I mean:
pawn Код:
if(!IsPlayerAdmin(playerid)) return 0; //Stop.. xD
SetPlayerMoney(playerid, 100);
printf("Player ID %d is an admin and received 100 dollar!", playerid);
So your script will look like this:

pawn Код:
COMMAND:takejob(playerid, params[])
{
    if(player[playerid][ajob] != 0) return SendClientMessage(playerid, COLOR_WHITE, "ERROR » You already have a job, use /quitjob first"); //You've done good here
    new job, accept[64], jobstring[128];
    //This is removed (sscanf)
    printf("Parameters: %s", accept);
    if(!IsPlayerInRangeOfPoint(playerid, 10.0, 2512.4465,-1473.9086,24.8523)) return false;
    if(sscanf(params, "s[63]", accept)) return SendClientMessage(playerid, COLOR_WHITE, "Are you sure you want the job? Type /takejob confirm");
    job = 1;
    player[playerid][ajob] = job;
    SavePlayerData(playerid, "ajob", player[playerid][ajob], 2);
    format(jobstring, sizeof(jobstring), "NOTE » You are now a %s type /help for more information and perks.", ReturnJobName(job));
    SendClientMessage(playerid, COLOR_YELLOW, jobstring);
    return 1;

}
It saves a bit diskspace. But with every function/command, it CAN save alot of diskspace!
But it's just an tip. Use what you like
Problem is that it's several jobs and I find it more clean to do it that way.
Reply
#8

Ej it's your call. I just prefer this And what way you mean? (with 'more clean')
Your way, or mine? :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)