Help with /getjob.
#1

I'm trying to make a dynamic job system in which you can do /getjob if you're in the range of the job position.

This is my code.

Код:
CMD:getjob(playerid, params[])
{
	for(new i = 0; i < MAX_JOBS; i++)
	{
		if(pInfo[playerid][pJob] == 0)
		{
			if(IsPlayerInRangeOfPoint(playerid, 5, jInfo[i][jPosX], jInfo[i][jPosY], jInfo[i][jPosZ]))
			{
				new string[256];
				format(string, sizeof(string), "* You have signed the contracts and you are now working as a %s.", jInfo[i][jName]);
				SendClientMessage(playerid, COLOR_ACHIEVEMENT, string);
				pInfo[playerid][pJob] = jInfo[i][jType];
			}
			else return SendClientMessage(playerid, COLOR_GREY, "You are not at a job point.");
		}
		else return SendClientMessage(playerid, COLOR_GREY, "You already have a job, use /quitjob instead.");
	}
	return 1;
}
I don't know why, but the command only works on the first job that loaded from the database.
For every other job it returns the "Not at a job point" text.
How can I fix this?
Reply
#2

Problem probably happens on the mysql loading I suppose..
Show us how you load the data
Reply
#3

Why dont you use cases and InRangeOf code like this? Its better than yours.

PHP код:
if(IsPlayerInRangeOfPoint(playerid,3.0,X,Y,Z Coordinates) {
            if(
PlayerInfo[playerid][pJob] == 0){
                
SendClientMessageEx(playeridCOLOR_LIGHTBLUE"You have signed in the papers and you are not workign for (job name)");
                
pInfo[playerid][pJob] = 1;
                return 
1;
            }
}
        else if(
IsPlayerInRangeOfPoint(playerid3.0X,Y,Z Coordinates)) {
            if(
PlayerInfo[playerid][pJob] == 0){
                
SendClientMessageEx(playeridCOLOR_LIGHTBLUE"* You have signed up in the papers and you are now working for (job name)");
                
pInfo[playerid][pJob] = 2;
                return 
1;
            }
        }
        else if (
IsPlayerInRangeOfPoint(playerid,3.0,X,Y,Z Coordinates ._.)) {
            if(
PlayerInfo[playerid][pJob] == 0){
                
SendClientMessageEx(playeridCOLOR_LIGHTBLUE"*You have signed up in the papers and you are now working for (job name)");
                
pInfo[playerid][pJob] = 3;
                return 
1;
            } 
Reply
#4

Don't use return in a loop

This is how I would do
pawn Код:
CMD:getjob(playerid, params[])
{
new isatjob;
    for(new i; i < MAX_JOBS; i++)
    {
        if(pInfo[playerid][pJob] == 0)
        {
            if(IsPlayerInRangeOfPoint(playerid, 5, jInfo[i][jPosX], jInfo[i][jPosY], jInfo[i][jPosZ]))
            {
                new string[256];
                format(string, sizeof(string), "* You have signed the contracts and you are now working as a %s.", jInfo[i][jName]);
                SendClientMessage(playerid, COLOR_ACHIEVEMENT, string);
                pInfo[playerid][pJob] = jInfo[i][jType];
isatjob = 1;
            }
        }
        else return SendClientMessage(playerid, COLOR_GREY, "You already have a job, use /quitjob instead.");
    }
if(!isatjob)
{
SendClientMessage(playerid, COLOR_GREY, "You are not at a job point.");
}
    return 1;
}
Reply
#5

Quote:
Originally Posted by Sascha
Посмотреть сообщение
Problem probably happens on the mysql loading I suppose..
Show us how you load the data
Код:
[00:18:44] [DEBUG] Calling callback "OnJobsLoad"..
[00:18:44] [DEBUG] cache_get_row_count - connection: 1
[00:18:44] [DEBUG] cache_get_field_content_int - row: 0, field_name: "jobID", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "jobID", data: "1"
[00:18:44] [DEBUG] cache_get_field_content - row: 0, field_name: "jobName", connection: 1, max_len: 256
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "jobName", data: "Arms Dealer"
[00:18:44] [DEBUG] cache_get_field_content_int - row: 0, field_name: "jobPickup", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "jobPickup", data: "1275"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 0, field_name: "jobPosX", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "jobPosX", data: "1796.42"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 0, field_name: "jobPosY", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "jobPosY", data: "-1149.37"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 0, field_name: "jobPosZ", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "jobPosZ", data: "23.742"
[00:18:44] [DEBUG] cache_get_field_content_int - row: 0, field_name: "jobType", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "jobType", data: "2"
[00:18:44] [DEBUG] cache_get_row_count - connection: 1
[00:18:44] [DEBUG] cache_get_field_content_int - row: 1, field_name: "jobID", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '1', field: "jobID", data: "2"
[00:18:44] [DEBUG] cache_get_field_content - row: 1, field_name: "jobName", connection: 1, max_len: 256
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '1', field: "jobName", data: "Drugs Dealer"
[00:18:44] [DEBUG] cache_get_field_content_int - row: 1, field_name: "jobPickup", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '1', field: "jobPickup", data: "1275"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 1, field_name: "jobPosX", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '1', field: "jobPosX", data: "2368.33"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 1, field_name: "jobPosY", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '1', field: "jobPosY", data: "-1675.35"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 1, field_name: "jobPosZ", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '1', field: "jobPosZ", data: "14.168"
[00:18:44] [DEBUG] cache_get_field_content_int - row: 1, field_name: "jobType", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '1', field: "jobType", data: "1"
[00:18:44] [DEBUG] cache_get_row_count - connection: 1
[00:18:44] [DEBUG] cache_get_field_content_int - row: 2, field_name: "jobID", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '2', field: "jobID", data: "3"
[00:18:44] [DEBUG] cache_get_field_content - row: 2, field_name: "jobName", connection: 1, max_len: 256
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '2', field: "jobName", data: "Trucker"
[00:18:44] [DEBUG] cache_get_field_content_int - row: 2, field_name: "jobPickup", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '2', field: "jobPickup", data: "1275"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 2, field_name: "jobPosX", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '2', field: "jobPosX", data: "2208.67"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 2, field_name: "jobPosY", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '2', field: "jobPosY", data: "-2198.18"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 2, field_name: "jobPosZ", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '2', field: "jobPosZ", data: "13.915"
[00:18:44] [DEBUG] cache_get_field_content_int - row: 2, field_name: "jobType", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '2', field: "jobType", data: "3"
[00:18:44] [DEBUG] cache_get_row_count - connection: 1
[00:18:44] [DEBUG] cache_get_field_content_int - row: 3, field_name: "jobID", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '3', field: "jobID", data: "4"
[00:18:44] [DEBUG] cache_get_field_content - row: 3, field_name: "jobName", connection: 1, max_len: 256
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '3', field: "jobName", data: "Detective"
[00:18:44] [DEBUG] cache_get_field_content_int - row: 3, field_name: "jobPickup", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '3', field: "jobPickup", data: "1275"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 3, field_name: "jobPosX", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '3', field: "jobPosX", data: "1411.45"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 3, field_name: "jobPosY", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '3', field: "jobPosY", data: "-1699.68"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 3, field_name: "jobPosZ", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '3', field: "jobPosZ", data: "13.539"
[00:18:44] [DEBUG] cache_get_field_content_int - row: 3, field_name: "jobType", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '3', field: "jobType", data: "6"
[00:18:44] [DEBUG] cache_get_row_count - connection: 1
[00:18:44] [DEBUG] cache_get_field_content_int - row: 4, field_name: "jobID", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '4', field: "jobID", data: "5"
[00:18:44] [DEBUG] cache_get_field_content - row: 4, field_name: "jobName", connection: 1, max_len: 256
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '4', field: "jobName", data: "Farmer"
[00:18:44] [DEBUG] cache_get_field_content_int - row: 4, field_name: "jobPickup", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '4', field: "jobPickup", data: "1275"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 4, field_name: "jobPosX", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '4', field: "jobPosX", data: "-382.976"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 4, field_name: "jobPosY", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '4', field: "jobPosY", data: "-1426.4"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 4, field_name: "jobPosZ", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '4', field: "jobPosZ", data: "26.319"
[00:18:44] [DEBUG] cache_get_field_content_int - row: 4, field_name: "jobType", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '4', field: "jobType", data: "4"
[00:18:44] [DEBUG] cache_get_row_count - connection: 1
[00:18:44] [DEBUG] cache_get_field_content_int - row: 5, field_name: "jobID", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '5', field: "jobID", data: "6"
[00:18:44] [DEBUG] cache_get_field_content - row: 5, field_name: "jobName", connection: 1, max_len: 256
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '5', field: "jobName", data: "Street Sweeper"
[00:18:44] [DEBUG] cache_get_field_content_int - row: 5, field_name: "jobPickup", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '5', field: "jobPickup", data: "1275"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 5, field_name: "jobPosX", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '5', field: "jobPosX", data: "1628.69"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 5, field_name: "jobPosY", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '5', field: "jobPosY", data: "-1903.41"
[00:18:44] [DEBUG] cache_get_field_content_float - row: 5, field_name: "jobPosZ", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '5', field: "jobPosZ", data: "13.553"
[00:18:44] [DEBUG] cache_get_field_content_int - row: 5, field_name: "jobType", connection: 1
[00:18:44] [DEBUG] CMySQLResult::GetRowDataByName - row: '5', field: "jobType", data: "8"
[00:18:44] [DEBUG] cache_get_row_count - connection: 1
[00:18:44] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
Reply
#6

Quote:
Originally Posted by TopShooter
Посмотреть сообщение
Why dont you use cases and InRangeOf code like this? Its better than yours.

PHP код:
if(IsPlayerInRangeOfPoint(playerid,3.0,X,Y,Z Coordinates) {
            if(
PlayerInfo[playerid][pJob] == 0){
                
SendClientMessageEx(playeridCOLOR_LIGHTBLUE"You have signed in the papers and you are not workign for (job name)");
                
pInfo[playerid][pJob] = 1;
                return 
1;
            }
}
        else if(
IsPlayerInRangeOfPoint(playerid3.0X,Y,Z Coordinates)) {
            if(
PlayerInfo[playerid][pJob] == 0){
                
SendClientMessageEx(playeridCOLOR_LIGHTBLUE"* You have signed up in the papers and you are now working for (job name)");
                
pInfo[playerid][pJob] = 2;
                return 
1;
            }
        }
        else if (
IsPlayerInRangeOfPoint(playerid,3.0,X,Y,Z Coordinates ._.)) {
            if(
PlayerInfo[playerid][pJob] == 0){
                
SendClientMessageEx(playeridCOLOR_LIGHTBLUE"*You have signed up in the papers and you are now working for (job name)");
                
pInfo[playerid][pJob] = 3;
                return 
1;
            } 
It is not, as I said my system is DYNAMIC which means that everything should be loading with the
Код:
for(new
function. So I can never use the x, y and z for declaring if the player is in range of it.
Reply
#7

Quote:
Originally Posted by Sascha
Посмотреть сообщение
Problem probably happens on the mysql loading I suppose..
Show us how you load the data
Код:
public OnJobsLoad(jobid)
{
	new string5[256], string3[256];
	for(new i = 0; i < cache_num_rows(); i++)
	{
		jInfo[i][jID] = cache_get_field_content_int(i, "jobID");
		cache_get_field_content(i,"jobName",jInfo[i][jName],mysql,256);
		jInfo[i][jPickup] = cache_get_field_content_int(i, "jobPickup");
		jInfo[i][jPosX] = cache_get_field_content_float(i, "jobPosX");
		jInfo[i][jPosY] = cache_get_field_content_float(i, "jobPosY");
		jInfo[i][jPosZ] = cache_get_field_content_float(i, "jobPosZ");
		jInfo[i][jType] = cache_get_field_content_int(i, "jobType");
		jCount++;
		CreatePickup(jInfo[i][jPickup], 1, jInfo[i][jPosX],jInfo[i][jPosY],jInfo[i][jPosZ], 0);
		format(string3, sizeof(string3), "{0095E6}Job ID: {FFFFFF}%d\n{0095E6}Job Name: {FFFFFF}%s\n{0095E6}Use /getjob", jInfo[i][jID], jInfo[i][jName]);
		Create3DTextLabel(string3, 0x008080FF, jInfo[i][jPosX],jInfo[i][jPosY],jInfo[i][jPosZ], 8.0, 0, 0);
	}
	format(string5, sizeof(string5), " %d jobs loaded from database.", jCount);
	print(string5);
	return 1;
}
Reply
#8

Yeah, my bad
Reply
#9

Anyone?
Reply
#10

Bumping
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)