Adding a job - error index out of bounds.. how?
#1

I have recently tried to add a job to my script, but apparently it won't let me. I don't get what's wrong, because all the other jobs works perfectly fine. And I can't find anything different that this job doesn't include, but I am still getting this error. So when I do /makejob 6 Farmer it gives me "Unknown command". Farmer job has been defined as jobid 6. However if I do /makejob 5 Something it works perfectly fine, but is of course not the farmer job though. Do you guys see why it wouldn't let me make that job? It has been defined as number 6 at the top of the script (code shown below).

Adding a farmer job, which will get "slot" 6 as 0-5 is already used by other jobs.
Код:
#DEFINE FARMER 6 (added at the top of the script)
Код:
CMD:makejob(playerid, params[])
{
	if(!CheckAdmin(playerid, HIGH_ADMIN_LEVEL)) return NotAuthMSG(playerid);
	new jobid, name[64], Float:x, Float:y, Float:z;
	if(sscanf(params,"ds[64]ddd", jobid, name)) return SyntaxMSG(playerid, "/makejob [jobid] [name]");
	x = PlayerPosX(playerid); y = PlayerPosY(playerid); z = PlayerPosZ(playerid);
	format(JobsInfo[jobid][jobName], 128, "%s", name);  // GETTING ERROR HERE (Array index out of bounds - acceing elemnt at index 6 past array upper bound 5)
	JobsInfo[jobid][jobX] = x;
	JobsInfo[jobid][jobY] = y;
	JobsInfo[jobid][jobZ] = z;
	JobsInfo[jobid][jobOn] = 1;
	format(msg, sizeof(msg), "A new job was added, [JobID: %d, Name: %s]", jobid, name);
	SCM(playerid, COLOR_RED, msg);
	AddJobToFile(jobid, name, x, y, z);
	return 1;
}
Код:
public LoadDynamicJobs()
{
    new rows, fields;
	new total = 0, jobid = 0;
    cache_get_data(rows, fields);
    if(rows)
    {
		while(total < rows)
		{
			jobid = cache_get_row_int(total, 1);
			JobsInfo[jobid][jobID] = cache_get_row_int(total, 0); // GETTING ERROR HERE (Array index out of bounds - acceing elemnt at index 6 past array upper bound 5)
			cache_get_row(total, 2, JobsInfo[jobid][jobName], dbHandle, 128);
			JobsInfo[jobid][jobX] = cache_get_row_float(total, 3);
			JobsInfo[jobid][jobY] = cache_get_row_float(total, 4);
			JobsInfo[jobid][jobZ] = cache_get_row_float(total, 5);
			JobsInfo[jobid][jobSideJob] = cache_get_row_int(total, 18);
			JobsInfo[jobid][jobOn] = 1;
		}
    }
    return 1;
}
AddJobToFile:
Код:
stock AddJobToFile(jobid, name[], Float:x, Float:y, Float:z)
{
	format(query, sizeof(query), "INSERT INTO `jobs` (jobid, name, posx, posy, posz) VALUES(%d, '%s', %f, %f, %f)", jobid, name, x, y, z);
	mysql_function_query(dbHandle, query, true, "OnJobInsert", "d", jobid);
	return 1;
}
OnJobInsert:
Код:
public OnJobInsert(JobID)
{
	JobsInfo[JobID][jobID] = cache_insert_id(dbHandle);
	return 1;
}
JobsInfo:
Код:
enum JOBS_INFO
{
	jobID,
	jobPickUp,
	Text3D:jobLabel,
	jobName[64],
	Float:jobX,
	Float:jobY,
	Float:jobZ,
	jobOn
}
new JobsInfo[MAX_JOBS][JOBS_INFO];
Reply


Messages In This Thread
Adding a job - error index out of bounds.. how? - by TheBigFive - 02.08.2016, 13:35
Re: Adding a job - error index out of bounds.. how? - by Konstantinos - 02.08.2016, 13:42
Re: Adding a job - error index out of bounds.. how? - by SyS - 02.08.2016, 13:44
Re: Adding a job - error index out of bounds.. how? - by TheBigFive - 02.08.2016, 14:06

Forum Jump:


Users browsing this thread: 3 Guest(s)