getjob cmd help
#1

even when im in range of a job point,it says im not in range of a job point and i have a job in the data base with the coordonates saved,i don't know what's wrong with my command,this is the command and the load function


CMD:getjob(playerid, params[]){

if(PlayerInfo[playerid][pJob] != 0)
return SendClientMessage(playerid, COLOR_GREY, "You already have a job");

for(new i = 1; i <= MAX_JOBS; i++)
{
if(!IsPlayerInRangeOfPoint(playerid, 3.0, JobInfo[i][jPosX], JobInfo[i][jPosY], JobInfo[i][jPosZ]))
return SendClientMessage(playerid, COLOR_GREY, "You aren't in range of any job point");
}
return 1;
}


function LoadJobs() {
new
Cache: db = mysql_query (mysql, "SELECT * FROM `jobs` ORDER BY `jobs`.`ID` ASC"),
x, jobs, result[180], string[180];

for (new i, j = cache_get_row_count (); i != j; ++i) {
jobs ++;
cache_get_field_content(i, "ID", result); x = strval(result);
cache_get_field_content(i, "Name", result); format(JobInfo[x][jName], 128, result);
//cache_get_field_content(i, "NeedLevel", result); JobInfo[x][jLevel] = strval(result);
cache_get_field_content(i, "PosX", result); JobInfo[x][jPosX] = floatstr(result);
cache_get_field_content(i, "PosY", result); JobInfo[x][jPosY] = floatstr(result);
cache_get_field_content(i, "PosZ", result); JobInfo[x][jPosZ] = floatstr(result);
}
printf("Jobs: %d", jobs);
cache_delete(db);
return 1;
}
Reply
#2

It's because you're killing the loop after the first false check, instead use continue, and outside the function if the code keeps running output the error message. It will look like this:

pawn Код:
CMD:getjob(playerid, params[]){

    if(PlayerInfo[playerid][pJob] != 0)
        return SendClientMessage(playerid, COLOR_GREY, "You already have a job");

    for(new i = 1; i <= MAX_JOBS; i++)
    {
        if(!IsPlayerInRangeOfPoint(playerid, 3.0, JobInfo[i][jPosX], JobInfo[i][jPosY], JobInfo[i][jPosZ])) continue;
        // if he is in range of any, the code will reach here
        return 1;
    }
    // if no match, then no return statement in the loop preventing it from reaching this part of code so:
    SendClientMessage(playerid, COLOR_GREY, "You aren't in range of any job point");
    return 1;
}
Reply
#3

Quote:
Originally Posted by TheToretto
Посмотреть сообщение
It's because you're killing the loop after the first false check, instead use continue, and outside the function if the code keeps running output the error message. It will look like this:

pawn Код:
CMD:getjob(playerid, params[]){

    if(PlayerInfo[playerid][pJob] != 0)
        return SendClientMessage(playerid, COLOR_GREY, "You already have a job");

    for(new i = 1; i <= MAX_JOBS; i++)
    {
        if(!IsPlayerInRangeOfPoint(playerid, 3.0, JobInfo[i][jPosX], JobInfo[i][jPosY], JobInfo[i][jPosZ])) continue;
        // if he is in range of any, the code will reach here
        return 1;
    }
    // if no match, then no return statement in the loop preventing it from reaching this part of code so:
    SendClientMessage(playerid, COLOR_GREY, "You aren't in range of any job point");
    return 1;
}
CMD:getjob(playerid, params[]){

if(PlayerInfo[playerid][pJob] != 0)
return SendClientMessage(playerid, COLOR_GREY, "You already have a job");

for(new i = 1; i <= MAX_JOBS; i++)
{
if(!IsPlayerInRangeOfPoint(playerid, 3.0, JobInfo[i][jPosX], JobInfo[i][jPosY], JobInfo[i][jPosZ])) continue;
SendClientMessage(playerid, -1, "Test");
return 1;
}
SendClientMessage(playerid, COLOR_GREY, "You aren't in range of any job point");
return 1;
}

this is the command now,and it says Server Unknown command
Reply
#4

Hi, take a look at this,

PHP код:
CMD:getjob(playeridparams[]){
    if(
PlayerInfo[playerid][pJob] != 0){
        
SendClientMessage(playeridCOLOR_GREY"You already have a job");
        return 
1;
    }
    for(new 
1<= MAX_JOBSi++)
    {
        if(!
IsPlayerInRangeOfPoint(playerid3.0JobInfo[i][jPosX], JobInfo[i][jPosY], JobInfo[i][jPosZ])){
            continue;    
        }
        
// Code if you are in range of a job goes here
        // Now give a value to PlayerInfo[playerid][pJob] different from 0, because we found a job 
        
break; // Break the loop once found the job you were looking for
    
}
    
// If after the loop we didnt find a job, and so PlayerInfo[playerid][pJob] is equal to 0 (or the value you use to say "no job found") we can do
    
if(PlayerInfo[playerid][pJob] == 0){
        
SendClientMessage(playeridCOLOR_GREY"You aren't in range of any job point");
        return 
1;
    }
    return 
1;

EDIT: Also, why do you start loop from 1? You are skipping first spot (0)
Reply
#5

Nope,still "This command does not exist"
Reply
#6

If it says you that, command doesn't get executed at all, or it happens when the command returns 0 somewhere and I don't see any in your code.
Reply
#7

Quote:
Originally Posted by v1k1nG
Посмотреть сообщение
Hi, take a look at this,

PHP код:
CMD:getjob(playeridparams[]){
    if(
PlayerInfo[playerid][pJob] != 0){
        
SendClientMessage(playeridCOLOR_GREY"You already have a job");
        return 
1;
    }
    for(new 
1<= MAX_JOBSi++)
    {
        if(!
IsPlayerInRangeOfPoint(playerid3.0JobInfo[i][jPosX], JobInfo[i][jPosY], JobInfo[i][jPosZ])){
            continue;    
        }
        
// Code if you are in range of a job goes here
        // Now give a value to PlayerInfo[playerid][pJob] different from 0, because we found a job 
        
break; // Break the loop once found the job you were looking for
    
}
    
// If after the loop we didnt find a job, and so PlayerInfo[playerid][pJob] is equal to 0 (or the value you use to say "no job found") we can do
    
if(PlayerInfo[playerid][pJob] == 0){
        
SendClientMessage(playeridCOLOR_GREY"You aren't in range of any job point");
        return 
1;
    }
    return 
1;

That's non sense. And it's not even dynamic, as pJob doesn't change obviously, probably going to display a dialog, anyway I don't see why it would return false all the conditions. Could you debug your code? Print in each condition. (you will have to add some braces)

Try changing

pawn Код:
for(new i = 1; i <= MAX_JOBS; i++)
By

pawn Код:
for(new i; i < sizeof(JobInfo); i++)

Edit: Are you even loading correctly the script? Compiling it in the right folder? The code seems to be fine.
Reply
#8

Quote:

That's non sense.

I just added a break instead of return when you find the value.
Quote:

And it's not even dynamic

Dynamic? How is your code dynamic? Because you return 1; in the loop?
Quote:

pJob doesn't change obviously, probably going to display a dialog

He didn't post rest of the code, we don't know about how he goes forward, how do you know and say "it's nonsense" and "obviously"?
Quote:

I don't see why it would return false all the conditions

It would return "true" only 1 condition, the nearest one, obv the rest are "false".
Quote:

(you will have to add some braces)

You should always use braces, I see you don't and that's not suggested.
Reply
#9

So,what do i do? :d
That's all i have on the getjob command
This happens only when im adding "continue",if im using return 1 instead of continue its working,but yeah,it's not doing what it's supposed to do that way.
Reply
#10

Do other commands work? It may be some other kind of problem
Reply
#11

Quote:
Originally Posted by v1k1nG
View Post
Do other commands work? It may be some other kind of problem
all my commands work,and this works too once i replace the "continue",but by replacing "continue",i ll never be able to get a job because as torreto said,the loop breakes after the first false check,so yeah,tf do i do.
Reply
#12

Quote:
Originally Posted by v1k1nG
Посмотреть сообщение
I just added a break instead of return when you find the value.
Dynamic? How is your code dynamic? Because you return 1; in the loop?
He didn't post rest of the code, we don't know about how he goes forward, how do you know and say "it's nonsense" and "obviously"?
It would return "true" only 1 condition, the nearest one, obv the rest are "false".
You should always use braces, I see you don't and that's not suggested.
Return and break in a loop aren't the same. Return would stop the whole function, which is cmd_getjob, while break will keep the outside code of the loop running, and that's not needed.

Your last comment is not valid, braces aren't required, if you have an if check with only one operation, you can skip the useless braces, and returning a SendClientMessage is basically returning true plus sending the message. By saying add braces, I was referring to the prints inside the if checks.
Reply
#13

Quote:
Originally Posted by TheToretto
Посмотреть сообщение
Return and break in a loop aren't the same. Return would stop the whole function, which is cmd_getjob, while break will keep the outside code of the loop running, and that's not needed.

Your last comment is not valid, braces aren't required, if you have an if check with only one operation, you can skip the useless braces, and returning a SendClientMessage is basically returning true plus sending the message. By saying add braces, I was referring to the prints inside the if checks.
but why would "continue" stop my whole command from working
Reply
#14

Quote:
Originally Posted by TheToretto
View Post
Return and break in a loop aren't the same. Return would stop the whole function, which is cmd_getjob, while break will keep the outside code of the loop running, and that's not needed.

Your last comment is not valid, braces aren't required, if you have an if check with only one operation, you can skip the useless braces, and returning a SendClientMessage is basically returning true plus sending the message. By saying add braces, I was referring to the prints inside the if checks.
1 - Yes continue and break are not the same, the code I wrote after the break is a simple SendClientMessage line in a check if a var is = or != than 0, and you build up a nice drama over that thing indeed.

2 - After any conditional check you would use braces in c++ like languages even if the code to write is a line.

/////////

bosmania you would need to post all the code related to the cmd, variables, defines, custom functions you use inside and such
Reply
#15

Quote:
Originally Posted by v1k1nG
View Post
1 - Yes continue and break are not the same, the code I wrote after the break is a simple SendClientMessage line in a check if a var is = or != than 0, and you build up a nice drama over that thing indeed.

2 - After any conditional check you would use braces in c++ like languages even if the code to write is a line.
You are absolutely wrong about the second thing you said. And for the first, I am not talking about continue, but break versus return. They are not the same.
Reply
#16

I clearly misplaced continue for return while writing.

https://stackoverflow.com/questions/...ine-if-or-loop

if you want to use your "style" is ok, but if someone wants to learn, teach him the proper way first.
Reply
#17

Quote:
Originally Posted by v1k1nG
View Post
I clearly misplaced continue for return while writing.

https://stackoverflow.com/questions/...ine-if-or-loop

if you want to use your "style" is ok, but if someone wants to learn, teach him the proper way first.
I can teach you if you want Next time don't "misplace" when trying to provide false codes
Reply
#18

I didnt "misplace" terms in my code but while writing the post.. you aren't even reading, peace.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)